Merge commit 'c859291ca3812d99e4b84201733e0447f4f33f26'

This commit is contained in:
DIYgod
2019-09-04 18:24:36 +08:00
4 changed files with 47 additions and 32 deletions

View File

@@ -19,16 +19,21 @@ module.exports = async (ctx, next) => {
const tasks = ctx.state.data.item.map(async (item) => { const tasks = ctx.state.data.item.map(async (item) => {
const { link, author, description } = item; const { link, author, description } = item;
const parsed_result = await ctx.cache.tryGet(`mercury-cache-${link}`, async () => { const parsed_result = await ctx.cache.tryGet(`mercury-cache-${link}`, async () => {
const res = await got(link); // if parser failed, return default description and not report error
const $ = cheerio.load(res.data); try {
const result = await mercury_parser.parse(link, { const res = await got(link);
html: $.html(), const $ = cheerio.load(res.data);
}); const result = await mercury_parser.parse(link, {
return result; html: $.html(),
});
return result;
} catch (e) {
// no-empty
}
}); });
item.author = author || parsed_result.author; item.author = author || (parsed_result ? parsed_result.author : '');
item.description = parsed_result.content || description; item.description = parsed_result ? parsed_result.content : description;
}); });
await Promise.all(tasks); await Promise.all(tasks);
} }

View File

@@ -12,11 +12,18 @@ function getContentByActivity(status) {
}); });
break; break;
case '转发': case '转发':
description = getContentByActivity(status.reshared_status).title; description = `${status.text}<br>`;
title = `${status.author.name} ${status.activity} ${status.reshared_status.author.name} 的广播:${status.reshared_status.text}`; if (status.reshared_status.deleted) {
status.reshared_status.images.forEach((image) => { title = `${status.author.name} ${status.activity} 广播:原动态已被发布者删除`;
description += `<p><img src="${image.normal.url}"/></p>`; description += `原动态已被发布者删除`;
}); } else {
description += getContentByActivity(status.reshared_status).title;
title = `${status.author.name} ${status.activity} ${status.reshared_status.author.name} 的广播:${status.reshared_status.text}`;
status.reshared_status.images.forEach((image) => {
description += `<p><img src="${image.normal.url}"/></p>`;
});
}
break; break;
default: default:
if (status.card) { if (status.card) {
@@ -44,19 +51,22 @@ module.exports = async (ctx) => {
Referer: `https://m.douban.com/people/${userid}/statuses`, Referer: `https://m.douban.com/people/${userid}/statuses`,
}, },
}); });
const items = response.data.items; const items = response.data.items;
ctx.state.data = { ctx.state.data = {
title: `豆瓣广播-${userid}`, title: `豆瓣广播-${userid}`,
link: `https://m.douban.com/people/${userid}/statuses`, link: `https://m.douban.com/people/${userid}/statuses`,
item: items.map((item) => { item: items
const r = getContentByActivity(item.status); .filter((item) => !item.deleted)
return { .map((item) => {
title: r.title, const r = getContentByActivity(item.status);
link: item.status.sharing_url, return {
pubDate: item.status.create_time, title: r.title,
description: r.description, link: item.status.sharing_url,
}; pubDate: item.status.create_time,
}), description: r.description,
};
}),
}; };
}; };

View File

@@ -36,12 +36,12 @@
"@vuepress/plugin-pwa": "1.0.3", "@vuepress/plugin-pwa": "1.0.3",
"cross-env": "5.2.1", "cross-env": "5.2.1",
"eslint": "6.3.0", "eslint": "6.3.0",
"eslint-config-prettier": "6.1.0", "eslint-config-prettier": "6.2.0",
"eslint-plugin-prettier": "3.1.0", "eslint-plugin-prettier": "3.1.0",
"jest": "24.9.0", "jest": "24.9.0",
"mockdate": "2.0.5", "mockdate": "2.0.5",
"nock": "11.3.2", "nock": "11.3.2",
"nodemon": "1.19.1", "nodemon": "1.19.2",
"pinyin": "2.9.0", "pinyin": "2.9.0",
"prettier": "1.18.2", "prettier": "1.18.2",
"prettier-check": "2.0.0", "prettier-check": "2.0.0",

View File

@@ -3896,10 +3896,10 @@ escodegen@^1.8.1, escodegen@^1.9.1:
optionalDependencies: optionalDependencies:
source-map "~0.6.1" source-map "~0.6.1"
eslint-config-prettier@6.1.0: eslint-config-prettier@6.2.0:
version "6.1.0" version "6.2.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.1.0.tgz#e6f678ba367fbd1273998d5510f76f004e9dce7b" resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.2.0.tgz#80e0b8714e3f6868c4ac2a25fbf39c02e73527a7"
integrity sha512-k9fny9sPjIBQ2ftFTesJV21Rg4R/7a7t7LCtZVrYQiHEp8Nnuk3EGaDmsKSAnsPj0BYcgB2zxzHa2NTkIxcOLg== integrity sha512-VLsgK/D+S/FEsda7Um1+N8FThec6LqE3vhcMyp8mlmto97y3fGf3DX7byJexGuOb1QY0Z/zz222U5t+xSfcZDQ==
dependencies: dependencies:
get-stdin "^6.0.0" get-stdin "^6.0.0"
@@ -7458,10 +7458,10 @@ nodemailer@6.1.1:
resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.1.1.tgz#09e88ef4b3646f01089c5d84d007b872141fb575" resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-6.1.1.tgz#09e88ef4b3646f01089c5d84d007b872141fb575"
integrity sha1-CeiO9LNkbwEInF2E0Ae4chQftXU= integrity sha1-CeiO9LNkbwEInF2E0Ae4chQftXU=
nodemon@1.19.1: nodemon@1.19.2:
version "1.19.1" version "1.19.2"
resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-1.19.1.tgz#576f0aad0f863aabf8c48517f6192ff987cd5071" resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-1.19.2.tgz#b0975147dc99b3761ceb595b3f9277084931dcc0"
integrity sha512-/DXLzd/GhiaDXXbGId5BzxP1GlsqtMGM9zTmkWrgXtSqjKmGSbLicM/oAy4FR0YWm14jCHRwnR31AHS2dYFHrg== integrity sha512-hRLYaw5Ihyw9zK7NF+9EUzVyS6Cvgc14yh8CAYr38tPxJa6UrOxwAQ351GwrgoanHCF0FalQFn6w5eoX/LGdJw==
dependencies: dependencies:
chokidar "^2.1.5" chokidar "^2.1.5"
debug "^3.1.0" debug "^3.1.0"