Skip to content

Commit

Permalink
feat(route/asus): 华硕 BIOS 路由增加国外访问 API 地址 (#16848)
Browse files Browse the repository at this point in the history
  • Loading branch information
ueiu authored Sep 21, 2024
1 parent aea69c8 commit c1913c8
Showing 1 changed file with 39 additions and 6 deletions.
45 changes: 39 additions & 6 deletions lib/routes/asus/bios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit c1913c8

Please sign in to comment.