* chore(deps-dev): bump eslint-plugin-unicorn from 60.0.0 to 61.0.1 Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 60.0.0 to 61.0.1. - [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases) - [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v60.0.0...v61.0.1) --- updated-dependencies: - dependency-name: eslint-plugin-unicorn dependency-version: 61.0.1 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * refactor: replace `replace(/regex/g)` with replaceAll * refactor: replace sort() with toSorted() for immutability in various routes and utilities * refactor: fix unicorn/prefer-array-find * refactor: fix unicorn/prefer-at * refactor: add unicorn/no-array-sort rule to ESLint configuration --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
85 lines
2.4 KiB
TypeScript
85 lines
2.4 KiB
TypeScript
import { Route } from '@/types';
|
|
import cache from '@/utils/cache';
|
|
import got from '@/utils/got';
|
|
import { load } from 'cheerio';
|
|
import timezone from '@/utils/timezone';
|
|
import { parseDate } from '@/utils/parse-date';
|
|
|
|
const host = 'https://www.ymgal.games';
|
|
|
|
const types = {
|
|
news: '?type=NEWS&page=1',
|
|
column: '?type=COLUMN&page=1',
|
|
};
|
|
|
|
export const route: Route = {
|
|
path: '/article/:type?',
|
|
categories: ['anime'],
|
|
example: '/ymgal/article',
|
|
parameters: { type: '文章类型' },
|
|
features: {
|
|
requireConfig: false,
|
|
requirePuppeteer: false,
|
|
antiCrawler: false,
|
|
supportBT: false,
|
|
supportPodcast: false,
|
|
supportScihub: false,
|
|
},
|
|
name: '文章',
|
|
maintainers: ['SunBK201'],
|
|
handler,
|
|
description: `| 全部文章 | 资讯 | 专栏 |
|
|
| -------- | ---- | ------ |
|
|
| all | news | column |`,
|
|
};
|
|
|
|
async function handler(ctx) {
|
|
const type = ctx.req.param('type') || 'all';
|
|
|
|
const link = `${host}/co/topic/list` + types[type];
|
|
let data = [];
|
|
if (type === 'all') {
|
|
await Promise.all(
|
|
Object.values(types).map(async (type) => {
|
|
const response = await got(`${host}/co/topic/list${type}`);
|
|
data.push(...response.data.data);
|
|
})
|
|
);
|
|
data = data.toSorted((a, b) => b.publishTime - a.publishTime).slice(0, 10);
|
|
} else {
|
|
const response = await got(link);
|
|
data = response.data.data;
|
|
}
|
|
|
|
const items = await Promise.all(
|
|
data.map((item) => {
|
|
const itemUrl = host + '/co/article/' + item.topicId;
|
|
return cache.tryGet(itemUrl, async () => {
|
|
const result = await got(itemUrl);
|
|
const $ = load(result.data);
|
|
const description = $('article').html().trim();
|
|
return {
|
|
title: item.title,
|
|
link: itemUrl,
|
|
pubDate: timezone(parseDate(item.publishTime), 8),
|
|
description,
|
|
};
|
|
});
|
|
})
|
|
);
|
|
|
|
let info = '全部文章';
|
|
if (type === 'news') {
|
|
info = '资讯';
|
|
} else if (type === 'column') {
|
|
info = '专栏';
|
|
}
|
|
|
|
return {
|
|
title: `月幕 Galgame - ${info}`,
|
|
link: `${host}/co/article`,
|
|
description: `月幕 Galgame - ${info}`,
|
|
item: items,
|
|
};
|
|
}
|