From 3a71193ff850bdc8fcc232ceda5bcfc0d769d837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B3pez=20Guimaraes?= Date: Thu, 29 Jun 2023 19:55:02 +0100 Subject: [PATCH] Add support for search_key to be string, not array The `search_key` parameter isn't always going to be a string array, but it can be a single string. Support both cases accordingly. --- src/services/api/routes/posts.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/api/routes/posts.ts b/src/services/api/routes/posts.ts index 6ad8aa7..b504b02 100644 --- a/src/services/api/routes/posts.ts +++ b/src/services/api/routes/posts.ts @@ -27,7 +27,7 @@ const newPostSchema = z.object({ screenshot: z.string().optional(), body: z.string().optional(), feeling_id: z.string(), - search_key: z.string().array().optional(), + search_key: z.string().array().or(z.string()).optional(), topic_tag: z.string().optional(), is_autopost: z.string(), is_spoiler: z.string().optional(), @@ -236,7 +236,7 @@ async function newPost(request: express.Request, response: express.Response): Pr const screenshot: string = bodyCheck.data.screenshot?.replace(/\0/g, '').trim() || ''; const appData: string = bodyCheck.data.app_data?.replace(/[^A-Za-z0-9+/=\s]/g, '').trim() || ''; const feelingID: number = parseInt(bodyCheck.data.feeling_id); - const searchKey: string[] | undefined = bodyCheck.data.search_key || []; + const searchKey: string[] | undefined = (typeof bodyCheck.data.search_key === 'string' ? [bodyCheck.data.search_key as string] : bodyCheck.data.search_key as string[]) || []; const topicTag: string | undefined = bodyCheck.data.topic_tag || ''; const autopost: string = bodyCheck.data.is_autopost; const spoiler: string | undefined = bodyCheck.data.is_spoiler;