fix: no yuque config error, close #2197

This commit is contained in:
DIYgod 2019-05-22 12:02:08 +08:00
parent 8f4a4b9b07
commit 1da8fb6639
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
1 changed files with 6 additions and 6 deletions

View File

@ -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;