mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add labels and state to save api in web frontend
This commit is contained in:
parent
1a5dfb5104
commit
4b85251c00
1 changed files with 11 additions and 2 deletions
|
|
@ -3,7 +3,12 @@ import { v4 as uuidv4 } from 'uuid'
|
|||
import { SaveResponseData } from '../../lib/networking/mutations/saveUrlMutation'
|
||||
import { ssrFetcher } from '../../lib/networking/networkHelpers'
|
||||
|
||||
const saveUrl = async (req: NextApiRequest, url: URL) => {
|
||||
const saveUrl = async (
|
||||
req: NextApiRequest,
|
||||
url: URL,
|
||||
labels: string[] | undefined,
|
||||
state: string | undefined
|
||||
) => {
|
||||
const clientRequestId = uuidv4()
|
||||
const mutation = `
|
||||
mutation SaveUrl($input: SaveUrlInput!) {
|
||||
|
|
@ -26,6 +31,8 @@ const saveUrl = async (req: NextApiRequest, url: URL) => {
|
|||
clientRequestId,
|
||||
url: url.toString(),
|
||||
source: 'api-save-url',
|
||||
labels: labels?.map((label) => ({ name: label })),
|
||||
state,
|
||||
},
|
||||
})
|
||||
|
||||
|
|
@ -47,8 +54,10 @@ export default async (
|
|||
res: NextApiResponse
|
||||
): Promise<void> => {
|
||||
const urlStr = req.query['url']
|
||||
const labels = req.query['labels'] as string[] | undefined
|
||||
const state = req.query['state'] as string | undefined
|
||||
const url = new URL(urlStr as string)
|
||||
const saveResult = await saveUrl(req, url)
|
||||
const saveResult = await saveUrl(req, url, labels, state)
|
||||
console.log('saveResult: ', saveResult)
|
||||
if (saveResult?.url) {
|
||||
res.redirect(`?url=${encodeURIComponent(url.toString())}`)
|
||||
|
|
|
|||
Loading…
Reference in a new issue