fix: no yuque config error, close #2197
This commit is contained in:
parent
8f4a4b9b07
commit
1da8fb6639
|
|
@ -1,20 +1,20 @@
|
|||
const axios = require('@/utils/axios');
|
||||
const config = require('@/config');
|
||||
// token通过process.env.YUQUE_TOKEN或者在config.js 配置
|
||||
const token = config.yuque.token;
|
||||
|
||||
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: {
|
||||
'X-Auth-Token': token,
|
||||
},
|
||||
headers,
|
||||
});
|
||||
|
||||
const repoDetail = await fetchData(repoUrl);
|
||||
|
|
@ -45,7 +45,7 @@ module.exports = async (ctx) => {
|
|||
|
||||
if (value) {
|
||||
item.description = value;
|
||||
} else if (token) {
|
||||
} else {
|
||||
const docDetail = await fetchData(`${docsUrl}/${doc.id}`);
|
||||
const { body_html } = docDetail.data.data;
|
||||
item.description = body_html;
|
||||
|
|
|
|||
Loading…
Reference in New Issue