feat(route/lenovo/drive): add lenovo drive route (#19198)

* feat(route/lenovo/drive): add lenovo drive route

* fix: fix timezone

* fix: using path join
This commit is contained in:
Cason Kervis
2025-05-26 22:18:28 +08:00
committed by GitHub
parent e584e46f45
commit 11b1d3c162
3 changed files with 81 additions and 0 deletions
+65
View File
@@ -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;
}
+7
View File
@@ -0,0 +1,7 @@
import type { Namespace } from '@/types';
export const namespace: Namespace = {
name: '联想',
url: 'lenovo.com.cn',
lang: 'zh-CN',
};
+9
View File
@@ -0,0 +1,9 @@
<div class="driver-info">
<h2>驱动信息</h2>
<ul>
<li><strong>驱动名称:</strong>{{ driveName }}</li>
<li><strong>驱动编码:</strong>{{ driveCode }}</li>
<li><strong>驱动版本:</strong>{{ driveVersion }}</li>
<li><strong>下载地址:</strong><a href="{{ downloadFilePath }}" download>{{ downloadFileName }}</a></li>
</ul>
</div>