Hotfix: infzm (#1341)

Closes #1339
This commit is contained in:
凉凉
2019-01-08 19:31:44 +08:00
committed by DIYgod
parent 57910eef17
commit 189a1dcd97
+17 -2
View File
@@ -29,7 +29,7 @@ module.exports = async (ctx) => {
const date = new Date(`${info.slice(-2)[0]}T${info.slice(-1)[0]}`);
const link = item.find('a').attr('href');
const id = link.match(/content\/(\d+)/)[1];
let description;
let description = '';
if (id) {
const key = `infzm: ${link}`;
@@ -43,7 +43,22 @@ module.exports = async (ctx) => {
url: `http://api.infzm.com/mobile/contents/${id}`,
});
description = response.data.data.content.fulltext;
if (response.data.code === 200) {
description = response.data.data.content.fulltext;
} else {
// 有时候接口会返回未发布但实际已发布
const response = await axios({
method: 'get',
url: `http://www.infzm.com/content/${id}`,
headers: {
Referer: url,
Cookie: `PHPSESSID=${Math.floor(Math.random() * 100)};`,
},
});
const $ = cheerio.load(response.data);
description = $('#content').html();
}
ctx.cache.set(key, description, 24 * 60 * 60);
}
} else {