mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix: 修复 语雀知识库link 404报错 (#2230)
This commit is contained in:
+10
-8
@@ -1,20 +1,21 @@
|
||||
const axios = require('@/utils/axios');
|
||||
const config = require('@/config');
|
||||
// token通过process.env.YUQUE_TOKEN或者在config.js 配置
|
||||
const { token = '' } = config.yuque;
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { repo_id } = ctx.params;
|
||||
const baseUrl = 'https://www.yuque.com';
|
||||
const repoUrl = `${baseUrl}/api/v2/repos/${repo_id}`;
|
||||
const docsUrl = `${repoUrl}/docs`;
|
||||
const headers = {};
|
||||
if (config.yuque.token) {
|
||||
headers['X-Auth-Token'] = config.yuque.token;
|
||||
}
|
||||
|
||||
const fetchData = (url) =>
|
||||
axios({
|
||||
url,
|
||||
method: 'get',
|
||||
headers,
|
||||
headers: {
|
||||
'X-Auth-Token': token,
|
||||
},
|
||||
});
|
||||
|
||||
const repoDetail = await fetchData(repoUrl);
|
||||
@@ -22,6 +23,7 @@ module.exports = async (ctx) => {
|
||||
name: repo,
|
||||
user: { name },
|
||||
description,
|
||||
namespace,
|
||||
} = repoDetail.data.data;
|
||||
const docsDetail = await fetchData(docsUrl);
|
||||
const docs = docsDetail.data.data;
|
||||
@@ -37,15 +39,15 @@ module.exports = async (ctx) => {
|
||||
const item = {
|
||||
title: doc.title,
|
||||
description: doc.description,
|
||||
pubDate: doc.created_at,
|
||||
link: `${baseUrl}/${repo_id}/${doc.id}`,
|
||||
pubDate: doc.published_at,
|
||||
link: `${baseUrl}/${namespace}/${doc.id}`,
|
||||
};
|
||||
const key = `yuque${doc.id}`;
|
||||
const value = await ctx.cache.get(key);
|
||||
|
||||
if (value) {
|
||||
item.description = value;
|
||||
} else {
|
||||
} else if (token) {
|
||||
const docDetail = await fetchData(`${docsUrl}/${doc.id}`);
|
||||
const { body_html } = docDetail.data.data;
|
||||
item.description = body_html;
|
||||
|
||||
Reference in New Issue
Block a user