style(eslint): fix no-unassigned-vars no-useless-assignment preserve-caught-error (#21175)
* fix: fix no-unassigned-vars * fix: fix preserve-caught-error * fix: fix no-useless-assignment * fix: update variable types for better type safety * fix: replace nullish coalescing with logical OR for limit assignment * fix: add DataItem type import for better type safety
This commit is contained in:
@@ -22,9 +22,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'en';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('table#home-table tr:not(.gore)')
|
||||
let items: DataItem[] = $('table#home-table tr:not(.gore)')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -22,9 +22,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('ul.l_newshot li dl.lhotnew2')
|
||||
let items: DataItem[] = $('ul.l_newshot li dl.lhotnew2')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { load } from 'cheerio';
|
||||
import iconv from 'iconv-lite';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import type { DataItem, Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
@@ -55,7 +55,7 @@ async function handler(ctx) {
|
||||
|
||||
const data = iconv.decode(response.data, 'gbk');
|
||||
|
||||
let items = {};
|
||||
let items: DataItem[];
|
||||
|
||||
const urls = data.match(/url:"(.*)",/g);
|
||||
|
||||
|
||||
@@ -21,9 +21,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh-CN';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('article.newsplus')
|
||||
let items: DataItem[] = $('article.newsplus')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -85,9 +85,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
},
|
||||
});
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = JSON.parse(response)
|
||||
let items: DataItem[] = JSON.parse(response)
|
||||
.slice(0, limit)
|
||||
.map((item): DataItem => {
|
||||
const title: string = item.title;
|
||||
|
||||
@@ -33,10 +33,9 @@ async function handler(ctx) {
|
||||
|
||||
const items = await Promise.all(list.map((item) => cache.tryGet(item.link, () => parseItem(item))));
|
||||
|
||||
let categories = [];
|
||||
let categoryName = '最新消息';
|
||||
if (!isLatest) {
|
||||
categories = await getCategories(cache.tryGet);
|
||||
const categories = await getCategories(cache.tryGet);
|
||||
categoryName = categories.find((c) => c.id === Number.parseInt(category)).name;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ export const route: Route = {
|
||||
const pattern = /'(WTKkN|bOYDu|wyeCN)':\s*(\d+)/g;
|
||||
|
||||
async function getFullcontent(item, cookie = '') {
|
||||
let fullContent: null | string = null;
|
||||
const articleResponse = await ofetch(item.url, {
|
||||
headers: {
|
||||
cookie,
|
||||
@@ -35,7 +34,7 @@ async function getFullcontent(item, cookie = '') {
|
||||
});
|
||||
const $ = load(articleResponse);
|
||||
|
||||
fullContent = new URL(item.url).host === 'ost.51cto.com' ? $('.posts-content').html() : $('article').html();
|
||||
const fullContent = new URL(item.url).host === 'ost.51cto.com' ? $('.posts-content').html() : $('article').html();
|
||||
|
||||
if (!fullContent && cookie === '') {
|
||||
// If fullContent is null and haven't tried to request with cookie, try to get fullContent with cookie
|
||||
|
||||
@@ -25,9 +25,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(iconv.decode(Buffer.from(response), encoding));
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('ul.list li')
|
||||
let items: DataItem[] = $('ul.list li')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -41,9 +41,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(targetResponse);
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = response.slice(0, limit).map((item): DataItem => {
|
||||
const items: DataItem[] = response.slice(0, limit).map((item): DataItem => {
|
||||
const title: string = item.title?.rendered ?? item.title;
|
||||
const description: string | undefined = item.content.rendered;
|
||||
const pubDate: number | string = item.date_gmt;
|
||||
|
||||
@@ -40,7 +40,7 @@ async function handler(ctx) {
|
||||
const rootUrl = 'https://www.abc.net.au';
|
||||
const apiUrl = new URL('news-web/api/loader/channelrefetch', rootUrl).href;
|
||||
|
||||
let currentUrl = '';
|
||||
let currentUrl: string;
|
||||
let documentId;
|
||||
|
||||
if (Number.isNaN(category)) {
|
||||
|
||||
@@ -22,9 +22,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh-CN';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.article_1')
|
||||
let items: DataItem[] = $('div.article_1')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -22,9 +22,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh-CN';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.article_1')
|
||||
let items: DataItem[] = $('div.article_1')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -19,9 +19,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'en';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('article.article')
|
||||
let items: DataItem[] = $('article.article')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -22,9 +22,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'en';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.wf-panel')
|
||||
let items: DataItem[] = $('div.wf-panel')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Route } from '@/types';
|
||||
import type { DataItem, Route } from '@/types';
|
||||
import { ViewType } from '@/types';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
@@ -116,8 +116,8 @@ async function handler(ctx) {
|
||||
const artistName = attributes.artistName;
|
||||
const platformAttributes = attributes.platformAttributes;
|
||||
|
||||
let items = [];
|
||||
let title = '';
|
||||
let items: DataItem[] = [];
|
||||
let title: string;
|
||||
let description = '';
|
||||
let image = '';
|
||||
|
||||
|
||||
@@ -27,9 +27,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
.toArray()
|
||||
.map((el) => $(el).text());
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $trEls
|
||||
let items: DataItem[] = $trEls
|
||||
.slice(1, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -22,9 +22,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh-CN';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.listBlocks ul li')
|
||||
let items: DataItem[] = $('div.listBlocks ul li')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -21,9 +21,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh-CN';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.listBlocks ul li')
|
||||
let items: DataItem[] = $('div.listBlocks ul li')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -40,9 +40,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'en';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div[data-slot="card"]')
|
||||
let items: DataItem[] = $('div[data-slot="card"]')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -154,7 +154,7 @@ async function handler(ctx) {
|
||||
const typeName = typeNames[type] || '';
|
||||
const subjectTypeName = subjectTypeNames[subjectType] || '';
|
||||
|
||||
let descriptionFields = '';
|
||||
let descriptionFields: string;
|
||||
|
||||
if (typeName && subjectTypeName) {
|
||||
descriptionFields = `${typeName}的${subjectTypeName}列表`;
|
||||
|
||||
@@ -22,9 +22,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('ul.small-list li.row')
|
||||
let items: DataItem[] = $('ul.small-list li.row')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -23,9 +23,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.bty_tbtj_list ul.clearFix li')
|
||||
let items: DataItem[] = $('div.bty_tbtj_list ul.clearFix li')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -239,8 +239,6 @@ const renderVideo = (block: Block, index: number): JSX.Element | null => {
|
||||
|
||||
let src: string | undefined;
|
||||
let sourceText: string | undefined;
|
||||
let width: number | undefined;
|
||||
let height: number | undefined;
|
||||
|
||||
if (mediaMetadataBlock?.model?.imageUrl) {
|
||||
src = mediaMetadataBlock.model.imageUrl;
|
||||
@@ -254,7 +252,7 @@ const renderVideo = (block: Block, index: number): JSX.Element | null => {
|
||||
return null;
|
||||
}
|
||||
|
||||
return renderFigure(`video-${index}`, src, altText, width, height, caption, sourceText);
|
||||
return renderFigure(`video-${index}`, src, altText, undefined, undefined, caption, sourceText);
|
||||
};
|
||||
|
||||
const renderMedia = (block: Block, index: number): JSX.Element | null => {
|
||||
|
||||
@@ -22,7 +22,7 @@ export const route: Route = {
|
||||
async function handler(ctx) {
|
||||
const product = ctx.req.param('product');
|
||||
|
||||
let productTitle = '';
|
||||
let productTitle: string;
|
||||
|
||||
switch (product) {
|
||||
case 'live':
|
||||
|
||||
@@ -26,7 +26,7 @@ async function handler(ctx) {
|
||||
const areaID = ctx.req.param('areaID');
|
||||
const order = ctx.req.param('order');
|
||||
|
||||
let orderTitle = '';
|
||||
let orderTitle: string;
|
||||
switch (order) {
|
||||
case 'live_time':
|
||||
orderTitle = '最新开播';
|
||||
@@ -47,7 +47,7 @@ async function handler(ctx) {
|
||||
});
|
||||
|
||||
let parentTitle = '';
|
||||
let parentID = '';
|
||||
let parentID: string;
|
||||
let areaTitle = '';
|
||||
let areaLink = '';
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ async function handler(ctx) {
|
||||
const order = ctx.req.param('order');
|
||||
|
||||
const urlEncodedKey = encodeURIComponent(key);
|
||||
let orderTitle = '';
|
||||
let orderTitle: string;
|
||||
|
||||
switch (order) {
|
||||
case 'live_time':
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Route } from '@/types';
|
||||
import type { DataItem, Route } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
|
||||
import utils from './utils';
|
||||
@@ -43,11 +43,8 @@ async function handler(ctx) {
|
||||
const responseApi = `https://api.bilibili.com/x/web-interface/newlist?ps=15&rid=${tid}&_=${Date.now()}`;
|
||||
|
||||
const response = await got_ins.get(responseApi);
|
||||
const items = [];
|
||||
let name = '未知';
|
||||
let list = {};
|
||||
|
||||
list = response.data.data.archives;
|
||||
const list = response.data.data.archives;
|
||||
if (list && list[0] && list[0].tname) {
|
||||
name = list[0].tname;
|
||||
}
|
||||
@@ -58,16 +55,13 @@ async function handler(ctx) {
|
||||
const HotRankResponse = await got_ins.get(HotRankResponseApi);
|
||||
const hotlist = HotRankResponse.data.result;
|
||||
|
||||
for (let item of hotlist) {
|
||||
item = {
|
||||
title: item.title,
|
||||
description: utils.renderUGCDescription(embed, item.pic, `${item.description} - ${item.tag}`, item.id, undefined, item.bvid),
|
||||
pubDate: new Date(item.pubdate).toUTCString(),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.id}`,
|
||||
author: item.author,
|
||||
};
|
||||
items.push(item);
|
||||
}
|
||||
const items: DataItem[] = hotlist.map((item) => ({
|
||||
title: item.title,
|
||||
description: utils.renderUGCDescription(embed, item.pic, `${item.description} - ${item.tag}`, item.id, undefined, item.bvid),
|
||||
pubDate: new Date(item.pubdate).toUTCString(),
|
||||
link: item.pubdate > utils.bvidTime && item.bvid ? `https://www.bilibili.com/video/${item.bvid}` : `https://www.bilibili.com/video/av${item.id}`,
|
||||
author: item.author,
|
||||
}));
|
||||
|
||||
return {
|
||||
title: `bilibili ${name} 最热视频`,
|
||||
|
||||
@@ -193,7 +193,7 @@ function getAPI(isNumericRid: boolean, rid: string | number) {
|
||||
const ridEnglish = zone[1].english;
|
||||
|
||||
let apiBase = 'https://api.bilibili.com/x/web-interface/ranking/v2';
|
||||
let apiParams = '';
|
||||
let apiParams: string;
|
||||
|
||||
switch (ridType) {
|
||||
case 'x/rid':
|
||||
|
||||
@@ -319,7 +319,7 @@
|
||||
|
||||
// func resetMemoryDataView()
|
||||
'runtime.resetMemoryDataView': (sp) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-useless-assignment
|
||||
sp >>>= 0;
|
||||
this.mem = new DataView(this._inst.exports.mem.buffer);
|
||||
},
|
||||
|
||||
@@ -60,7 +60,7 @@ async function handler(ctx) {
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
let link = '';
|
||||
let link: string;
|
||||
const url = item.attr('href');
|
||||
if (url.startsWith('http')) {
|
||||
link = url;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Route } from '@/types';
|
||||
import type { DataItem, Route } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
import timezone from '@/utils/timezone';
|
||||
@@ -185,7 +185,7 @@ async function handler(ctx) {
|
||||
|
||||
const data = JSON.parse(response.data.match(/null\(\[({.*})]\)/)[1]);
|
||||
|
||||
let items = [];
|
||||
let items: DataItem[];
|
||||
|
||||
switch (type) {
|
||||
case '/info/listse':
|
||||
|
||||
@@ -19,7 +19,7 @@ async function doGot(num, host, link) {
|
||||
throw new Error('api error');
|
||||
}
|
||||
cookieJar.setCookieSync(match[1], host);
|
||||
return doGot(++num, host, link);
|
||||
return doGot(num + 1, host, link);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -20,9 +20,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'en';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('section#block-bootstrap-views-block-latest-articles-block div.media, div.gold-news-content table tr')
|
||||
let items: DataItem[] = $('section#block-bootstrap-views-block-latest-articles-block div.media, div.gold-news-content table tr')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { load } from 'cheerio';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import type { DataItem, Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
@@ -88,7 +88,7 @@ async function handler(ctx) {
|
||||
|
||||
const $ = load(indexData);
|
||||
|
||||
let items: any[] = [];
|
||||
let items: DataItem[];
|
||||
|
||||
// 新闻-视频首页特殊处理
|
||||
if (column === 'xw' && subColumn === 'SP' && !category) {
|
||||
|
||||
@@ -29,9 +29,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
},
|
||||
});
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = response.data.slice(0, limit).map((item): DataItem => {
|
||||
let items: DataItem[] = response.data.slice(0, limit).map((item): DataItem => {
|
||||
const title: string = item.title;
|
||||
const image: string | undefined = item.image;
|
||||
const description: string | undefined = renderDescription({
|
||||
|
||||
@@ -21,9 +21,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('ul.news_list li a')
|
||||
let items: DataItem[] = $('ul.news_list li a')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -20,11 +20,9 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh-CN';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
const regex = /\{url:'(.*)',title:'(.*)',time:'(.*)'\},/g;
|
||||
|
||||
items =
|
||||
let items: DataItem[] =
|
||||
response
|
||||
.match(regex)
|
||||
?.slice(0, limit)
|
||||
|
||||
@@ -22,9 +22,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('ul.huodong-list li')
|
||||
let items: DataItem[] = $('ul.huodong-list li')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -81,7 +81,7 @@ async function handler(ctx) {
|
||||
});
|
||||
|
||||
const items = data.data.records.map((item) => {
|
||||
let description = '';
|
||||
let description: string;
|
||||
switch (category) {
|
||||
case 'priorityApproval':
|
||||
description = renderToString(<PriorityApprovalTable item={item} />);
|
||||
|
||||
@@ -23,9 +23,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh-CN';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.gy_box, ul.content_list li')
|
||||
let items: DataItem[] = $('div.gy_box, ul.content_list li')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -20,9 +20,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = 'zh-CN';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.contRight ul.list li')
|
||||
let items: DataItem[] = $('div.contRight ul.list li')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { load } from 'cheerio';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import type { DataItem, Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import ofetch from '@/utils/ofetch';
|
||||
|
||||
@@ -23,7 +23,7 @@ export const route: Route = {
|
||||
|
||||
async function handler() {
|
||||
const response = await ofetch('https://www.chongdiantou.com/nice-json/front-end/home-load-more');
|
||||
let items = [];
|
||||
let items: DataItem[];
|
||||
|
||||
items = response.data.map((item) => ({
|
||||
title: item.title,
|
||||
|
||||
@@ -41,7 +41,7 @@ async function handler() {
|
||||
let itemUrl = '';
|
||||
itemUrl = path.startsWith('http') ? path : host + path;
|
||||
return cache.tryGet(itemUrl, async () => {
|
||||
let description = '';
|
||||
let description: string;
|
||||
let itemDate;
|
||||
if (path) {
|
||||
const result = await got(itemUrl);
|
||||
|
||||
@@ -46,7 +46,7 @@ async function handler() {
|
||||
const path = item.find('a').attr('href');
|
||||
const itemUrl = path.startsWith('http') ? path : host + path;
|
||||
return cache.tryGet(itemUrl, async () => {
|
||||
let description = '';
|
||||
let description: string;
|
||||
if (!path.startsWith('https://') && !path.startsWith('http://')) {
|
||||
const result = await got(itemUrl);
|
||||
const $ = load(result.data);
|
||||
|
||||
@@ -53,7 +53,7 @@ async function handler(ctx) {
|
||||
let itemUrl = '';
|
||||
itemUrl = path.startsWith('http') ? path : host + path;
|
||||
return cache.tryGet(itemUrl, async () => {
|
||||
let description = '';
|
||||
let description: string;
|
||||
if (itemUrl) {
|
||||
const result = await got(itemUrl);
|
||||
const $ = load(result.data);
|
||||
|
||||
@@ -20,9 +20,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.main_left ul li')
|
||||
let items: DataItem[] = $('div.main_left ul li')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -41,7 +41,7 @@ async function handler(ctx) {
|
||||
const chapterArray = await cache.tryGet(
|
||||
strBaseUrl,
|
||||
async () => {
|
||||
let bHasNextPage = false;
|
||||
let bHasNextPage: boolean;
|
||||
let chapters = [];
|
||||
let iReqOffSet = 0;
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'en';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.views-row article')
|
||||
let items: DataItem[] = $('div.views-row article')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -23,9 +23,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('ul.media-list li.media')
|
||||
let items: DataItem[] = $('ul.media-list li.media')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -22,9 +22,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? lang;
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('h4, h6')
|
||||
let items: DataItem[] = $('h4, h6')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -17,9 +17,7 @@ const md = MarkdownIt({
|
||||
const baseUrl = 'https://www.dgtle.com';
|
||||
|
||||
const ProcessItems = async (limit: number, dataList: any): Promise<DataItem[]> => {
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = dataList.slice(0, limit).map((item): DataItem => {
|
||||
let items: DataItem[] = dataList.slice(0, limit).map((item): DataItem => {
|
||||
const title: string = item.title || item.content;
|
||||
const image: string | undefined = item.cover;
|
||||
const description: string | undefined = renderDescription({
|
||||
|
||||
@@ -25,9 +25,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
|
||||
const response = await ofetch(apiUrl);
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = response.data.list.slice(0, limit).map((item): DataItem => {
|
||||
let items: DataItem[] = response.data.list.slice(0, limit).map((item): DataItem => {
|
||||
const title: string = item.title;
|
||||
const image: string | undefined = item.cover?.split(/\?/)?.[0];
|
||||
const description: string | undefined = renderDescription({
|
||||
|
||||
@@ -60,7 +60,7 @@ async function handler(ctx) {
|
||||
return await cache.tryGet(url, async () => {
|
||||
// fetch article content
|
||||
// some contents are only available for internal network
|
||||
let description = '';
|
||||
let description: string;
|
||||
try {
|
||||
const { data: response } = await got(url);
|
||||
const $ = load(response);
|
||||
|
||||
@@ -51,7 +51,7 @@ async function handler() {
|
||||
return await cache.tryGet(url, async () => {
|
||||
// fetch article content
|
||||
// some contents are only available for internal network
|
||||
let description = '';
|
||||
let description: string;
|
||||
try {
|
||||
const { data: response } = await got(url);
|
||||
const $ = load(response);
|
||||
|
||||
@@ -21,9 +21,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'es';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div#printableArea a.text-dark')
|
||||
let items: DataItem[] = $('div#printableArea a.text-dark')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -40,9 +40,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(targetResponse);
|
||||
const language = $('html').attr('lang') ?? 'en';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = response.results.slice(0, limit).map((item): DataItem => {
|
||||
const items: DataItem[] = response.results.slice(0, limit).map((item): DataItem => {
|
||||
const title: string = item.title;
|
||||
const description: string | undefined = item.latest_event?.description ?? undefined;
|
||||
const pubDate: number | string = item.latest_event?.date;
|
||||
|
||||
@@ -45,7 +45,7 @@ async function handler(ctx) {
|
||||
|
||||
const channel_name = channel_info_response.data.title;
|
||||
const data = response.data.modules[nav].payload.subjects;
|
||||
let nav_name = '';
|
||||
let nav_name: string;
|
||||
|
||||
switch (nav) {
|
||||
case '0':
|
||||
|
||||
@@ -45,7 +45,7 @@ async function handler(ctx) {
|
||||
|
||||
const channel_name = channel_info_response.data.title;
|
||||
const data = response.data.items;
|
||||
let nav_name = '';
|
||||
let nav_name: string;
|
||||
|
||||
switch (nav) {
|
||||
case 'hot':
|
||||
|
||||
@@ -23,9 +23,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.post-item')
|
||||
let items: DataItem[] = $('div.post-item')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -26,9 +26,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(iconv.decode(Buffer.from(response), 'gb2312'));
|
||||
const language = $('html').attr('lang') ?? 'zh-CN';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.co_content8 ul table')
|
||||
let items: DataItem[] = $('div.co_content8 ul table')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
function getRatingChangeStr(ratingChange) {
|
||||
let ratingChangeName = '';
|
||||
let ratingChangeName: string;
|
||||
switch (String(ratingChange)) {
|
||||
case '0':
|
||||
ratingChangeName = '调高';
|
||||
|
||||
@@ -34,9 +34,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(targetResponse);
|
||||
const language = $('html').attr('lang') ?? 'en';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = response.data.slice(0, limit).map((item): DataItem => {
|
||||
let items: DataItem[] = response.data.slice(0, limit).map((item): DataItem => {
|
||||
const title: string = item.title;
|
||||
const description: string | undefined = renderDescription({
|
||||
intro: item.description,
|
||||
|
||||
@@ -20,9 +20,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'en';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.main h3 a')
|
||||
let items: DataItem[] = $('div.main h3 a')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -31,9 +31,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
},
|
||||
});
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = response.data.slice(0, limit).map((item): DataItem => {
|
||||
let items: DataItem[] = response.data.slice(0, limit).map((item): DataItem => {
|
||||
const title: string = item.title;
|
||||
const description: string = renderToString(item.zhaiyao ? <blockquote>{item.zhaiyao}</blockquote> : null);
|
||||
const pubDate: number | string = item.createtime;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { config } from '@/config';
|
||||
import type { Route } from '@/types';
|
||||
import type { DataItem, Route } from '@/types';
|
||||
import { ViewType } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
@@ -163,7 +163,7 @@ async function handler(ctx) {
|
||||
},
|
||||
});
|
||||
|
||||
let items = {};
|
||||
let items: DataItem[];
|
||||
|
||||
switch (type) {
|
||||
case 'fanclubs':
|
||||
|
||||
@@ -58,7 +58,7 @@ export const route: Route = {
|
||||
async function handler(ctx) {
|
||||
const bank = ctx.req.param('bank');
|
||||
const target = `${host}/forum-${bank}-1.html`;
|
||||
let bankname = '';
|
||||
let bankname: string;
|
||||
|
||||
switch (bank) {
|
||||
case 'creditcard':
|
||||
|
||||
@@ -55,7 +55,7 @@ export const route: Route = {
|
||||
|
||||
async function handler(ctx) {
|
||||
const category = ctx.req.param('category');
|
||||
let url = '';
|
||||
let url: string;
|
||||
let categoryName = '';
|
||||
const categoryTable = {
|
||||
1: 'PC',
|
||||
@@ -126,7 +126,7 @@ async function handler(ctx) {
|
||||
async (item) => {
|
||||
item.description = await cache.tryGet(item.link, async () => {
|
||||
const response = await got.get(item.link);
|
||||
let component = '';
|
||||
let component: string;
|
||||
const urlReg = /window\.lazySizesConfig/g;
|
||||
|
||||
let pubInfo;
|
||||
|
||||
@@ -29,9 +29,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
},
|
||||
];
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('a.flex-col')
|
||||
let items: DataItem[] = $('a.flex-col')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -31,9 +31,7 @@ const processItems = async (limit: number, query: any, apiUrl: string, targetUrl
|
||||
const included = response.included;
|
||||
const data = [...response.data, ...included].filter((item) => types.has(item.type));
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = data?.slice(0, limit).map((item): DataItem => {
|
||||
const items: DataItem[] = data?.slice(0, limit).map((item): DataItem => {
|
||||
const attributes = item.attributes;
|
||||
const relationships = item.relationships;
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ export const eventTypeMapping: Record<string, string> = {
|
||||
function formatEventItem(event: any) {
|
||||
const { id, type, actor, repo, payload, created_at } = event;
|
||||
|
||||
let title = '';
|
||||
let description = '';
|
||||
let link = '';
|
||||
let title: string;
|
||||
let description: string;
|
||||
let link: string;
|
||||
|
||||
switch (type) {
|
||||
case 'PushEvent': {
|
||||
|
||||
@@ -33,7 +33,7 @@ async function handler(ctx) {
|
||||
const originDomain = 'https://www.gov.cn';
|
||||
let url = '';
|
||||
let title = '';
|
||||
let list = '';
|
||||
let list: string;
|
||||
switch (uid) {
|
||||
case 'bm':
|
||||
url = `${originDomain}/lianbo/bumen/index.htm`;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { load } from 'cheerio';
|
||||
import { renderToString } from 'hono/jsx/dom/server';
|
||||
|
||||
import type { Route } from '@/types';
|
||||
import type { DataItem, Route } from '@/types';
|
||||
import cache from '@/utils/cache';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
@@ -23,8 +23,8 @@ async function handler(ctx) {
|
||||
|
||||
const channelId = $('meta[name="channelid"]').attr('content');
|
||||
|
||||
let data,
|
||||
out = [];
|
||||
let data;
|
||||
let out: DataItem[];
|
||||
if (channelId) {
|
||||
data = await got(`${baseUrl}/searchList/${channelId}`, {
|
||||
searchParams: {
|
||||
|
||||
@@ -39,7 +39,7 @@ export const route: Route = {
|
||||
|
||||
async function handler(ctx) {
|
||||
const { gchannel = 'paimai' } = ctx.req.param();
|
||||
let channelName = '';
|
||||
let channelName: string;
|
||||
let link = '';
|
||||
|
||||
switch (gchannel) {
|
||||
|
||||
@@ -105,8 +105,8 @@ const gdgov = async (info, ctx) => {
|
||||
const currentUrl = `${rootUrl}/${pathname}`;
|
||||
|
||||
let $ = '';
|
||||
let name = '';
|
||||
let list = '';
|
||||
let name: string;
|
||||
let list: string;
|
||||
// 判断是否处于特殊目录
|
||||
if (pathname.startsWith('gkmlpt')) {
|
||||
title_element = undefined;
|
||||
@@ -149,7 +149,7 @@ const gdgov = async (info, ctx) => {
|
||||
}
|
||||
|
||||
const lists = list.map((i, item) => {
|
||||
let link = '';
|
||||
let link: string;
|
||||
|
||||
if (pathname.startsWith('gkmlpt')) {
|
||||
link = i.url;
|
||||
@@ -198,16 +198,13 @@ const gdgov = async (info, ctx) => {
|
||||
const content = load(res);
|
||||
|
||||
// 获取来源
|
||||
let author = '';
|
||||
author = author_element === undefined ? content('meta[name="ContentSource"]').attr('content') : content(author_element).text().trim().match(author_match)[1].trim().replaceAll(/(-*$)/g, '');
|
||||
const author = author_element === undefined ? content('meta[name="ContentSource"]').attr('content') : content(author_element).text().trim().match(author_match)[1].trim().replaceAll(/(-*$)/g, '');
|
||||
|
||||
// 获取发布时间
|
||||
let pubDate = '';
|
||||
pubDate = pubDate_element === undefined ? content('meta[name="PubDate"]').attr('content') : content(pubDate_element).text().trim().match(pubDate_match)[1].trim().replaceAll(/(-*$)/g, '');
|
||||
const pubDate = pubDate_element === undefined ? content('meta[name="PubDate"]').attr('content') : content(pubDate_element).text().trim().match(pubDate_match)[1].trim().replaceAll(/(-*$)/g, '');
|
||||
|
||||
// 获取标题
|
||||
let title = '';
|
||||
title = title_element === undefined ? content('meta[name="ArticleTitle"]').attr('content') : content(title_element).text().trim().match(title_match)[1];
|
||||
const title = title_element === undefined ? content('meta[name="ArticleTitle"]').attr('content') : content(title_element).text().trim().match(title_match)[1];
|
||||
// 获取正文
|
||||
const description_content = description_element.split(',').filter((item) => item !== '');
|
||||
for (let index = 0; index < description_content.length; index++) {
|
||||
|
||||
@@ -16,14 +16,14 @@ async function handler(ctx) {
|
||||
.filter((item) => item !== '');
|
||||
let pathstartat = 0;
|
||||
let defaultPath = '';
|
||||
let list_element = '';
|
||||
let list_element: string;
|
||||
let list_include = 'site';
|
||||
let title_element = '';
|
||||
let title_element: string;
|
||||
let title_match = '(.*)';
|
||||
let description_element = '';
|
||||
let authorisme = '';
|
||||
let pubDate_element = '';
|
||||
let pubDate_match = '';
|
||||
let description_element: string;
|
||||
let authorisme: string;
|
||||
let pubDate_element: string;
|
||||
let pubDate_match: string;
|
||||
// let pubDate_format = undefined;
|
||||
switch (path[1]) {
|
||||
case 'www':
|
||||
|
||||
@@ -30,8 +30,8 @@ export const route: Route = {
|
||||
};
|
||||
|
||||
async function handler(ctx) {
|
||||
let id = '';
|
||||
let name = '';
|
||||
let id: string;
|
||||
let name: string;
|
||||
|
||||
switch (ctx.req.param('category')) {
|
||||
case 'zwgk':
|
||||
|
||||
@@ -21,9 +21,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('a.cjcx_biaob, ul#div li a')
|
||||
let items: DataItem[] = $('a.cjcx_biaob, ul#div li a')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -21,9 +21,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh-CN';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('ul#div li')
|
||||
let items: DataItem[] = $('ul#div li')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -247,7 +247,7 @@ function dealLink(element, url) {
|
||||
// host 不同的是外部文章,outside
|
||||
// url 里带 govpublic 的都是公示文章,govpublic
|
||||
// 其他的都算普通文章,normal
|
||||
let pageType = null;
|
||||
let pageType: string;
|
||||
if (host === hostUrlObj.host) {
|
||||
pageType = href.includes('gk') || href.includes('govpublic') ? 'govpublic' : 'normal';
|
||||
} else {
|
||||
|
||||
@@ -20,9 +20,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.tab-pane a')
|
||||
let items: DataItem[] = $('div.tab-pane a')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -58,10 +58,10 @@ export const route: Route = {
|
||||
async function handler(ctx) {
|
||||
const rootUrl = 'https://www.suzhou.gov.cn';
|
||||
const uid = ctx.req.param('uid');
|
||||
let url = '';
|
||||
let title = '';
|
||||
let url: string;
|
||||
let title: string;
|
||||
let apiUrl = '';
|
||||
let items = [];
|
||||
let items: DataItem[];
|
||||
switch (uid) {
|
||||
case 'szyw':
|
||||
case 'news':
|
||||
|
||||
@@ -71,7 +71,7 @@ async function handler(ctx) {
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
cache.tryGet(item.link, async () => {
|
||||
let description = '';
|
||||
let description: string;
|
||||
try {
|
||||
const contentData = await got(item.link);
|
||||
const $ = load(contentData.data);
|
||||
|
||||
@@ -20,9 +20,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh-CN';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.m_listpagebox ol li a')
|
||||
let items: DataItem[] = $('div.m_listpagebox ol li a')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -35,7 +35,7 @@ export default parseList;
|
||||
|
||||
async function tryGetFullText(href, link, type) {
|
||||
let articleData = '';
|
||||
let description = '';
|
||||
let description: string;
|
||||
// for some unexpected href link
|
||||
try {
|
||||
const articleRes = await got(link);
|
||||
@@ -97,7 +97,7 @@ async function ggtzParse(ctx, $) {
|
||||
const result = await cache.tryGet(link, async () => {
|
||||
const { articleData, description } = await tryGetFullText(href, link, 'ggtz');
|
||||
let author = '';
|
||||
let pubDate = '';
|
||||
let pubDate: string;
|
||||
if (typeof articleData === 'function') {
|
||||
const header = articleData('h1').next().text();
|
||||
const index = header.indexOf('日期');
|
||||
@@ -176,7 +176,7 @@ async function zsjycParse(ctx, $) {
|
||||
const result = await cache.tryGet(link, async () => {
|
||||
const { articleData, description } = await tryGetFullText(href, link, 'zsjyc');
|
||||
|
||||
let pubDate = '';
|
||||
let pubDate: string;
|
||||
if (typeof articleData === 'function') {
|
||||
const date = articleData('span[class=timestyle127702]').text();
|
||||
pubDate = parseDate(date, 'YYYY-MM-DD HH:mm');
|
||||
|
||||
@@ -22,9 +22,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('li.news, div.tbt17')
|
||||
let items: DataItem[] = $('li.news, div.tbt17')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -100,7 +100,7 @@ async function handler(ctx) {
|
||||
|
||||
// 提取文章内容 - 只使用主要内容选择器
|
||||
const content = $detail('.v_news_content');
|
||||
let description = '';
|
||||
let description: string;
|
||||
|
||||
if (content.length > 0) {
|
||||
// 清理内容
|
||||
|
||||
@@ -71,7 +71,7 @@ async function handler(ctx) {
|
||||
});
|
||||
|
||||
const list = JSON.parse(response.data.match(/"data":(\[{.*}])}/)[1]).map((item) => {
|
||||
let link = '';
|
||||
let link: string;
|
||||
|
||||
if (item.UrlPath_en) {
|
||||
link = item[`UrlPath_${language}`].includes('http') ? item[`UrlPath_${language}`] : `${rootUrl}${item[`UrlPath_${language}`]}`;
|
||||
|
||||
@@ -55,7 +55,7 @@ async function handler(ctx) {
|
||||
const notes = note_data.extData.list;
|
||||
const items = await Promise.all(
|
||||
notes.map(async (item) => {
|
||||
let desc = '';
|
||||
let desc: string;
|
||||
switch (item.type) {
|
||||
case 'normal':
|
||||
desc = `<p><img src="${item.imageUrl}"></p>`;
|
||||
|
||||
@@ -15,7 +15,7 @@ export function extractNextData<T = unknown>(html: string, url?: string): T {
|
||||
try {
|
||||
return JSON.parse(scriptMatch[1]) as T;
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to parse __NEXT_DATA__ JSON: ${error instanceof Error ? error.message : String(error)}`);
|
||||
throw new Error(`Failed to parse __NEXT_DATA__ JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,9 +40,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(targetResponse);
|
||||
const language = $('html').attr('lang') ?? 'en';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = response.slice(0, limit).map((item): DataItem => {
|
||||
const items: DataItem[] = response.slice(0, limit).map((item): DataItem => {
|
||||
const title: string = item.title?.rendered ?? item.title;
|
||||
const description: string | undefined = item.content.rendered;
|
||||
const pubDate: number | string = item.date_gmt;
|
||||
|
||||
@@ -9,7 +9,7 @@ const renderItems = (items) =>
|
||||
// Content
|
||||
const summary = item.caption?.text ?? '';
|
||||
|
||||
let description = '';
|
||||
let description: string;
|
||||
switch (productType) {
|
||||
case 'carousel_container': {
|
||||
const images = item.carousel_media.map((i) => ({
|
||||
|
||||
@@ -154,7 +154,7 @@ const renderGuestItems = (items) => {
|
||||
const type = node.__typename;
|
||||
const summary = node.edge_media_to_caption.edges[0]?.node.text ?? '';
|
||||
|
||||
let description = '';
|
||||
let description: string;
|
||||
switch (type) {
|
||||
// carousel, can include GraphVideo and GraphImage
|
||||
case 'GraphSidecar':
|
||||
|
||||
@@ -20,9 +20,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'zh';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('div.right_content_item a')
|
||||
let items: DataItem[] = $('div.right_content_item a')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -45,7 +45,7 @@ async function handler(ctx) {
|
||||
}
|
||||
|
||||
let pos = 1;
|
||||
let hasMore = false;
|
||||
let hasMore: boolean;
|
||||
let epgs = [];
|
||||
do {
|
||||
const {
|
||||
|
||||
@@ -230,9 +230,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
},
|
||||
});
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = response.List.slice(0, limit).map((item): DataItem => {
|
||||
let items: DataItem[] = response.List.slice(0, limit).map((item): DataItem => {
|
||||
const title: string =
|
||||
item.reportname ??
|
||||
(() => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Route } from '@/types';
|
||||
import type { DataItem, Route } from '@/types';
|
||||
import got from '@/utils/got';
|
||||
import { parseDate } from '@/utils/parse-date';
|
||||
|
||||
@@ -65,7 +65,7 @@ async function handler(ctx) {
|
||||
const response = await got(url);
|
||||
const data = response.data;
|
||||
|
||||
let items = {};
|
||||
let items: DataItem[];
|
||||
|
||||
if (category) {
|
||||
const newsFilteredByCategory = data.filter((item) => item.category === categories[category]);
|
||||
|
||||
@@ -37,8 +37,8 @@ async function handler(ctx) {
|
||||
'6824710203112423437': '树洞一下',
|
||||
};
|
||||
|
||||
let url = '';
|
||||
let json = {};
|
||||
let url: string;
|
||||
let json: Record<string, unknown>;
|
||||
if (/^\d+$/.test(type)) {
|
||||
url = `https://api.juejin.cn/recommend_api/v1/short_msg/topic`;
|
||||
json = { id_type: 4, sort_type: 500, cursor: '0', limit: 20, topic_id: type };
|
||||
|
||||
@@ -412,6 +412,6 @@ async function handler(ctx) {
|
||||
item: items,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to fetch data from Kemono: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
throw new Error(`Failed to fetch data from Kemono: ${error instanceof Error ? error.message : 'Unknown error'}`, { cause: error });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'en';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('main a.group')
|
||||
let items: DataItem[] = $('main a.group')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
@@ -19,9 +19,7 @@ export const handler = async (ctx: Context): Promise<Data> => {
|
||||
const $: CheerioAPI = load(response);
|
||||
const language = $('html').attr('lang') ?? 'en';
|
||||
|
||||
let items: DataItem[] = [];
|
||||
|
||||
items = $('a.block')
|
||||
let items: DataItem[] = $('a.block')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((el): Element => {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user