From d2e82e02d80e485c1ab0e68e975e34a9d975ecbc Mon Sep 17 00:00:00 2001 From: Theo Sun Date: Wed, 29 May 2024 21:22:15 +0800 Subject: [PATCH] chore: update --- .vscode/settings.json | 5 +++- openapi.yaml | 60 +++++++++++++++++++++++++++++++++++++++++++ src/utils.mjs | 3 +++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index de3f32f..b90e0f6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,8 @@ "editor.codeActionsOnSave": { "source.fixAll": "explicit", "source.organizeImports": "explicit" - } + }, + "cSpell.words": [ + "Sogou" + ] } \ No newline at end of file diff --git a/openapi.yaml b/openapi.yaml index 371e4fe..61822ef 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -65,6 +65,66 @@ paths: error: type: string example: "Internal Server Error" + + /bing: + get: + operationId: Bing Search + summary: Perform a search on Bing + description: Returns search results from Sogou based on the query parameter. + parameters: + - name: search + in: query + required: true + description: The search query. + schema: + type: string + responses: + "200": + description: A JSON array of search results. + content: + application/json: + schema: + type: array + items: + type: object + properties: + title: + type: string + description: The title of the search result. + example: "Example Search Result Title" + link: + type: string + description: The URL of the search result. + example: "https://example.com" + description: + type: string + description: A brief description of the search result. + example: "This is an example description of a search result." + text: + type: string + description: The text of the search result. + example: "This is an example text of a search result." + "400": + description: Bad request, search query parameter is missing. + content: + application/json: + schema: + type: object + properties: + error: + type: string + example: "search query parameter is required" + "500": + description: Internal server error. + content: + application/json: + schema: + type: object + properties: + error: + type: string + example: "Internal Server Error" + components: securitySchemes: apiKey: diff --git a/src/utils.mjs b/src/utils.mjs index 2436114..c67f894 100644 --- a/src/utils.mjs +++ b/src/utils.mjs @@ -31,6 +31,9 @@ export function asyncExpressMiddleware(fn) { export function createCommonSearchAPI(options) { return asyncExpressMiddleware(async (req, res) => { const { search } = req.query; + if (!search) { + return res.status(400).json({ error: "search query is required" }); + } const browser = await puppeteer.connect({ browserWSEndpoint: process.env.PW_REMOTE_URL, });