diff --git a/docs/anime.md b/docs/anime.md index 81e946be5d4a67..fbc78e51e8c5f3 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -318,6 +318,12 @@ pageClass: routes +## 拷贝漫画 + +### 漫画更新 + + + ## 漫画 DB ### 漫画 DB diff --git a/lib/router.js b/lib/router.js index bd6d61f9bcce84..40dabfbf793d27 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1137,6 +1137,9 @@ router.get('/manhuagui/comic/:id', lazyloadRouteHandler('./routes/manhuagui/comi router.get('/mhgui/comic/:id', lazyloadRouteHandler('./routes/mhgui/comic')); router.get('/twmanhuagui/comic/:id', lazyloadRouteHandler('./routes/twmanhuagui/comic')); +// 拷贝漫画 +router.get('/copymanga/comic/:id', lazyloadRouteHandler('./routes/copymanga/comic')); + // 動漫狂 router.get('/cartoonmad/comic/:id', lazyloadRouteHandler('./routes/cartoonmad/comic')); // Vol diff --git a/lib/routes/copymanga/comic.js b/lib/routes/copymanga/comic.js new file mode 100644 index 00000000000000..c5697f8ff0ad76 --- /dev/null +++ b/lib/routes/copymanga/comic.js @@ -0,0 +1,67 @@ +const cheerio = require('cheerio'); +const got = require('@/utils/got'); + +// 直接调用拷贝漫画的接口 +module.exports = async (ctx) => { + const { id } = ctx.params; + + // 获取漫画列表 + let bHasNextPage = false; + const iReqLimit = (ctx.queries && ctx.queries.limit) || 100; + let iReqOffSet = 0; + const strBaseUrl = `https://api.copymanga.com/api/v3/comic/${id}/group/default/chapters?`; + let chapterArray = []; + + do { + bHasNextPage = false; + // eslint-disable-next-line no-await-in-loop + const { data } = await got.get(strBaseUrl + 'limit=' + iReqLimit + '&offset=' + iReqOffSet); + const { code, results } = data; + + if (code !== 200) { + break; + } + + if (results.limit + results.offset < results.total) { + bHasNextPage = true; + } + iReqOffSet += iReqLimit; + + chapterArray = chapterArray.concat(results.list); + } while (bHasNextPage); + + chapterArray = chapterArray + .map(({ comic_path_word, uuid, name, size, datetime_created, index }) => ({ + link: 'https://copymanga.com/comic/' + comic_path_word + '/chapter/' + uuid, + title: name, + num: size, + updateTime: datetime_created, + index, + })) + .reverse(); + + // 获取漫画标题、介绍 + const { bookTitle, bookIntro } = await ctx.cache.tryGet(`https://copymanga.com/comic/${id}`, async () => { + const { data } = await got.get(`https://copymanga.com/comic/${id}`); + const $ = cheerio.load(data); + return { + bookTitle: $('.comicParticulars-title-right > ul > li > h6').text(), + bookIntro: $('.intro').text(), + }; + }); + + const genResult = (chapter) => ({ + link: chapter.link, + title: chapter.title, + description: ` +

${chapter.num}p

+ `.trim(), + }); + + ctx.state.data = { + title: `拷贝漫画 - ${bookTitle}`, + link: `https://copymanga.com/comic/${id}`, + description: bookIntro, + item: chapterArray.map(genResult), + }; +};