refactor(router): cast (#14742)
* refactor(route): remove interface ResponseData * feat(radar): radar rule for cast * Update lib/routes/cast/index.ts
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
import { Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got, { type Response } from '@/utils/got';
|
||||
import got from '@/utils/got';
|
||||
import { load } from 'cheerio';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
const baseUrl = 'https://www.cast.org.cn';
|
||||
|
||||
interface ResponseData<T> extends Response {
|
||||
data: T;
|
||||
}
|
||||
|
||||
async function parsePage(html: string) {
|
||||
return await Promise.all(
|
||||
load(html)('li')
|
||||
@@ -27,7 +23,7 @@ async function parsePage(html: string) {
|
||||
articleUrl = `${baseUrl}${title.attr('href')}`;
|
||||
|
||||
return cache.tryGet(articleUrl, async () => {
|
||||
const res = (await got.get(articleUrl!)) as ResponseData<string>;
|
||||
const res = await got.get<string>(articleUrl!);
|
||||
const article = load(res.data);
|
||||
const pubDate = timezone(parseDate(article('meta[name=PubDate]').attr('content')!, 'YYYY-MM-DD HH:mm'), +8);
|
||||
|
||||
@@ -55,6 +51,10 @@ export const route: Route = {
|
||||
supportPodcast: false,
|
||||
supportScihub: false,
|
||||
},
|
||||
radar: {
|
||||
source: ['cast.org.cn/:column/:subColumn/:category/index.html', 'cast.org.cn/:column/:subColumn/index.html'],
|
||||
target: '/cast/:column/:subColumn/:category?',
|
||||
},
|
||||
name: '通用',
|
||||
maintainers: ['KarasuShin', 'TonyRL'],
|
||||
handler,
|
||||
@@ -80,7 +80,7 @@ async function handler(ctx) {
|
||||
if (category) {
|
||||
link += `/${category}/index.html`;
|
||||
}
|
||||
const { data: indexData } = (await got.get(link)) as ResponseData<string>;
|
||||
const { data: indexData } = await got.get<string>(link);
|
||||
|
||||
const $ = load(indexData);
|
||||
|
||||
@@ -95,9 +95,9 @@ async function handler(ctx) {
|
||||
const queryData = JSON.parse(buildUnitScript.attr('querydata')?.replace(/'/g, '"') ?? '{}');
|
||||
queryData.paramJson = `{"pageNo":1,"pageSize":${limit}}`;
|
||||
|
||||
const { data } = (await got.get(queryUrl, {
|
||||
const { data } = await got.get<{ data: { html: string } }>(queryUrl, {
|
||||
searchParams: new URLSearchParams(queryData),
|
||||
})) as ResponseData<{ data: { html: string } }>;
|
||||
});
|
||||
|
||||
items = await parsePage(data.data.html);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user