Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route):add 拷贝漫画 #7896

Merged
merged 22 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/anime.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ pageClass: routes

<Route author="btdwv" path="/twmanhuagui/comic/:id" example="/twmanhuagui/comic/13317" :paramsDesc="['漫画ID']" radar="1" rssbud="1"/>

## 拷贝漫画

### 漫画更新

<Route author="btdwv" path="/copymanga/comic/:id" example="/copymanga/comic/zhandoupohuaixueyuandangerous" :paramsDesc="['漫画ID']" radar="1" rssbud="1"/>

## 漫画 DB

### 漫画 DB
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 67 additions & 0 deletions lib/routes/copymanga/comic.js
Original file line number Diff line number Diff line change
@@ -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: `
<h1>${chapter.num}p</h1>
btdwv marked this conversation as resolved.
Show resolved Hide resolved
`.trim(),
});

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