feat(route/zaimanhua): enhance update route and fetch comic chapter details (#19147)

This commit is contained in:
Kjasn 2025-05-20 21:48:47 +08:00 committed by GitHub
parent 7d80c36027
commit 6982390d71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 42 additions and 10 deletions

View File

@ -2,6 +2,10 @@ import { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { config } from '@/config';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import path from 'node:path';
import cache from '@/utils/cache';
import pMap from 'p-map';
export const route: Route = {
path: '/update',
@ -34,16 +38,44 @@ export const route: Route = {
},
});
const data = response.data.comicList;
const items = data.map((item) => ({
title: item.name,
author: item.author,
link: `${baseUrl}/view/${item.comic_py}/${item.id}/${item.last_update_chapter_id}`,
image: item.cover,
description: `[${item.status}] | ${item.name} - ${item.last_update_chapter_name}`,
category: [item.status, ...item.types.split('/').map((type) => type.trim())],
pubDate: parseDate(item.last_updatetime * 1000),
}));
// 近期更新漫画数据
const updateData = response.data.comicList;
const items = await pMap(
updateData,
async (item) => {
const comicId = item.id;
const lastUpdateChapterId = item.last_update_chapter_id;
const comicPy = item.comic_py;
// 当前漫画章节内容的 API
const chapterUrl = `${baseUrl}/api/v1/comic2/chapter/detail?comic_id=${comicId}&chapter_id=${lastUpdateChapterId}`;
return await cache.tryGet(chapterUrl, async () => {
// 获取章节内容
const chapterResponse = await ofetch(chapterUrl, {
headers: {
'user-agent': config.trueUA,
referer: baseUrl,
},
});
const chapterData = chapterResponse.data;
const description = art(path.join(__dirname, 'template/comic.art'), {
contents: chapterData.chapterInfo.page_url || [],
});
return {
title: `[${item.status}] | ${item.name} - ${item.last_update_chapter_name}`,
author: item.authors,
category: [item.status, ...item.types.split('/').map((type) => type.trim())],
image: item.cover,
link: `${baseUrl}/view/${comicPy}/${comicId}/${lastUpdateChapterId}`,
pubDate: parseDate(item.last_updatetime * 1000),
description,
};
});
},
{ concurrency: 3 }
);
return {
title: '再漫画 - 最近更新',