* 修复/zhihu/question,需要设置非登录状态下cookie * Update lib/routes/zhihu/execlib/g_encrypt.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * 根据TonyRL review建议进行了修改 * Update lib/routes/zhihu/question.js Co-authored-by: Rongrong <Rongronggg9@outlook.com> * Update lib/routes/zhihu/question.js Co-authored-by: Rongrong <Rongronggg9@outlook.com> * Update lib/routes/zhihu/question.js Co-authored-by: Rongrong <Rongronggg9@outlook.com> * Update lib/routes/zhihu/question.js Co-authored-by: Rongrong <Rongronggg9@outlook.com> * Update lib/routes/zhihu/question.js Co-authored-by: Rongrong <Rongronggg9@outlook.com> * Update lib/routes/zhihu/question.js Co-authored-by: Rongrong <Rongronggg9@outlook.com> * 增加cookie中dc_0字段检验 * Update lib/routes/zhihu/question.js Co-authored-by: Rongrong <Rongronggg9@outlook.com> * Update lib/routes/zhihu/question.js Co-authored-by: Rongrong <Rongronggg9@outlook.com> * refactor: migrate to v2 * fix: Incomplete URL substring sanitization Co-authored-by: Rongrong <Rongronggg9@outlook.com>
50 lines
1.9 KiB
JavaScript
50 lines
1.9 KiB
JavaScript
const got = require('@/utils/got');
|
|
const utils = require('./utils');
|
|
|
|
// 参考:https://github.com/izzyleung/ZhihuDailyPurify/wiki/%E7%9F%A5%E4%B9%8E%E6%97%A5%E6%8A%A5-API-%E5%88%86%E6%9E%90
|
|
// 文章给出了v7版 api的信息,包含全文api
|
|
|
|
module.exports = async (ctx) => {
|
|
const { sectionId } = ctx.params;
|
|
const listRes = await got({
|
|
method: 'get',
|
|
url: `https://news-at.zhihu.com/api/7/section/${sectionId}`,
|
|
headers: {
|
|
...utils.header,
|
|
Referer: `https://news-at.zhihu.com/api/7/section/${sectionId}`,
|
|
},
|
|
});
|
|
// 根据api的说明,过滤掉极个别站外链接
|
|
const storyList = listRes.data.stories.filter((el) => el.url.startsWith('https://daily.zhihu.com/'));
|
|
const resultItem = await Promise.all(
|
|
storyList.map((story) => {
|
|
const url = 'https://news-at.zhihu.com/api/7/news/' + story.id;
|
|
const item = {
|
|
title: story.title,
|
|
description: '',
|
|
link: 'https://daily.zhihu.com/story/' + story.id,
|
|
};
|
|
return ctx.cache.tryGet(`https://daily.zhihu.com/story/${story.id}`, async () => {
|
|
const storyDetail = await got({
|
|
method: 'get',
|
|
url,
|
|
headers: {
|
|
Referer: url,
|
|
},
|
|
});
|
|
item.description = utils.ProcessImage(storyDetail.data.body.replace(/<div class="meta">([\s\S]*?)<\/div>/g, '<strong>$1</strong>').replace(/<\/?h2.*?>/g, ''));
|
|
|
|
return item;
|
|
});
|
|
})
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: `${listRes.data.name} - 知乎日报`,
|
|
link: 'https://daily.zhihu.com',
|
|
description: '每天3次,每次7分钟',
|
|
image: 'http://static.daily.zhihu.com/img/new_home_v3/mobile_top_logo.png',
|
|
item: resultItem,
|
|
};
|
|
};
|