refactor(eslint): add back no-return-await (#11877)
* chore: add back no-return-await * chore: fix action warning * chore: fix all no-return-await
This commit is contained in:
+2
-1
@@ -2,7 +2,7 @@
|
||||
"extends": ["eslint:recommended", "plugin:prettier/recommended", "plugin:yml/recommended"],
|
||||
"plugins": ["prettier"],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2020,
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"env": {
|
||||
@@ -65,6 +65,7 @@
|
||||
"no-prototype-builtins": 0,
|
||||
"no-new-func": 2,
|
||||
"require-await": 2,
|
||||
"no-return-await": 2,
|
||||
"prefer-arrow-callback": 2,
|
||||
"object-shorthand": 2,
|
||||
"yml/quotes": [
|
||||
|
||||
@@ -23,6 +23,9 @@ jobs:
|
||||
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 5
|
||||
permissions:
|
||||
contents: read
|
||||
security-events: write
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
|
||||
@@ -29,19 +29,18 @@ module.exports = async (ctx) => {
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.middle_box').html();
|
||||
item.description = content('.middle_box').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -31,21 +31,20 @@ module.exports = async (ctx) => {
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('.newsTitle, .ads').remove();
|
||||
content('.newsTitle, .ads').remove();
|
||||
|
||||
item.description = content('div[itemprop="text"]').html();
|
||||
item.description = content('div[itemprop="text"]').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -43,21 +43,20 @@ module.exports = async (ctx) => {
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('.newsTitle, .ads').remove();
|
||||
content('.newsTitle, .ads').remove();
|
||||
|
||||
item.description = content('div[itemprop="text"]').html();
|
||||
item.description = content('div[itemprop="text"]').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ const path = require('path');
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const ProcessFeed = async (limit, offset) =>
|
||||
await got({
|
||||
const ProcessFeed = (limit, offset) =>
|
||||
got({
|
||||
method: 'post',
|
||||
url: 'https://music.163.com/api/dj/program/byradio',
|
||||
headers: {
|
||||
|
||||
@@ -94,23 +94,22 @@ module.exports = async (ctx) => {
|
||||
}));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('img[_ngcontent-c11]').each(function () {
|
||||
content(this).attr('alt', '');
|
||||
});
|
||||
content('img[_ngcontent-c11]').each(function () {
|
||||
content(this).attr('alt', '');
|
||||
});
|
||||
|
||||
item.description = content('.text').html();
|
||||
item.description = content('.text').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+11
-12
@@ -22,20 +22,19 @@ module.exports = async (ctx) => {
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.post-content').html();
|
||||
item.pubDate = Date.parse(content('small time').attr('datetime'));
|
||||
item.description = content('.post-content').html();
|
||||
item.pubDate = Date.parse(content('small time').attr('datetime'));
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -187,9 +187,9 @@ const normalizeUrl = (url, bypassHostCheck = false) => {
|
||||
* @param {boolean} bypassHostCheck - Whether to bypass host check.
|
||||
* @return {Promise<object>} - An object containing the article and its metadata.
|
||||
*/
|
||||
const fetchArticle = async (ctx, url, bypassHostCheck = false) => {
|
||||
const fetchArticle = (ctx, url, bypassHostCheck = false) => {
|
||||
url = normalizeUrl(url, bypassHostCheck);
|
||||
return await ctx.cache.tryGet(url, async () => {
|
||||
return ctx.cache.tryGet(url, async () => {
|
||||
const response = await got(url);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
|
||||
+10
-11
@@ -33,19 +33,18 @@ module.exports = async (ctx) => {
|
||||
}));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.info-content').html();
|
||||
item.description = content('.info-content').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+10
-11
@@ -33,19 +33,18 @@ module.exports = async (ctx) => {
|
||||
}));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.info-content').html();
|
||||
item.description = content('.info-content').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ const rootUrl = 'https://www.abmedia.io';
|
||||
const cateAPIUrl = `${rootUrl}/wp-json/wp/v2/categories`;
|
||||
const postsAPIUrl = `${rootUrl}/wp-json/wp/v2/posts`;
|
||||
|
||||
const getCategoryId = async (category) => await got.get(`${cateAPIUrl}?slug=${category}`).then((res) => res.data[0].id);
|
||||
const getCategoryId = (category) => got.get(`${cateAPIUrl}?slug=${category}`).then((res) => res.data[0].id);
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category ?? 'technology-development';
|
||||
|
||||
+41
-42
@@ -54,49 +54,48 @@ module.exports = async (ctx) => {
|
||||
.slice(0, ctx.query.limit || 20);
|
||||
|
||||
items = await Promise.all(
|
||||
items.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got(item.link);
|
||||
const $ = cheerio.load(response.data);
|
||||
// fix weird format
|
||||
let description = '';
|
||||
const content = $('div.content_all');
|
||||
if (content.length) {
|
||||
content
|
||||
.eq(content.length - 1) // some pages have "summary"
|
||||
.contents()
|
||||
.each((_, child) => {
|
||||
const $child = $(child);
|
||||
let innerHtml;
|
||||
if (child.name === 'div') {
|
||||
innerHtml = $child.html();
|
||||
innerHtml = innerHtml && innerHtml.trim();
|
||||
description += !innerHtml || innerHtml === ' ' ? (description ? '<br>' : '') : innerHtml;
|
||||
} else {
|
||||
// bare text node or something else
|
||||
description += $child.toString().trim();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// http://rail.ally.net.cn/html/2022/InviteTen_0407/4686.html
|
||||
description = $('div.content div').first().html();
|
||||
}
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got(item.link);
|
||||
const $ = cheerio.load(response.data);
|
||||
// fix weird format
|
||||
let description = '';
|
||||
const content = $('div.content_all');
|
||||
if (content.length) {
|
||||
content
|
||||
.eq(content.length - 1) // some pages have "summary"
|
||||
.contents()
|
||||
.each((_, child) => {
|
||||
const $child = $(child);
|
||||
let innerHtml;
|
||||
if (child.name === 'div') {
|
||||
innerHtml = $child.html();
|
||||
innerHtml = innerHtml && innerHtml.trim();
|
||||
description += !innerHtml || innerHtml === ' ' ? (description ? '<br>' : '') : innerHtml;
|
||||
} else {
|
||||
// bare text node or something else
|
||||
description += $child.toString().trim();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// http://rail.ally.net.cn/html/2022/InviteTen_0407/4686.html
|
||||
description = $('div.content div').first().html();
|
||||
}
|
||||
|
||||
description = description.replace(/\s*<br ?\/?>\s*$/, ''); // trim <br> at the end
|
||||
const info = $('.content > em span');
|
||||
return {
|
||||
title: $('.content > h2').text() || item.title,
|
||||
description,
|
||||
// pubDate: timezone(parseDate(info.eq(0).text()), 8),
|
||||
pubDate: item.pubDate,
|
||||
author: info
|
||||
.eq(1)
|
||||
.text()
|
||||
.replace(/^来源:/, ''),
|
||||
link: item.link,
|
||||
};
|
||||
})
|
||||
description = description.replace(/\s*<br ?\/?>\s*$/, ''); // trim <br> at the end
|
||||
const info = $('.content > em span');
|
||||
return {
|
||||
title: $('.content > h2').text() || item.title,
|
||||
description,
|
||||
// pubDate: timezone(parseDate(info.eq(0).text()), 8),
|
||||
pubDate: item.pubDate,
|
||||
author: info
|
||||
.eq(1)
|
||||
.text()
|
||||
.replace(/^来源:/, ''),
|
||||
link: item.link,
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ module.exports = async (ctx) => {
|
||||
},
|
||||
});
|
||||
const params = utils.addVerifyInfo(`mid=${uid}&ps=30&tid=0&pn=${pageId}&keyword=&order=pubdate&order_avoided=true`, verifyString);
|
||||
return await got(`https://api.bilibili.com/x/space/wbi/arc/search?${params}`, {
|
||||
return got(`https://api.bilibili.com/x/space/wbi/arc/search?${params}`, {
|
||||
headers: {
|
||||
Referer: `https://space.bilibili.com/${uid}/video?tid=0&page=${pageId}&keyword=&order=pubdate`,
|
||||
Cookie: cookie,
|
||||
|
||||
+17
-18
@@ -27,28 +27,27 @@ module.exports = async (ctx) => {
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got(item.link, {
|
||||
https: {
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
});
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got(item.link, {
|
||||
https: {
|
||||
rejectUnauthorized: false,
|
||||
},
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('.ProceedingsArticleOpenAccessPanel').remove();
|
||||
content('#divNotSignedSection, #rightRail').remove();
|
||||
content('.ProceedingsArticleOpenAccessPanel').remove();
|
||||
content('#divNotSignedSection, #rightRail').remove();
|
||||
|
||||
item.description = content('.panel-body').html();
|
||||
item.title = content('meta[name="dc.Title"]').attr('content');
|
||||
item.author = content('meta[name="dc.Creator"]').attr('content');
|
||||
item.doi = content('meta[name="dc.Identifier"]').attr('content');
|
||||
item.pubDate = parseDate(content('meta[name="dc.Date"]').attr('content'));
|
||||
item.description = content('.panel-body').html();
|
||||
item.title = content('meta[name="dc.Title"]').attr('content');
|
||||
item.author = content('meta[name="dc.Creator"]').attr('content');
|
||||
item.doi = content('meta[name="dc.Identifier"]').attr('content');
|
||||
item.pubDate = parseDate(content('meta[name="dc.Date"]').attr('content'));
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ async function load(link) {
|
||||
return { description, pubDate };
|
||||
}
|
||||
|
||||
const ProcessFeed = async (base, list, caches) =>
|
||||
const ProcessFeed = (base, list, caches) =>
|
||||
// 使用 Promise.all() 进行 async 并发
|
||||
await Promise.all(
|
||||
Promise.all(
|
||||
// 遍历每一篇文章
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
@@ -53,7 +53,7 @@ const ProcessFeed = async (base, list, caches) =>
|
||||
|
||||
// 使用tryGet方法从缓存获取内容。
|
||||
// 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。
|
||||
const other = await caches.tryGet(itemUrl, async () => await load(itemUrl));
|
||||
const other = await caches.tryGet(itemUrl, () => load(itemUrl));
|
||||
|
||||
// 合并解析后的结果集作为该篇文章最终的输出结果
|
||||
return { ...single, ...other };
|
||||
|
||||
@@ -73,8 +73,8 @@ const parseNewsList = async (url, ctx) => {
|
||||
});
|
||||
};
|
||||
|
||||
const parseArticle = async (item, ctx) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const parseArticle = (item, ctx) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const group = regex
|
||||
.map((r) => r.exec(item.link))
|
||||
.filter((e) => e && e.groups)
|
||||
@@ -116,15 +116,15 @@ const parseArticle = async (item, ctx) =>
|
||||
|
||||
switch (page) {
|
||||
case 'audio':
|
||||
return await parseAudioPage(res, api, item);
|
||||
return parseAudioPage(res, api, item);
|
||||
case 'videos':
|
||||
return await parseVideoPage(res, api, item);
|
||||
return parseVideoPage(res, api, item);
|
||||
case 'photo-essays':
|
||||
return await parsePhotoEssaysPage(res, api, item);
|
||||
return parsePhotoEssaysPage(res, api, item);
|
||||
case 'features/': // single features page
|
||||
return await parseFeaturePage(res, api, item);
|
||||
return parseFeaturePage(res, api, item);
|
||||
default:
|
||||
return await parseOtherPage(res, api, item);
|
||||
return parseOtherPage(res, api, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -199,7 +199,7 @@ const parseFeaturePage = async (res, api, item) => {
|
||||
const article_json = JSON.parse(JSON.parse(json));
|
||||
const meta = article_json.meta;
|
||||
|
||||
const desc = article_json.blocks.map(async (b) => {
|
||||
const desc = article_json.blocks.map((b) => {
|
||||
if (b.type === 'Paragraph') {
|
||||
return b.props.text.html;
|
||||
}
|
||||
@@ -208,7 +208,7 @@ const parseFeaturePage = async (res, api, item) => {
|
||||
return art(path.join(__dirname, 'templates/image_figure.art'), image);
|
||||
}
|
||||
if (b.type === 'Lede') {
|
||||
return await processLedeMedia(b);
|
||||
return processLedeMedia(b);
|
||||
}
|
||||
return '';
|
||||
});
|
||||
|
||||
@@ -20,8 +20,8 @@ const getList = async (url) => {
|
||||
return list;
|
||||
};
|
||||
|
||||
const getItems = async (ctx, list) =>
|
||||
await Promise.all(
|
||||
const getItems = (ctx, list) =>
|
||||
Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got(item.link);
|
||||
|
||||
+20
-21
@@ -38,34 +38,33 @@ module.exports = async (ctx) => {
|
||||
}));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const data = detailResponse.data;
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const data = detailResponse.data;
|
||||
|
||||
item.description += `<video src="${data.hls_url}" controls="controls" poster="${item.image}" width="100%"></video><br>`;
|
||||
item.description += `<video src="${data.hls_url}" controls="controls" poster="${item.image}" width="100%"></video><br>`;
|
||||
|
||||
for (const c of data.video.chapters) {
|
||||
for (const c of data.video.chapters) {
|
||||
item.description += `<video src="${c.url}" controls="controls" poster="${c.image}" width="100%"></video><br>`;
|
||||
}
|
||||
|
||||
for (let i = 2; data.video[`chapters${i}`]; i++) {
|
||||
for (const c of data.video[`chapters${i}`]) {
|
||||
item.description += `<video src="${c.url}" controls="controls" poster="${c.image}" width="100%"></video><br>`;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 2; data.video[`chapters${i}`]; i++) {
|
||||
for (const c of data.video[`chapters${i}`]) {
|
||||
item.description += `<video src="${c.url}" controls="controls" poster="${c.image}" width="100%"></video><br>`;
|
||||
}
|
||||
}
|
||||
item.link = item.url;
|
||||
|
||||
item.link = item.url;
|
||||
delete item.url;
|
||||
delete item.image;
|
||||
|
||||
delete item.url;
|
||||
delete item.image;
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ module.exports = async (ctx) => {
|
||||
.map(async (index, item) => {
|
||||
item = $(item);
|
||||
const itemLink = utils.siteLink + item.find('h2 > a').attr('href');
|
||||
const detail = await ctx.cache.tryGet(itemLink, async () => await utils.getArticleDetail(itemLink));
|
||||
const detail = await ctx.cache.tryGet(itemLink, () => utils.getArticleDetail(itemLink));
|
||||
|
||||
return {
|
||||
title: detail.title,
|
||||
|
||||
@@ -17,7 +17,7 @@ module.exports = async (ctx) => {
|
||||
.map(async (index, item) => {
|
||||
item = $(item);
|
||||
const itemLink = utils.siteLink + item.find('li a').attr('href');
|
||||
const detail = await ctx.cache.tryGet(itemLink, async () => await utils.getArticleDetail(itemLink));
|
||||
const detail = await ctx.cache.tryGet(itemLink, () => utils.getArticleDetail(itemLink));
|
||||
|
||||
return {
|
||||
title: detail.title,
|
||||
|
||||
@@ -18,7 +18,7 @@ module.exports = async (ctx) => {
|
||||
articlesLinkList.map(async (item) => {
|
||||
const articlesLink = utils.siteLink + item;
|
||||
|
||||
const detail = await ctx.cache.tryGet(articlesLink, async () => await utils.getArticleDetail(articlesLink));
|
||||
const detail = await ctx.cache.tryGet(articlesLink, () => utils.getArticleDetail(articlesLink));
|
||||
|
||||
const element = {
|
||||
title: detail.title,
|
||||
|
||||
@@ -17,7 +17,7 @@ module.exports = async (ctx) => {
|
||||
articlesLinkList.map(async (item) => {
|
||||
const articlesLink = item;
|
||||
|
||||
const detail = await ctx.cache.tryGet(articlesLink, async () => await utils.getArticleDetail(articlesLink));
|
||||
const detail = await ctx.cache.tryGet(articlesLink, () => utils.getArticleDetail(articlesLink));
|
||||
|
||||
const element = {
|
||||
title: detail.title,
|
||||
|
||||
@@ -28,20 +28,19 @@ module.exports = async (ctx) => {
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got({
|
||||
url: item.link,
|
||||
cookieJar,
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const content = $('#art');
|
||||
item.description = content.html();
|
||||
item.pubDate = item.pubDate.includes('-') ? timezone(parseDate(item.pubDate, 'YYYY-MM-DD'), +8) : parseRelativeDate(item.pubDate);
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got({
|
||||
url: item.link,
|
||||
cookieJar,
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const content = $('#art');
|
||||
item.description = content.html();
|
||||
item.pubDate = item.pubDate.includes('-') ? timezone(parseDate(item.pubDate, 'YYYY-MM-DD'), +8) : parseRelativeDate(item.pubDate);
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+14
-15
@@ -28,25 +28,24 @@ module.exports = async (ctx) => {
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
responseType: 'buffer',
|
||||
});
|
||||
const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk'));
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
responseType: 'buffer',
|
||||
});
|
||||
const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk'));
|
||||
|
||||
item.description = content('#text').html();
|
||||
item.pubDate = timezone(parseDate(content('.t8').eq(0).text(), 'YYYY/M/D H:mm:ss'), +8);
|
||||
item.description = content('#text').html();
|
||||
item.pubDate = timezone(parseDate(content('.t8').eq(0).text(), 'YYYY/M/D H:mm:ss'), +8);
|
||||
|
||||
content('.t14').remove();
|
||||
content('.t14').remove();
|
||||
|
||||
item.author = content('#author').text();
|
||||
item.author = content('#author').text();
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ module.exports = async (ctx) => {
|
||||
await page.goto(`${api}&limit=100`);
|
||||
await page.waitForSelector('body > pre');
|
||||
const response = await page.evaluate(() => document.querySelector('body > pre').innerText);
|
||||
const cookies = await ctx.cache.tryGet('dcard:cookies', async () => await page.cookies(), 3600, false);
|
||||
const cookies = await ctx.cache.tryGet('dcard:cookies', () => page.cookies(), 3600, false);
|
||||
await page.close();
|
||||
|
||||
const data = JSON.parse(response);
|
||||
|
||||
@@ -23,21 +23,20 @@ module.exports = async (ctx) => {
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.author = content('.meta-author').text();
|
||||
item.description = content('.entry-content').html();
|
||||
item.pubDate = parseDate(content('.meta-date').text(), 'MMMM D, YYYY');
|
||||
item.author = content('.meta-author').text();
|
||||
item.description = content('.entry-content').html();
|
||||
item.pubDate = parseDate(content('.meta-date').text(), 'MMMM D, YYYY');
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+11
-12
@@ -28,20 +28,19 @@ module.exports = async (ctx) => {
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.content-3mNFyi').html();
|
||||
item.pubDate = parseDate(detailResponse.data.match(/"date":"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}\+\d{2}:\d{2})","thumbnail_url":/)[1]);
|
||||
item.description = content('.content-3mNFyi').html();
|
||||
item.pubDate = parseDate(detailResponse.data.match(/"date":"(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}\+\d{2}:\d{2})","thumbnail_url":/)[1]);
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+12
-13
@@ -59,21 +59,20 @@ module.exports = async (ctx) => {
|
||||
links.push(item.link.replace(/\.html/, `-${i}.html`));
|
||||
}
|
||||
|
||||
links.forEach(
|
||||
async (link) =>
|
||||
await ctx.cache.tryGet(link, async () => {
|
||||
const pageResponse = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
const subContent = cheerio.load(pageResponse.data);
|
||||
links.forEach((link) =>
|
||||
ctx.cache.tryGet(link, async () => {
|
||||
const pageResponse = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
const subContent = cheerio.load(pageResponse.data);
|
||||
|
||||
subContent('img').each(function () {
|
||||
subContent(this).attr('src', subContent(this).attr('data-url'));
|
||||
});
|
||||
subContent('img').each(function () {
|
||||
subContent(this).attr('src', subContent(this).attr('data-url'));
|
||||
});
|
||||
|
||||
item.description += subContent('#J-contain_detail_cnt').html();
|
||||
})
|
||||
item.description += subContent('#J-contain_detail_cnt').html();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ const parser = require('@/utils/rss-parser');
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const getArticleDetail = async (link, ctx) =>
|
||||
await ctx.cache.tryGet(link, async () => {
|
||||
const getArticleDetail = (link, ctx) =>
|
||||
ctx.cache.tryGet(link, async () => {
|
||||
const response = await got(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
$('div.article-audio-player__center-tooltip').remove();
|
||||
|
||||
@@ -33,10 +33,10 @@ async function load(link) {
|
||||
return { description };
|
||||
}
|
||||
|
||||
const ProcessFeed = async (list, caches) => {
|
||||
const ProcessFeed = (list, caches) => {
|
||||
const host = 'https://www.flyert.com';
|
||||
|
||||
return await Promise.all(
|
||||
return Promise.all(
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
|
||||
@@ -54,7 +54,7 @@ const ProcessFeed = async (list, caches) => {
|
||||
|
||||
// 使用tryGet方法从缓存获取内容。
|
||||
// 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。
|
||||
const other = await caches.tryGet(itemUrl, async () => await load(itemUrl));
|
||||
const other = await caches.tryGet(itemUrl, () => load(itemUrl));
|
||||
|
||||
// 合并解析后的结果集作为该篇文章最终的输出结果
|
||||
return Promise.resolve(Object.assign({}, single, other));
|
||||
|
||||
@@ -18,6 +18,6 @@ module.exports = async (ctx) => {
|
||||
title: `GoCN社区-文章`,
|
||||
link: base_url,
|
||||
description: `获取GoCN站点最新文章`,
|
||||
item: await Promise.all(list.map(async (item) => await ctx.cache.tryGet(`${base_url}/${item.guid}`, () => util.getFeedItem(item)))),
|
||||
item: await Promise.all(list.map((item) => ctx.cache.tryGet(`${base_url}/${item.guid}`, () => util.getFeedItem(item)))),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -28,19 +28,18 @@ module.exports = async (ctx) => {
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('#sites-canvas').html();
|
||||
item.description = content('#sites-canvas').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ const changeTrCookie = async () => {
|
||||
|
||||
const parseArticle = async (item, ctx) => {
|
||||
await changeTrCookie();
|
||||
return await ctx.cache.tryGet(item.link, async () => {
|
||||
return ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got(item.link, { cookieJar });
|
||||
const data = response.data;
|
||||
await parseCookie(data);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const processItems = async (list, ctx) =>
|
||||
await Promise.all(
|
||||
const processItems = (list, ctx) =>
|
||||
Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got.post(item.link);
|
||||
|
||||
@@ -45,8 +45,8 @@ const getInfoUrlList = async (countyName) => {
|
||||
};
|
||||
|
||||
// 获取信息正文内容
|
||||
const getInfoContent = async (ctx, url, countyName) =>
|
||||
await ctx.cache.tryGet(url, async () => {
|
||||
const getInfoContent = (ctx, url, countyName) =>
|
||||
ctx.cache.tryGet(url, async () => {
|
||||
let response;
|
||||
try {
|
||||
response = await got(url);
|
||||
@@ -80,7 +80,7 @@ const getInfoContent = async (ctx, url, countyName) =>
|
||||
module.exports = async (ctx) => {
|
||||
const countyName = ctx.params.countyName;
|
||||
const infoUrlList = await getInfoUrlList(countyName);
|
||||
const items = await Promise.all(infoUrlList.map(async (item) => await getInfoContent(ctx, item, countyName)));
|
||||
const items = await Promise.all(infoUrlList.map((item) => getInfoContent(ctx, item, countyName)));
|
||||
|
||||
ctx.state.data = {
|
||||
title: `政府公开信息 - ${countyName}`,
|
||||
|
||||
@@ -26,8 +26,8 @@ const parseContList = async (url, selector, ctx) => {
|
||||
return { list, title };
|
||||
};
|
||||
|
||||
const parseXilan = async (item, ctx) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const parseXilan = (item, ctx) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got(item.link);
|
||||
const $ = cheerio.load(response.data);
|
||||
const title = $('.xilan_titf').text();
|
||||
|
||||
@@ -4,8 +4,8 @@ const { parseDate } = require('@/utils/parse-date');
|
||||
const { finishArticleItem } = require('./utils');
|
||||
const config = require('@/config').value;
|
||||
|
||||
const getInitEntry = async (url) =>
|
||||
await got(url)
|
||||
const getInitEntry = (url) =>
|
||||
got(url)
|
||||
.then((_r) => _r.data)
|
||||
.catch((err) => {
|
||||
if (err.response.statusCode === 404) {
|
||||
@@ -18,7 +18,7 @@ module.exports = async (ctx, path, id, titleHeader = '', custom_title = null, sk
|
||||
const rootUrl = 'http://web.gzh360.com';
|
||||
const currentUrl = `${rootUrl}/${id ? `${path}?id=${id}` : ''}`;
|
||||
|
||||
const respData = cacheInitEntry ? await ctx.cache.tryGet(currentUrl, async () => await getInitEntry(currentUrl), config.cache.routeExpire, false) : await getInitEntry(currentUrl);
|
||||
const respData = cacheInitEntry ? await ctx.cache.tryGet(currentUrl, () => getInitEntry(currentUrl), config.cache.routeExpire, false) : await getInitEntry(currentUrl);
|
||||
const $ = cheerio.load(respData);
|
||||
|
||||
const title = id ? $('head > title').text().split(' - ', 1)[0] : '首页';
|
||||
|
||||
@@ -36,8 +36,8 @@ const finishArticleItem = async (ctx, item, skipAuthor = false) => {
|
||||
// we can't cache the item instead of the webpage because we need to retry when the last request failed
|
||||
const article = await ctx.cache.tryGet(
|
||||
item.link,
|
||||
async () =>
|
||||
await got(item.link)
|
||||
() =>
|
||||
got(item.link)
|
||||
.then((_r) => _r.data)
|
||||
.catch(() => null) // it is safe do that in tryGet because a false value always lead to a cache miss
|
||||
);
|
||||
|
||||
@@ -9,8 +9,8 @@ const apiRootUrl = 'https://web-data.api.hk01.com';
|
||||
module.exports = {
|
||||
rootUrl,
|
||||
apiRootUrl,
|
||||
ProcessItems: async (items, limit, tryGet) =>
|
||||
await Promise.all(
|
||||
ProcessItems: (items, limit, tryGet) =>
|
||||
Promise.all(
|
||||
items
|
||||
.filter((item) => item.type !== 2)
|
||||
.slice(0, limit ? parseInt(limit) : 50)
|
||||
|
||||
@@ -23,8 +23,8 @@ async function load(link) {
|
||||
return { description, pubDate };
|
||||
}
|
||||
|
||||
const ProcessFeed = async (list, caches) =>
|
||||
await Promise.all(
|
||||
const ProcessFeed = (list, caches) =>
|
||||
Promise.all(
|
||||
// 遍历每一篇文章
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
@@ -43,7 +43,7 @@ const ProcessFeed = async (list, caches) =>
|
||||
|
||||
// 使用tryGet方法从缓存获取内容。
|
||||
// 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。
|
||||
const other = await caches.tryGet(itemUrl, async () => await load(itemUrl));
|
||||
const other = await caches.tryGet(itemUrl, () => load(itemUrl));
|
||||
|
||||
// 合并解析后的结果集作为该篇文章最终的输出结果
|
||||
return { ...single, ...other };
|
||||
|
||||
@@ -23,11 +23,11 @@ async function load(link) {
|
||||
return { description, pubDate };
|
||||
}
|
||||
|
||||
const ProcessFeed = async (list, caches) => {
|
||||
const ProcessFeed = (list, caches) => {
|
||||
const host = 'http://jwc.njnu.edu.cn/';
|
||||
|
||||
// 使用 Promise.all() 进行 async 并发
|
||||
return await Promise.all(
|
||||
return Promise.all(
|
||||
// 遍历每一篇文章
|
||||
list.map(async (item) => {
|
||||
const $ = cheerio.load(item);
|
||||
@@ -46,7 +46,7 @@ const ProcessFeed = async (list, caches) => {
|
||||
|
||||
// 使用tryGet方法从缓存获取内容。
|
||||
// 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。
|
||||
const other = await caches.tryGet(itemUrl, async () => await load(itemUrl));
|
||||
const other = await caches.tryGet(itemUrl, () => load(itemUrl));
|
||||
|
||||
// 合并解析后的结果集作为该篇文章最终的输出结果
|
||||
return { ...single, ...other };
|
||||
|
||||
+2
-2
@@ -45,8 +45,8 @@ async function ProcessList(newsUrl, baseUrl, listName, listDate, webPageName) {
|
||||
return [items, pageName];
|
||||
}
|
||||
|
||||
const ProcessFeed = async (items, artiContent, ctx) =>
|
||||
await Promise.all(
|
||||
const ProcessFeed = (items, artiContent, ctx) =>
|
||||
Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
switch (item.type) {
|
||||
|
||||
+13
-14
@@ -19,24 +19,23 @@ module.exports = async (ctx) => {
|
||||
}));
|
||||
|
||||
items = await Promise.all(
|
||||
items.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data.match(/"content":"(.*)"}},"secondaryList":/)[1]);
|
||||
const content = cheerio.load(detailResponse.data.match(/"content":"(.*)"}},"secondaryList":/)[1]);
|
||||
|
||||
content('img').each(function () {
|
||||
content(this).attr('src', content(this).attr('src').replace(/\\"/g, ''));
|
||||
});
|
||||
content('img').each(function () {
|
||||
content(this).attr('src', content(this).attr('src').replace(/\\"/g, ''));
|
||||
});
|
||||
|
||||
item.description = content.html();
|
||||
item.description = content.html();
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+14
-15
@@ -24,25 +24,24 @@ module.exports = async (ctx) => {
|
||||
}));
|
||||
|
||||
items = await Promise.all(
|
||||
items.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data.match(/"content":"(.*)","extraction_tags":/)[1]);
|
||||
const content = cheerio.load(detailResponse.data.match(/"content":"(.*)","extraction_tags":/)[1]);
|
||||
|
||||
content('img').each(function () {
|
||||
content(this).attr('src', content(this).attr('src').replace(/\\"/g, ''));
|
||||
});
|
||||
content('img').each(function () {
|
||||
content(this).attr('src', content(this).attr('src').replace(/\\"/g, ''));
|
||||
});
|
||||
|
||||
item.description = content.html();
|
||||
item.author = author = detailResponse.data.match(/"name":"(.*)","role_id/)[1];
|
||||
item.description = content.html();
|
||||
item.author = author = detailResponse.data.match(/"name":"(.*)","role_id/)[1];
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+20
-21
@@ -33,29 +33,28 @@ module.exports = async (ctx) => {
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('#content').html();
|
||||
item.pubDate = timezone(
|
||||
parseDate(
|
||||
content('.xq-head')
|
||||
.find('span')
|
||||
.text()
|
||||
.match(/发布时间:\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}/)[0],
|
||||
'YYYY-MM-DD HH:mm'
|
||||
),
|
||||
+8
|
||||
);
|
||||
item.description = content('#content').html();
|
||||
item.pubDate = timezone(
|
||||
parseDate(
|
||||
content('.xq-head')
|
||||
.find('span')
|
||||
.text()
|
||||
.match(/发布时间:\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}/)[0],
|
||||
'YYYY-MM-DD HH:mm'
|
||||
),
|
||||
+8
|
||||
);
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
module.exports = async (link, ctx) => {
|
||||
module.exports = (link, ctx) => {
|
||||
if (link.startsWith('https://xinwen.wh.sdu.edu.cn/')) {
|
||||
return await require('./wh/news')(link, ctx);
|
||||
return require('./wh/news')(link, ctx);
|
||||
}
|
||||
if (link.startsWith('https://www.view.sdu.edu.cn/')) {
|
||||
return await require('./view')(link, ctx);
|
||||
return require('./view')(link, ctx);
|
||||
}
|
||||
if (link.startsWith('https://www.sdrj.sdu.edu.cn/')) {
|
||||
return await require('./sdrj')(link, ctx);
|
||||
return require('./sdrj')(link, ctx);
|
||||
}
|
||||
if (link.startsWith('https://jwc.wh.sdu.edu.cn/')) {
|
||||
return await require('./wh/jwc')(link, ctx);
|
||||
return require('./wh/jwc')(link, ctx);
|
||||
}
|
||||
return {};
|
||||
};
|
||||
|
||||
@@ -3,8 +3,8 @@ const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
module.exports = async (link, ctx) =>
|
||||
await ctx.cache.tryGet(link, async () => {
|
||||
module.exports = (link, ctx) =>
|
||||
ctx.cache.tryGet(link, async () => {
|
||||
let content, author, exactDate;
|
||||
try {
|
||||
const result = await got(link);
|
||||
|
||||
@@ -3,8 +3,8 @@ const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
module.exports = async (link, ctx) =>
|
||||
await ctx.cache.tryGet(link, async () => {
|
||||
module.exports = (link, ctx) =>
|
||||
ctx.cache.tryGet(link, async () => {
|
||||
let content, author, exactDate;
|
||||
try {
|
||||
const result = await got(link);
|
||||
|
||||
@@ -3,8 +3,8 @@ const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
module.exports = async (link, ctx) =>
|
||||
await ctx.cache.tryGet(link, async () => {
|
||||
module.exports = (link, ctx) =>
|
||||
ctx.cache.tryGet(link, async () => {
|
||||
let content, exactDate;
|
||||
try {
|
||||
const result = await got(link);
|
||||
|
||||
@@ -3,8 +3,8 @@ const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
module.exports = async (link, ctx) =>
|
||||
await ctx.cache.tryGet(link, async () => {
|
||||
module.exports = (link, ctx) =>
|
||||
ctx.cache.tryGet(link, async () => {
|
||||
let content, author, exactDate;
|
||||
try {
|
||||
const result = await got(link);
|
||||
|
||||
@@ -21,7 +21,7 @@ module.exports = async (ctx) => {
|
||||
const href = anchor.attr('href');
|
||||
const link = href.startsWith('http') ? href : baseUrl + href;
|
||||
const title = item.text();
|
||||
const { description, author: exactAuthor, exactDate } = await ctx.cache.tryGet(link, async () => await extractor(link, ctx));
|
||||
const { description, author: exactAuthor, exactDate } = await ctx.cache.tryGet(link, () => extractor(link, ctx));
|
||||
const author = exactAuthor ?? '教务处';
|
||||
const pubDate = exactDate ?? timezone(parseDate(dateText.slice(1, dateText.length - 1), 'YYYY-MM-DD'), +8);
|
||||
return {
|
||||
|
||||
@@ -17,7 +17,7 @@ module.exports = async (ctx) => {
|
||||
const title = anchor.attr('title');
|
||||
const href = anchor.attr('href');
|
||||
const link = href.startsWith('http') ? href : baseUrl + href;
|
||||
const { description, author, exactDate } = await ctx.cache.tryGet(link, async () => await extractor(link, ctx));
|
||||
const { description, author, exactDate } = await ctx.cache.tryGet(link, () => extractor(link, ctx));
|
||||
const span = item.find('span');
|
||||
const pubDate = exactDate ?? parseDate(span.text(), 'YYYY/MM/DD');
|
||||
return {
|
||||
|
||||
@@ -3,9 +3,9 @@ const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
async function load_detail(list, cache) {
|
||||
return await Promise.all(
|
||||
list.map(async (item) => {
|
||||
function load_detail(list, cache) {
|
||||
return Promise.all(
|
||||
list.map((item) => {
|
||||
const notice_item = cheerio.load(item);
|
||||
const href = notice_item('a').attr('href');
|
||||
const url = 'http://www.shmeea.edu.cn' + href;
|
||||
@@ -16,7 +16,7 @@ async function load_detail(list, cache) {
|
||||
link: href,
|
||||
};
|
||||
}
|
||||
return await cache.tryGet(url, async () => {
|
||||
return cache.tryGet(url, async () => {
|
||||
const detail_response = await got({
|
||||
method: 'get',
|
||||
url,
|
||||
|
||||
+10
-11
@@ -29,19 +29,18 @@ module.exports = async (ctx) => {
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.v_news_content').html();
|
||||
item.description = content('.v_news_content').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+11
-12
@@ -28,20 +28,19 @@ module.exports = async (ctx) => {
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.v_news_content').html();
|
||||
item.pubDate = timezone(parseDate(detailResponse.data.match(/发布时间: (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/)[1], 'YYYY-MM-DD HH:mm:ss'), +8);
|
||||
item.description = content('.v_news_content').html();
|
||||
item.pubDate = timezone(parseDate(detailResponse.data.match(/发布时间: (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/)[1], 'YYYY-MM-DD HH:mm:ss'), +8);
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@ const defaultRssItem = (item) => ({
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
ProcessItem: async (item, ctx) => {
|
||||
ProcessItem: (item, ctx) => {
|
||||
if (item.link) {
|
||||
// external link
|
||||
return defaultRssItem(item);
|
||||
}
|
||||
const itemUrl = `https://m.thepaper.cn/detail/${item.contId}`;
|
||||
return await ctx.cache.tryGet(itemUrl, async () => {
|
||||
return ctx.cache.tryGet(itemUrl, async () => {
|
||||
const res = await got(itemUrl);
|
||||
const data = JSON.parse(cheerio.load(res.data)('#__NEXT_DATA__').html());
|
||||
const detailData = data.props.pageProps.detailData;
|
||||
|
||||
@@ -199,13 +199,13 @@ const cacheTryGet = async (cache, screenName, params, func) => {
|
||||
const id = await getUserID(cache, screenName);
|
||||
const funcName = func.name;
|
||||
const paramsString = JSON.stringify(params);
|
||||
return await cache.tryGet(`twitter:${id}:${funcName}:${paramsString}`, async () => await func(id, params), config.cache.routeExpire, false);
|
||||
return cache.tryGet(`twitter:${id}:${funcName}:${paramsString}`, () => func(id, params), config.cache.routeExpire, false);
|
||||
};
|
||||
|
||||
const getUserTweets = async (cache, screenName, params = {}) => await cacheTryGet(cache, screenName, params, getUserTweetsByID);
|
||||
const getUserTweetsAndReplies = async (cache, screenName, params = {}) => await cacheTryGet(cache, screenName, params, getUserTweetsAndRepliesByID);
|
||||
const getUserMedia = async (cache, screenName, params = {}) => await cacheTryGet(cache, screenName, params, getUserMediaByID);
|
||||
const getUserLikes = async (cache, screenName, params = {}) => await cacheTryGet(cache, screenName, params, getUserLikesByID);
|
||||
const getUserTweets = (cache, screenName, params = {}) => cacheTryGet(cache, screenName, params, getUserTweetsByID);
|
||||
const getUserTweetsAndReplies = (cache, screenName, params = {}) => cacheTryGet(cache, screenName, params, getUserTweetsAndRepliesByID);
|
||||
const getUserMedia = (cache, screenName, params = {}) => cacheTryGet(cache, screenName, params, getUserMediaByID);
|
||||
const getUserLikes = (cache, screenName, params = {}) => cacheTryGet(cache, screenName, params, getUserLikesByID);
|
||||
|
||||
const getSearch = async (keywords, params = {}) => gatherLegacyFromLegacyApiData(await timelineKeywords(keywords, params), 'sq-I-t-');
|
||||
|
||||
|
||||
+20
-21
@@ -24,29 +24,28 @@ module.exports = async (ctx) => {
|
||||
pages = pages.map((page) => page.data);
|
||||
|
||||
const result = await Promise.all(
|
||||
pages.map(
|
||||
async (page) =>
|
||||
await Promise.all(
|
||||
page.posts.map((post) =>
|
||||
ctx.cache.tryGet(`${rootURL}${post.link}`, async () => {
|
||||
let { data: article } = await got(`${apiURL}/wp-json/blog/v1/data`, {
|
||||
searchParams: {
|
||||
slug: post.link.replace(/\//g, '').replace('blog', ''),
|
||||
},
|
||||
});
|
||||
article = article.article;
|
||||
pages.map((page) =>
|
||||
Promise.all(
|
||||
page.posts.map((post) =>
|
||||
ctx.cache.tryGet(`${rootURL}${post.link}`, async () => {
|
||||
let { data: article } = await got(`${apiURL}/wp-json/blog/v1/data`, {
|
||||
searchParams: {
|
||||
slug: post.link.replace(/\//g, '').replace('blog', ''),
|
||||
},
|
||||
});
|
||||
article = article.article;
|
||||
|
||||
return {
|
||||
link: article.link,
|
||||
title: article.title,
|
||||
description: article.content,
|
||||
pubDate: parseDate(article.created),
|
||||
author: article.author,
|
||||
category: article.categories.map((category) => category.category_name),
|
||||
};
|
||||
})
|
||||
)
|
||||
return {
|
||||
link: article.link,
|
||||
title: article.title,
|
||||
description: article.content,
|
||||
pubDate: parseDate(article.created),
|
||||
author: article.author,
|
||||
category: article.categories.map((category) => category.category_name),
|
||||
};
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+2
-2
@@ -22,11 +22,11 @@ module.exports = async (ctx) => {
|
||||
);
|
||||
|
||||
const items = await Promise.all(
|
||||
feed.items.splice(0, 10).map(async (item) => {
|
||||
feed.items.splice(0, 10).map((item) => {
|
||||
// generally speaking, changing `item.link` of an existing route could potentially break `item.guid`
|
||||
// but since the route has been down for at least 8 months, it's probably safe
|
||||
item.link = item.link.replace(/^http:\/\//, 'https://');
|
||||
return await ctx.cache.tryGet(item.link, async () => {
|
||||
return ctx.cache.tryGet(item.link, async () => {
|
||||
const response = await got.get(item.link, {
|
||||
headers: {
|
||||
'User-Agent': UA,
|
||||
|
||||
@@ -123,7 +123,7 @@ module.exports = async (ctx) => {
|
||||
throw err;
|
||||
}
|
||||
|
||||
await Promise.all(items.map(async (item) => await finishArticleItem(ctx, item, !!categoryPage)));
|
||||
await Promise.all(items.map((item) => finishArticleItem(ctx, item, !!categoryPage)));
|
||||
|
||||
ctx.state.data = {
|
||||
title,
|
||||
|
||||
@@ -24,7 +24,7 @@ module.exports = async (ctx) => {
|
||||
})
|
||||
.get();
|
||||
|
||||
await Promise.all(items.map(async (item) => await finishArticleItem(ctx, item)));
|
||||
await Promise.all(items.map((item) => finishArticleItem(ctx, item)));
|
||||
|
||||
ctx.state.data = {
|
||||
title: `微信公众号 - ${$('span.name').text()}`,
|
||||
|
||||
@@ -18,7 +18,7 @@ module.exports = async (ctx) => {
|
||||
guid: item.id,
|
||||
}));
|
||||
|
||||
items = await Promise.all(items.map(async (item) => await finishArticleItem(ctx, item)));
|
||||
items = await Promise.all(items.map((item) => finishArticleItem(ctx, item)));
|
||||
|
||||
ctx.state.data = {
|
||||
title: response.data.title,
|
||||
|
||||
@@ -12,7 +12,7 @@ module.exports = async (ctx) => {
|
||||
link: item.link,
|
||||
guid: item.link,
|
||||
}));
|
||||
await Promise.all(items.map(async (item) => await finishArticleItem(ctx, item)));
|
||||
await Promise.all(items.map((item) => finishArticleItem(ctx, item)));
|
||||
|
||||
ctx.state.data = {
|
||||
title: feed.title,
|
||||
|
||||
+2
-2
@@ -27,12 +27,12 @@ module.exports = async (ctx) => {
|
||||
// 标题,另外差一个菜单标题!求助
|
||||
const mptitle = $('div.articles_header').find('a').text() + `|` + $('div.articles_header > h2.rich_media_title').text();
|
||||
const articledata = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
list.map((item) => {
|
||||
const single = {
|
||||
link: item.link,
|
||||
guid: item.link,
|
||||
};
|
||||
return await finishArticleItem(ctx, single);
|
||||
return finishArticleItem(ctx, single);
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
|
||||
@@ -15,7 +15,7 @@ module.exports = async (ctx) => {
|
||||
const list = $('li').get();
|
||||
const mptitle = $('.album__author-name').text() + `|` + $('.album__label-title').text();
|
||||
const articledata = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
list.map((item) => {
|
||||
const link = $(item).attr('data-link').replace('http://', 'https://');
|
||||
const title = $(item).attr('data-title');
|
||||
const single = {
|
||||
@@ -23,7 +23,7 @@ module.exports = async (ctx) => {
|
||||
link,
|
||||
guid: link,
|
||||
};
|
||||
return await finishArticleItem(ctx, single);
|
||||
return finishArticleItem(ctx, single);
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ module.exports = async (ctx) => {
|
||||
|
||||
// 对于列表的每一项, 单独获取 时间与详细内容
|
||||
// eslint-disable-next-line no-return-await
|
||||
const other = await ctx.cache.tryGet($item_url, async () => await load($item_url));
|
||||
const other = await ctx.cache.tryGet($item_url, () => load($item_url));
|
||||
// 合并解析后的结果集作为该篇文章最终的输出结果
|
||||
return { ...single, ...other };
|
||||
})
|
||||
|
||||
+17
-18
@@ -43,28 +43,27 @@ module.exports = async (ctx) => {
|
||||
}
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const matches = detailResponse.data.match(/"headline":"(.*)","description":"(.*)","datePublished":"(.*)","image"/);
|
||||
const matches = detailResponse.data.match(/"headline":"(.*)","description":"(.*)","datePublished":"(.*)","image"/);
|
||||
|
||||
if (matches) {
|
||||
item.title = matches[1];
|
||||
item.description = matches[2];
|
||||
item.pubDate = parseDate(matches[3]);
|
||||
} else {
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
if (matches) {
|
||||
item.title = matches[1];
|
||||
item.description = matches[2];
|
||||
item.pubDate = parseDate(matches[3]);
|
||||
} else {
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.sf-content-block').html();
|
||||
}
|
||||
item.description = content('.sf-content-block').html();
|
||||
}
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+9
-10
@@ -20,18 +20,17 @@ module.exports = async (ctx) => {
|
||||
}));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
item.description = detailResponse.data.match(/"description":"(.*)","datePublished"/)[1];
|
||||
item.description = detailResponse.data.match(/"description":"(.*)","datePublished"/)[1];
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+10
-11
@@ -33,19 +33,18 @@ module.exports = async (ctx) => {
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.wb100').html();
|
||||
item.description = content('.wb100').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
+20
-21
@@ -29,31 +29,30 @@ module.exports = async (ctx) => {
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
if (item.link.indexOf('wyzxwk.com') > 0) {
|
||||
try {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
if (item.link.indexOf('wyzxwk.com') > 0) {
|
||||
try {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('.zs-modal-body').prev().nextAll().remove();
|
||||
content('.zs-modal-body').prev().nextAll().remove();
|
||||
|
||||
const pubDate = detailResponse.data.match(/<span class="s-grey-3">(\d{4}-\d{2}-\d{2})<\/span>/);
|
||||
if (pubDate) {
|
||||
item.pubDate = parseDate(pubDate[1], 'YYYY-MM-DD');
|
||||
}
|
||||
|
||||
item.description = content('article').html();
|
||||
} catch (e) {
|
||||
item.description = '';
|
||||
const pubDate = detailResponse.data.match(/<span class="s-grey-3">(\d{4}-\d{2}-\d{2})<\/span>/);
|
||||
if (pubDate) {
|
||||
item.pubDate = parseDate(pubDate[1], 'YYYY-MM-DD');
|
||||
}
|
||||
|
||||
item.description = content('article').html();
|
||||
} catch (e) {
|
||||
item.description = '';
|
||||
}
|
||||
return item;
|
||||
})
|
||||
}
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ module.exports = {
|
||||
}),
|
||||
}));
|
||||
|
||||
return await Promise.all(
|
||||
return Promise.all(
|
||||
items.map((item) =>
|
||||
tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
|
||||
@@ -200,13 +200,13 @@ const testAntiHotlink = async (path, expectObj, query) => {
|
||||
return parsed;
|
||||
};
|
||||
|
||||
const expectImgOrigin = async (query) => await testAntiHotlink('/test/complicated', expects.complicated.origin, query);
|
||||
const expectImgProcessed = async (query) => await testAntiHotlink('/test/complicated', expects.complicated.processed, query);
|
||||
const expectImgUrlencoded = async (query) => await testAntiHotlink('/test/complicated', expects.complicated.urlencoded, query);
|
||||
const expectMultimediaOrigin = async (query) => await testAntiHotlink('/test/multimedia', expects.multimedia.origin, query);
|
||||
const expectMultimediaRelayed = async (query) => await testAntiHotlink('/test/multimedia', expects.multimedia.relayed, query);
|
||||
const expectMultimediaPartlyRelayed = async (query) => await testAntiHotlink('/test/multimedia', expects.multimedia.partlyRelayed, query);
|
||||
const expectMultimediaWrappedInIframe = async (query) => await testAntiHotlink('/test/multimedia', expects.multimedia.wrappedInIframe, query);
|
||||
const expectImgOrigin = (query) => testAntiHotlink('/test/complicated', expects.complicated.origin, query);
|
||||
const expectImgProcessed = (query) => testAntiHotlink('/test/complicated', expects.complicated.processed, query);
|
||||
const expectImgUrlencoded = (query) => testAntiHotlink('/test/complicated', expects.complicated.urlencoded, query);
|
||||
const expectMultimediaOrigin = (query) => testAntiHotlink('/test/multimedia', expects.multimedia.origin, query);
|
||||
const expectMultimediaRelayed = (query) => testAntiHotlink('/test/multimedia', expects.multimedia.relayed, query);
|
||||
const expectMultimediaPartlyRelayed = (query) => testAntiHotlink('/test/multimedia', expects.multimedia.partlyRelayed, query);
|
||||
const expectMultimediaWrappedInIframe = (query) => testAntiHotlink('/test/multimedia', expects.multimedia.wrappedInIframe, query);
|
||||
|
||||
describe('anti-hotlink', () => {
|
||||
it('template-legacy', async () => {
|
||||
|
||||
Reference in New Issue
Block a user