Skip to content

Commit

Permalink
chore(deps): bump tiny-async-pool from 1.2.0 to 2.0.1 (#9350)
Browse files Browse the repository at this point in the history
* chore(deps): bump tiny-async-pool from 1.2.0 to 2.0.1

Bumps [tiny-async-pool](https://github.com/rxaviers/async-pool) from 1.2.0 to 2.0.1.
- [Release notes](https://github.com/rxaviers/async-pool/releases)
- [Commits](rxaviers/async-pool@v1.2.0...v2.0.1)

---
updated-dependencies:
- dependency-name: tiny-async-pool
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

* fix(route): tiny-async-pool v2 compatibility, url.resolve

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: TonyRL <[email protected]>
  • Loading branch information
dependabot[bot] and TonyRL authored Mar 20, 2022
1 parent 6477e6b commit db78d3d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 62 deletions.
47 changes: 24 additions & 23 deletions lib/routes/novel/biquge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
const asyncPool = require('tiny-async-pool');
const { parseDate } = require('@/utils/parse-date');

const baseUrl = 'http://www.biquge5200.com/';
// 获取小说的最新章节列表
Expand All @@ -25,36 +26,36 @@ module.exports = async (ctx) => {
.map((_, e) => ({
title: e.children[0].data,
link: e.attribs.href,
pubDate: new Date((parseInt(e.attribs.href.split('/').pop().replace('.html', '')) - 15015015) * 10000).toUTCString(),
pubDate: parseDate((parseInt(e.attribs.href.split('/').pop().replace('.html', '')) - 15015015) * 10000),
}))
.get();

const items = await asyncPool(3, chapter_item, async (item) => {
const cache = await ctx.cache.get(item.link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const items = [];
for await (const item of asyncPool(3, chapter_item, (item) =>
ctx.cache.tryGet(item, async () => {
const response = await got({
method: 'get',
url: item.link,
responseType: 'buffer',
});

const response = await got({
method: 'get',
url: item.link,
responseType: 'buffer',
});
const responseHtml = iconv.decode(response.data, 'GBK');
const $ = cheerio.load(responseHtml);

const responseHtml = iconv.decode(response.data, 'GBK');
const $ = cheerio.load(responseHtml);
const description = $('#content').html();

const description = $('#content').html();
const single = {
title: item.title,
description,
link: item.link,
pubDate: item.pubDate,
};
return single;
})
)) {
items.push(item);
}

const single = {
title: item.title,
description,
link: item.link,
pubDate: item.pubDate,
};
ctx.cache.set(item.link, JSON.stringify(single));
return Promise.resolve(single);
});
ctx.state.data = {
title: `笔趣阁 ${title}`,
link: `${baseUrl}${id}/`,
Expand Down
52 changes: 26 additions & 26 deletions lib/routes/novel/biqugeinfo.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const iconv = require('iconv-lite');
const url = require('url');
const asyncPool = require('tiny-async-pool');
const { parseDate } = require('@/utils/parse-date');

const firstDay = new Date('2020-01-01');
const baseUrl = 'http://www.biquge.info';
// 获取小说的最新章节列表
module.exports = async (ctx) => {
const { id, limit = 10 } = ctx.params; // 小说id
const pageUrl = url.resolve(baseUrl, `/${id}/`);
const pageUrl = new URL(`/${id}/`, baseUrl);

const response = await got({
method: 'get',
Expand All @@ -28,37 +28,37 @@ module.exports = async (ctx) => {
.find('a')
.map((i, e) => ({
title: e.children[0].data,
link: url.resolve(pageUrl, e.attribs.href),
pubDate: new Date(firstDay.getTime() + (nItems - parseInt(limit) + i) * 1000 * 60 * 60 * 24),
link: new URL(e.attribs.href, pageUrl),
pubDate: parseDate(firstDay.getTime() + (nItems - parseInt(limit) + i) * 1000 * 60 * 60 * 24),
}))
.get();

const items = await asyncPool(3, chapter_item, async (item) => {
const cache = await ctx.cache.get(item.link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const items = [];
for await (const item of asyncPool(3, chapter_item, (item) =>
ctx.cache.tryGet(item, async () => {
const response = await got({
method: 'get',
url: item.link,
responseType: 'buffer',
});

const response = await got({
method: 'get',
url: item.link,
responseType: 'buffer',
});
const responseHtml = iconv.decode(response.data, 'utf-8');
const $ = cheerio.load(responseHtml);

const responseHtml = iconv.decode(response.data, 'utf-8');
const $ = cheerio.load(responseHtml);
const description = $('#content').html();

const description = $('#content').html();
const single = {
title: item.title,
description,
link: item.link,
pubDate: item.pubDate,
};
return single;
})
)) {
items.push(item);
}

const single = {
title: item.title,
description,
link: item.link,
pubDate: item.pubDate,
};
ctx.cache.set(item.link, JSON.stringify(single));
return Promise.resolve(single);
});
ctx.state.data = {
title: `笔趣阁 ${title}`,
link: pageUrl,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"simplecc-wasm": "0.1.4",
"socks-proxy-agent": "6.1.1",
"string-similarity": "4.0.4",
"tiny-async-pool": "1.2.0",
"tiny-async-pool": "2.0.1",
"torrent-search-api": "2.1.4",
"tough-cookie": "4.0.0",
"tunnel": "0.0.6",
Expand Down
16 changes: 4 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13014,13 +13014,10 @@ timsort@^0.3.0:
resolved "https://registry.yarnpkg.com/timsort/-/timsort-0.3.0.tgz#405411a8e7e6339fe64db9a234de11dc31e02bd4"
integrity sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=

[email protected]:
version "1.2.0"
resolved "https://registry.yarnpkg.com/tiny-async-pool/-/tiny-async-pool-1.2.0.tgz#22132957e18f8b6020a94b390d07718fd519cc71"
integrity sha512-PY/OiSenYGBU3c1nTuP1HLKRkhKFDXsAibYI5GeHbHw2WVpt6OFzAPIRP94dGnS66Jhrkheim2CHAXUNI4XwMg==
dependencies:
semver "^5.5.0"
yaassertion "^1.0.0"
[email protected]:
version "2.0.1"
resolved "https://registry.yarnpkg.com/tiny-async-pool/-/tiny-async-pool-2.0.1.tgz#b91a5e9fa539f2d89b2201cd843a7341fe2710a7"
integrity sha512-QIXBQdZdFWb7sLsuS5R8+23YdUXypkplXG+C3AMkEVzUlAZ/2EWrQzfAey0l4/r8ih+F7KgbJdPWHrfOce908A==

[email protected]:
version "1.224.0"
Expand Down Expand Up @@ -14482,11 +14479,6 @@ y18n@^5.0.5:
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==

yaassertion@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/yaassertion/-/yaassertion-1.0.2.tgz#f1a90166e1cc4ad44dbb71487009ebca017e9874"
integrity sha512-sBoJBg5vTr3lOpRX0yFD+tz7wv/l2UPMFthag4HGTMPrypBRKerjjS8jiEnNMjcAEtPXjbHiKE0UwRR1W1GXBg==

yallist@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"
Expand Down

0 comments on commit db78d3d

Please sign in to comment.