fix(route): zhihu daily (#11060)

This commit is contained in:
zpcc
2022-10-11 19:32:28 +08:00
committed by GitHub
parent cf1c3025c9
commit a8d9bf6842
+25
View File
@@ -5,15 +5,38 @@ const { parseDate } = require('@/utils/parse-date');
// 参考: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
// 文章给出了v4版 api的信息,包含全文api
async function dohResolve(name) {
const response = await got('https://223.5.5.5/resolve', {
searchParams: {
name,
type: 'A',
edns_client_subnet: '223.5.5.5', // 使用国内的ip地址
},
headers: {
accept: 'application/dns-json',
},
});
return response.data.Answer.map((item) => item.data);
}
module.exports = async (ctx) => {
const api = 'https://news-at.zhihu.com/api/4/news';
const HOST = 'news-at.zhihu.com';
let address = HOST;
try {
await got(`${api}/latest`);
} catch (e) {
address = (await dohResolve(HOST)).pop(); // 国外ip证书配置有误,解析到国内地址
}
const listRes = await got({
method: 'get',
url: `${api}/latest`,
headers: {
...utils.header,
Referer: `${api}/latest`,
Host: HOST,
},
host: address,
});
// 根据api的说明,过滤掉极个别站外链接
const storyList = listRes.data.stories.filter((el) => el.type === 0);
@@ -36,7 +59,9 @@ module.exports = async (ctx) => {
url,
headers: {
Referer: url,
Host: HOST,
},
host: address,
});
return utils.ProcessImage(storyDetail.data.body.replace(/<div class="meta">([\s\S]*?)<\/div>/g, '<strong>$1</strong>').replace(/<\/?h2.*?>/g, ''));
});