From c1913c83c10f5f0c292318bb4bb93d5faed69919 Mon Sep 17 00:00:00 2001 From: ueiu <39592269+ueiu@users.noreply.github.com> Date: Sat, 21 Sep 2024 22:31:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(route/asus):=20=E5=8D=8E=E7=A1=95=20BIOS?= =?UTF-8?q?=20=E8=B7=AF=E7=94=B1=E5=A2=9E=E5=8A=A0=E5=9B=BD=E5=A4=96?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=20API=20=E5=9C=B0=E5=9D=80=20(#16848)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/asus/bios.ts | 45 +++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/lib/routes/asus/bios.ts b/lib/routes/asus/bios.ts index e82587ce2..fd10061a4 100644 --- a/lib/routes/asus/bios.ts +++ b/lib/routes/asus/bios.ts @@ -7,8 +7,24 @@ import { parseDate } from '@/utils/parse-date'; import { art } from '@/utils/render'; import path from 'node:path'; -const getProductID = async (model) => { - const searchAPI = `https://odinapi.asus.com.cn/recent-data/apiv2/SearchSuggestion?SystemCode=asus&WebsiteCode=cn&SearchKey=${model}&SearchType=ProductsAll&RowLimit=4&sitelang=cn`; +const endPoints = { + zh: { + url: 'https://odinapi.asus.com.cn/', + lang: 'cn', + website_code: 'cn', + }, + en: { + url: 'https://odinapi.asus.com/', + lang: 'en', + website_code: 'us', + }, +}; + +const getProductID = async (model, language) => { + const currentEndpoint = endPoints[language] ?? endPoints.zh; + const { url, lang, website_code } = currentEndpoint; + + const searchAPI = `${url}recent-data/apiv2/SearchSuggestion?SystemCode=asus&WebsiteCode=${website_code}&SearchKey=${model}&SearchType=ProductsAll&RowLimit=4&sitelang=${lang}`; const response = await got(searchAPI); return { @@ -18,10 +34,26 @@ const getProductID = async (model) => { }; export const route: Route = { - path: '/bios/:model', + path: '/bios/:model/:lang?', categories: ['program-update'], - example: '/asus/bios/RT-AX88U', - parameters: { model: 'Model, can be found in product page' }, + example: '/asus/bios/RT-AX88U/zh', + parameters: { + model: 'Model, can be found in product page', + lang: { + description: 'Language, provide access routes for other parts of the world', + options: [ + { + label: 'Chinese', + value: 'zh', + }, + { + label: 'English', + value: 'en', + }, + ], + default: 'zh', + }, + }, features: { requireConfig: false, requirePuppeteer: false, @@ -43,7 +75,8 @@ export const route: Route = { async function handler(ctx) { const model = ctx.req.param('model'); - const { productID, url } = await getProductID(model); + const language = ctx.req.param('lang') ?? 'zh'; + const { productID, url } = await getProductID(model, language); const biosAPI = `https://www.asus.com.cn/support/api/product.asmx/GetPDBIOS?website=cn&model=${model}&pdid=${productID}&sitelang=cn`; const response = await got(biosAPI);