* chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0 Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 64.0.0 to 65.0.0. - [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases) - [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v64.0.0...v65.0.0) --- updated-dependencies: - dependency-name: eslint-plugin-unicorn dependency-version: 65.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * fix: no-array-from-fill * fix: unicorn-js/no-duplicate-set-values * fix: no-this-outside-of-class * fix: no-unnecessary-nested-ternary * fix: prefer-array-last-methods * fix: prefer-queue-microtask * fix: prefer-split-limit * fix: no-array-from-fill * fix: no-unused-array-method-return * fix: prefer-single-call * fix: prefer-includes-over-repeated-comparisons * fix: consistent-compound-words * fix: prefer-includes-over-repeated-comparisons * chore: add eslint-plugin-unicorn v65 recommended preset * fix: correct duration parsing logic in parseDuration function * fix: update oxlint-disable --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tony <TonyRL@users.noreply.github.com>
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { load } from 'cheerio';
|
|
|
|
import cache from '@/utils/cache';
|
|
import got from '@/utils/got';
|
|
import { parseDate } from '@/utils/parse-date';
|
|
import timezone from '@/utils/timezone';
|
|
|
|
import { ProcessItems, rootUrl } from './utils';
|
|
|
|
export async function handler(ctx) {
|
|
const { type, id } = ctx.req.param();
|
|
|
|
const currentUrl = type ? `${rootUrl}/${type}/${id}.htm` : rootUrl;
|
|
|
|
let response = await got(currentUrl);
|
|
|
|
const $ = load(response.data);
|
|
|
|
const token = encodeURI($('meta[name="csrf-token"]').attr('content'));
|
|
const apiUrl = `${rootUrl}/home/more?&type=${$('div[data-type]').data('type')}&page=1&_csrf=${token}&_=${Date.now()}`;
|
|
|
|
response = await got(apiUrl);
|
|
|
|
const items = type
|
|
? response.data.result.list.map((item) => ({
|
|
title: item.title,
|
|
description: item.hometext,
|
|
author: item.source.split('@http', 1)[0],
|
|
pubDate: timezone(parseDate(item.inputtime), +8),
|
|
link: item.url_show.startsWith('//') ? `https:${item.url_show}` : item.url_show.replace('http:', 'https:'),
|
|
category: item.label.name,
|
|
}))
|
|
: response.data.result.map((item) => ({
|
|
title: item.title,
|
|
link: item.url_show.startsWith('//') ? `https:${item.url_show}` : item.url_show.replace('http:', 'https:'),
|
|
category: item.label.name,
|
|
}));
|
|
|
|
return {
|
|
title: $('title').text(),
|
|
link: currentUrl,
|
|
item: await ProcessItems(items, ctx.req.query('limit'), cache.tryGet),
|
|
};
|
|
}
|