Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include file names for files in a table #7

Open
kartiknair opened this issue Sep 22, 2020 · 2 comments
Open

Include file names for files in a table #7

kartiknair opened this issue Sep 22, 2020 · 2 comments

Comments

@kartiknair
Copy link

Hey there! Really like this project & have found it very helpful to create a simple CMS of sorts.

I just have one issue & that is that the api doesn't return file names, but rather just an array of URLs. For example here's an example notion page & this is potion's api response for it. It would be very helpful to provide the filenames in the response to show attachments on the client side for example.

I have a solution for it working locally it's just a small change in the api/table.js file, just wondering if this would be an ok PR. Especially because it is a breaking change to the table api.

Here is the change btw:

files.forEach((file) => {
  const s3Url = file[1][0][1]
  outputFiles.push({
    name: file[0],
    url: getAssetUrl(s3Url, page.value.id)
  })
})

instead of just pushing the url to output files.

@benborgers
Copy link
Owner

This is great! Do you have any ideas for how we could version this change?

I don't think we can push it right in, because people using fields.Files[0] as the URL would break (it would now be fields.Files[0].url).

@kartiknair
Copy link
Author

Yep agreed, that's why I created this issue, didn't just wanna pull request out of the blue. I've mostly seen api versioning done either through a subdomain (like v3.api.github.com) or as a nested page (like api.github.com/v3).

The nested page one seems easier to implement using Vercel. I tried a basic implementation locally by just forwarding /v2 requests to the regular api but with a version query parameter. This is how it looks like in now.json:

{
  "rewrites": [
    { "source": "/v2/(.*)", "destination": "/api/$1?version=2" },
    { "source": "/(.*)", "destination": "/api/$1" }
  ]
}

And then in the table source it can be handled by checking for the query:

module.exports = async (req, res) => {
  const { id: queryId, version: apiVersion } = req.query
  
  /* ... */

  const outputFiles = []

  files.forEach((file) => {
    const s3Url = file[1][0][1]
    const assetUrl = getAssetUrl(s3Url, page.value.id)

    outputFiles.push(
      apiVersion === "2"
        ? {
            name: file[0],
            url: assetUrl
          }
        : assetUrl
    )
  })

  /* ... */
}

To be completely honest I'm not very sure about the correct way to go about it, so go for whatever you think is right. Even if you don't wanna add it to the hosted endpoint I totally understand. I can always self-host it internally within the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants