* style: add eslint-unicorn * style: fix unicorn/no-useless-spread * style: fix unicorn/no-useless-promise-resolve-reject * style: fix unicorn/no-for-loop * fix: codeql bad HTML filtering regexp * fix: codeql incomplete replace * fix: unicorn/no-abusive-eslint-disable * style: fix unicorn/no-new-array * style: fix unicorn/no-typeof-undefined * style: fix unicorn/no-zero-fractions * style: fix unicorn/no-empty-file * style: fix unicorn/prefer-date-now * revert: auto fix unicorn/prefer-switch on lib/v2/kuaidi100/utils.js * style: fix unicorn/prefer-array-find * style: fix unicorn/prefer-array-flat * style: fix unicorn/prefer-array-flat-map * style: fix unicorn/prefer-at * style: fix unicorn/prefer-string-starts-ends-with * style: fix unicorn/prefer-includes * fix: codeql URL substring sanitization * style: fix unicorn/prefer-optional-catch-binding * style: fix unicorn/catch-error-name * style: fix unicorn/escape-case * style: fix unicorn/prefer-native-coercion-functions * style: fix unicorn/prefer-regexp-test * style: fix unicorn/require-array-join-separator * style: fix unicorn/prefer-math-trunc * style: fix unicorn/prefer-negative-index * style: fix unicorn/prefer-dom-node-dataset * style: fix unicorn/prefer-dom-node-text-content * style: fix unicorn/prefer-query-selector * style: fix unicorn/no-array-for-each * style: fix unicorn/no-negated-condition * style: fix unicorn/prefer-add-event-listener * style: fix unicorn/import-style * style: fix prefer-regex-literals * style: disable unicorn/no-useless-switch-case * style: disable unicorn/text-encoding-identifier-case * style: fix unicorn/prefer-set-has * style: fix unicorn/prefer-spread * revert: auto fix on lib/routes/universities/ynnu/edu/base64.js * style: fix unicorn/no-useless-undefined * style: fix unicorn/no-array-push-push * style: fix unicorn/no-useless-undefined again * style: fix unicorn/no-lonely-if * style: fix unicorn/prefer-reflect-apply * style: fix unicorn/switch-case-braces * style: fix unicorn/prefer-switch * style: fix unicorn/prefer-array-some * fix: deepscan UNUSED_VAR_ASSIGN * style: fix unicorn/prefer-ternary * fix: follow-up of unicorn/prefer-ternary * revert: auto fix of unicorn/prefer-string-slice for substring() * style: disable unicorn/prefer-string-slice fix: auto fix slice over deprecated substr * style: fix unicorn/throw-new-error * style: fix unicorn/filename-case * test: fix dateParser renaming * style: fix unicorn/better-regex * style: fix unicorn/prefer-string-replace-all * fix(deps): add sanitize-html * style: fix no-prototype-builtins * style: fix unicorn/consistent-destructuring * style: fix unicorn/consistent-function-scoping * style: fix unicorn/prefer-regexp-test * style: fix unicorn/prefer-logical-operator-over-ternary * style: fix unicorn/no-array-callback-reference * style: add prefer-object-has-own * style: warn unicorn/no-empty-file * style: fix unicorn/prefer-number-properties * style: fix no-useless-undefined again * style: fix unicorn/numeric-separators-style * style: disable unicorn/no-array-callback-reference false postive with cheerio
159 lines
6.2 KiB
JavaScript
159 lines
6.2 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
const { parseDate } = require('@/utils/parse-date');
|
|
|
|
module.exports = async (ctx) => {
|
|
const id = ctx.params.id;
|
|
|
|
const response = await got({
|
|
method: 'get',
|
|
url: `https://m.okjike.com/users/${id}`,
|
|
headers: {
|
|
Referer: `https://m.okjike.com/users/${id}`,
|
|
},
|
|
});
|
|
|
|
const html = response.data;
|
|
const $ = cheerio.load(html);
|
|
const raw = $('[type = "application/json"]').html();
|
|
const data = JSON.parse(raw).props.pageProps;
|
|
|
|
const getLink = (id, type) => {
|
|
switch (type) {
|
|
case 'REPOST':
|
|
return `https://m.okjike.com/reposts/${id}`;
|
|
case 'MEDIUM':
|
|
return `https://www.okjike.com/medium/${id}`;
|
|
default:
|
|
return `https://m.okjike.com/originalPosts/${id}`;
|
|
}
|
|
};
|
|
|
|
const items = await Promise.all(
|
|
data.posts.map(async (item) => {
|
|
const typeMap = {
|
|
ORIGINAL_POST: '发布',
|
|
REPOST: '转发',
|
|
ANSWER: '回答',
|
|
QUESTION: '提问',
|
|
PERSONAL_UPDATE: '创建新主题',
|
|
};
|
|
|
|
let linkTemplate = '';
|
|
if (item.linkInfo && item.linkInfo.linkUrl) {
|
|
linkTemplate = `<a href="${item.linkInfo.linkUrl}">${item.linkInfo.title}</a><br>`;
|
|
}
|
|
|
|
let imgTemplate = '';
|
|
if (item.pictures) {
|
|
for (const picture of item.pictures) {
|
|
imgTemplate += `<br><img src="${picture.picUrl}">`;
|
|
}
|
|
}
|
|
|
|
let content = item.content || (item.linkInfo && item.linkInfo.title) || (item.question && item.question.title) || item.title || '';
|
|
content = content.replaceAll(/\r\n|\n|\r/g, '<br>');
|
|
|
|
let shortenTitle = '一条动态';
|
|
if (content) {
|
|
shortenTitle = content.replaceAll(/(<br>)+/g, ' ');
|
|
content = `${content}<br><br>`;
|
|
}
|
|
|
|
let repostContent;
|
|
if (item.type === 'REPOST') {
|
|
const screenNameTemplate = item.target.user ? `<a href="https://m.okjike.com/users/${item.target.user.username}" target="_blank">@${item.target.user.screenName}</a>` : '';
|
|
|
|
let repostImgTemplate = '';
|
|
if (item.target.pictures) {
|
|
for (const picture of item.target.pictures) {
|
|
repostImgTemplate += `<br><img src="${picture.thumbnailUrl}">`;
|
|
}
|
|
}
|
|
|
|
repostContent = `<div class="rsshub-quote">转发 ${screenNameTemplate}: ${item.target.content}${repostImgTemplate}</div>`.replaceAll(/\r\n|\n|\r/g, '<br>');
|
|
content = `${content}${repostContent}`;
|
|
}
|
|
// 部分功能未知
|
|
/* else if (item.type === 'ANSWER') {
|
|
let answerTextTemplate = '';
|
|
let answerImgTemplate = '';
|
|
let answerImgKeys = [];
|
|
item.richtextContent.blocks &&
|
|
item.richtextContent.blocks.forEach((item) => {
|
|
if (item.entityRanges.length && item.text === '[图片]') {
|
|
answerImgKeys = [...answerImgKeys, ...Object.keys(item.entityRanges)];
|
|
} else {
|
|
answerTextTemplate += item.text;
|
|
}
|
|
});
|
|
|
|
if (answerImgKeys.length) {
|
|
answerImgKeys.forEach((key) => {
|
|
const entity = item.richtextContent.entityMap[key];
|
|
if (entity.type.toUpperCase() === 'IMAGE') {
|
|
answerImgTemplate += `<br><img src="${entity.data.pictureUrl.middlePicUrl}">`;
|
|
}
|
|
});
|
|
}
|
|
const answerContent = `回答: ${answerTextTemplate}${answerImgTemplate}`;
|
|
content = `${content}${answerContent}`.replace(/\n|\r/g, '<br>');
|
|
} else if (item.type === 'QUESTION') {
|
|
content = `在主题 <a href="https://web.okjike.com/topic/${item.topic.id}/official" target="_blank">${item.topic.content}</a> 提出了一个问题:<br><br>${content}`;
|
|
} else if (item.type === 'PERSONAL_UPDATE') {
|
|
shortenTitle = item.topic.content;
|
|
content = `<img src="${item.topic.squarePicture.picUrl}"> 主题简介:<br>${item.topic.briefIntro.replace(/(?:\r\n|\r|\n)/g, '<br>')}`;
|
|
}*/
|
|
|
|
const single = {
|
|
title: `${typeMap[item.type]}了: ${shortenTitle}`,
|
|
description: `${content}${linkTemplate}${imgTemplate}`.replace(/(<br>|\s)+$/, ''),
|
|
pubDate: parseDate(item.createdAt),
|
|
link: getLink(item.id, item.type),
|
|
_extra: repostContent && {
|
|
links: [
|
|
{
|
|
url: getLink(item.target.id, item.target.type),
|
|
type: 'quote',
|
|
},
|
|
],
|
|
},
|
|
};
|
|
|
|
if (id === 'wenhao1996' && item.topic.id === '553870e8e4b0cafb0a1bef68') {
|
|
single.link = item.urlsInText[0].url;
|
|
|
|
const { data } = await got({
|
|
method: 'get',
|
|
url: single.link,
|
|
headers: {
|
|
Referer: `https://m.okjike.com/users/${id}`,
|
|
},
|
|
});
|
|
const $$ = cheerio.load(data);
|
|
$$('span.num,span.arrow').remove();
|
|
|
|
single.title = `一觉醒来世界发生了什么 ${$$('title').text()}`;
|
|
|
|
single.description = '';
|
|
$$('div.container')
|
|
.find('li.item')
|
|
// eslint-disable-next-line array-callback-return
|
|
.map((i, j) => {
|
|
single.description += `<a href="${$$(j).find('a').attr('href')}">${$$(j).find('a').text()}</a><br>`;
|
|
});
|
|
}
|
|
|
|
return single;
|
|
})
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: `${data.user.screenName}的即刻动态`,
|
|
description: data.user.bio,
|
|
link: `https://m.okjike.com/users/${id}`,
|
|
image: data.user.avatarImage.picUrl,
|
|
item: items,
|
|
};
|
|
};
|