From 4b85251c00d0bb5a3c4d5e27260404674d516a6a Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Wed, 19 Apr 2023 15:53:30 +0800 Subject: [PATCH] Add labels and state to save api in web frontend --- packages/web/pages/api/save.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/web/pages/api/save.ts b/packages/web/pages/api/save.ts index a43e6ccb7..d3474a494 100644 --- a/packages/web/pages/api/save.ts +++ b/packages/web/pages/api/save.ts @@ -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 => { 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())}`)