Skip to content

Commit

Permalink
fix(route): asus bios global url (#16866)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Sep 22, 2024
1 parent e9a6146 commit 6c24f14
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 30 deletions.
82 changes: 58 additions & 24 deletions lib/routes/asus/bios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,53 @@ import { Route } from '@/types';
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);

import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import path from 'node:path';
import cache from '@/utils/cache';

const endPoints = {
zh: {
url: 'https://odinapi.asus.com.cn/',
lang: 'cn',
website_code: 'cn',
websiteCode: 'cn',
},
en: {
url: 'https://odinapi.asus.com/',
lang: 'en',
website_code: 'us',
websiteCode: 'global',
},
};

const getProductID = async (model, language) => {
const getProductInfo = (model, language) => {
const currentEndpoint = endPoints[language] ?? endPoints.zh;
const { url, lang, website_code } = currentEndpoint;
const { url, lang, websiteCode } = 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);
const searchAPI = `${url}recent-data/apiv2/SearchSuggestion?SystemCode=asus&WebsiteCode=${websiteCode}&SearchKey=${model}&SearchType=ProductsAll&RowLimit=4&sitelang=${lang}`;

return {
productID: response.data.Result[0].Content[0].DataId,
url: response.data.Result[0].Content[0].Url,
};
return cache.tryGet(`asus:bios:${model}:${language}`, async () => {
const response = await ofetch(searchAPI);
const product = response.Result[0].Content[0];

return {
productID: product.DataId,
hashId: product.HashId,
url: product.Url,
title: product.Title,
image: product.ImageURL,
m1Id: product.M1Id,
productLine: product.ProductLine,
};
}) as Promise<{
productID: string;
hashId: string;
url: string;
title: string;
image: string;
m1Id: string;
productLine: string;
}>;
};

export const route: Route = {
Expand All @@ -47,11 +65,11 @@ export const route: Route = {
value: 'zh',
},
{
label: 'English',
label: 'Global',
value: 'en',
},
],
default: 'zh',
default: 'en',
},
},
features: {
Expand All @@ -64,37 +82,53 @@ export const route: Route = {
},
radar: [
{
source: ['asus.com.cn/'],
source: [
'www.asus.com/displays-desktops/:productLine/:series/:model',
'www.asus.com/laptops/:productLine/:series/:model',
'www.asus.com/motherboards-components/:productLine/:series/:model',
'www.asus.com/networking-iot-servers/:productLine/:series/:model',
'www.asus.com/:region/displays-desktops/:productLine/:series/:model',
'www.asus.com/:region/laptops/:productLine/:series/:model',
'www.asus.com/:region/motherboards-components/:productLine/:series/:model',
'www.asus.com/:region/networking-iot-servers/:productLine/:series/:model',
'asus.com.cn/',
],
target: '/bios/:model',
},
],
name: 'BIOS',
maintainers: ['Fatpandac'],
handler,
url: 'asus.com.cn/',
url: 'www.asus.com',
};

async function handler(ctx) {
const model = ctx.req.param('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 language = ctx.req.param('lang') ?? 'en';
const productInfo = await getProductInfo(model, language);
const biosAPI =
language === 'zh'
? `https://www.asus.com.cn/support/api/product.asmx/GetPDBIOS?website=cn&model=${model}&pdid=${productInfo.productID}&sitelang=cn`
: `https://www.asus.com/support/api/product.asmx/GetPDBIOS?website=global&model=${model}&pdid=${productInfo.productID}&sitelang=en`;

const response = await got(biosAPI);
const biosList = response.data.Result.Obj[0].Files;
const response = await ofetch(biosAPI);
const biosList = response.Result.Obj[0].Files;

const items = biosList.map((item) => ({
title: item.Title,
description: art(path.join(__dirname, 'templates/bios.art'), {
item,
language,
}),
guid: url + item.Version,
guid: productInfo.url + item.Version,
pubDate: parseDate(item.ReleaseDate, 'YYYY/MM/DD'),
link: url,
link: productInfo.url,
}));

return {
title: `${model} BIOS`,
link: url,
title: `${productInfo.title} BIOS`,
link: productInfo.url,
image: productInfo.image,
item: items,
};
}
19 changes: 13 additions & 6 deletions lib/routes/asus/templates/bios.art
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<p>更新信息:</p>
{{@ item.Description}}
<p>版本: {{item.Version}}</p>
<p>大小: {{item.FileSize}}</p>
<p>更新日期: {{item.ReleaseDate}}</p>
<p>下载链接: <a href="{{item.DownloadUrl.China}}">中国下载</a> | <a href="{{item.DownloadUrl.Global}}">全球下载</a></p>
{{ if language !== 'zh' }}
<p><b>Changes:</b></p>
{{@ item.Description}}
<p><b>Version:</b> {{item.Version}}</p>
<p><b>Size:</b> {{item.FileSize}}</p>
<p><b>Download:</b> <a href="{{ item.DownloadUrl.Global }}">{{ item.DownloadUrl.Global.split('/').pop().split('?')[0] }}</a></p>
{{ else }}
<p>更新信息:</p>
{{@ item.Description}}
<p>版本: {{item.Version}}</p>
<p>大小: {{item.FileSize}}</p>
<p>下载链接: <a href="{{item.DownloadUrl.China}}">中国下载</a> | <a href="{{item.DownloadUrl.Global}}">全球下载</a></p>
{{ /if }}

0 comments on commit 6c24f14

Please sign in to comment.