diff --git a/lib/routes/zaimanhua/update.ts b/lib/routes/zaimanhua/update.ts index 939de35a8..28d15f9f0 100644 --- a/lib/routes/zaimanhua/update.ts +++ b/lib/routes/zaimanhua/update.ts @@ -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: '再漫画 - 最近更新',