From 11b1d3c1624ee4a6e79bf7a4185ebc80ea841cb7 Mon Sep 17 00:00:00 2001 From: Cason Kervis Date: Mon, 26 May 2025 22:18:28 +0800 Subject: [PATCH] feat(route/lenovo/drive): add lenovo drive route (#19198) * feat(route/lenovo/drive): add lenovo drive route * fix: fix timezone * fix: using path join --- lib/routes/lenovo/drive.ts | 65 +++++++++++++++++++++++++++ lib/routes/lenovo/namespace.ts | 7 +++ lib/routes/lenovo/templates/drive.art | 9 ++++ 3 files changed, 81 insertions(+) create mode 100644 lib/routes/lenovo/drive.ts create mode 100644 lib/routes/lenovo/namespace.ts create mode 100644 lib/routes/lenovo/templates/drive.art diff --git a/lib/routes/lenovo/drive.ts b/lib/routes/lenovo/drive.ts new file mode 100644 index 000000000..bbeb45652 --- /dev/null +++ b/lib/routes/lenovo/drive.ts @@ -0,0 +1,65 @@ +import { Route, Data, DataItem } from '@/types'; +import path from 'node:path'; +import { art } from '@/utils/render'; +import InvalidParameterError from '@/errors/types/invalid-parameter'; +import ofetch from '@/utils/ofetch'; +import { parseDate } from '@/utils/parse-date'; + +export const route: Route = { + path: '/drive/:selName', + categories: ['program-update'], + example: '/lenovo/drive/PF3WRD2G', + parameters: { selName: '产品序列号' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['lenovo.com.cn'], + target: '/drive/:selName', + }, + ], + name: '驱动', + maintainers: ['cscnk52'], + handler, +}; + +export async function handler(ctx) { + const selName = ctx.req.param('selName'); + const link = `https://newsupport.lenovo.com.cn/api/drive/drive_listnew?searchKey=${selName}`; + + const response = await ofetch(link); + + if (response.statusCode !== 200) { + throw new InvalidParameterError(`无效序列号, 请检查你的序列号是否正确.`); + } + + const driveList = response.data.partList.flatMap((part) => part.drivelist); + + const items: DataItem[] = driveList.map( + (item) => + ({ + title: `${item.DriverName} ${item.Version}`, + link: `https://newsupport.lenovo.com.cn/driveDownloads_detail.html?driveId=${item.DriverEdtionId}`, + description: art(path.join(__dirname, 'templates/drive.art'), { + driveName: item.DriverName, + driveCode: item.DriverCode, + driveVersion: item.Version, + downloadFileName: item.FileName, + downloadFilePath: item.FilePath, + }), + pubDate: parseDate(item.CreateTime, +8), + }) as DataItem + ); + + return { + title: `${response.data.driverSerious[0].NodeCode} 驱动`, + item: items, + language: 'zh-CN', + } as Data; +} diff --git a/lib/routes/lenovo/namespace.ts b/lib/routes/lenovo/namespace.ts new file mode 100644 index 000000000..e7663d269 --- /dev/null +++ b/lib/routes/lenovo/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '联想', + url: 'lenovo.com.cn', + lang: 'zh-CN', +}; diff --git a/lib/routes/lenovo/templates/drive.art b/lib/routes/lenovo/templates/drive.art new file mode 100644 index 000000000..4d53dbd1e --- /dev/null +++ b/lib/routes/lenovo/templates/drive.art @@ -0,0 +1,9 @@ +
+

驱动信息

+ +