omnivore-app / omnivore

Omnivore is a complete, open source read-it-later solution for people who like reading.
https://omnivore.app
GNU Affero General Public License v3.0
13.6k stars 877 forks source link

Add web API endpoint to allow saving a URL #1827

Closed jacksonh closed 1 year ago

jacksonh commented 1 year ago

On vercel we should be able to easily support a call like: https://omnivore.app/api/save?url= this would just need a file in packages/web/pages/api/save.ts that makes the GQL call to SaveURL

jacksonh commented 1 year ago

I think this would work:

import type { NextApiRequest, NextApiResponse } from 'next'
import { saveUrlMutation } from '../../lib/networking/mutations/saveUrlMutation'

// eslint-disable-next-line import/no-anonymous-default-export
export default async (
  req: NextApiRequest,
  res: NextApiResponse
): Promise<void> => {
  let urlStr = req.query['url']
  let url = new URL(urlStr as string)
  let saveResult = await saveUrlMutation(url.toString())
  if (saveResult?.jobId) {
    res.redirect(`/sr/${saveResult?.jobId}`)
    return
  }

  res.status(200).send('ok')
}