add dcard posts

This commit is contained in:
DIYgod
2019-02-28 12:14:12 +08:00
parent 2551a5fa78
commit 6057c18963
4 changed files with 65 additions and 0 deletions

34
lib/routes/dcard/utils.js Normal file
View File

@@ -0,0 +1,34 @@
const axios = require('../../utils/axios');
module.exports = {
ProcessFeed: async (list, cache) => {
const result = await Promise.all(
list.map(async (item) => {
const link = `https://www.dcard.tw/f/funny/p/${item.id}-${encodeURIComponent(item.title)}`;
const content = await cache.tryGet(`dcard${item.id}`, async () => {
const response = await axios({
method: 'get',
url: `https://www.dcard.tw/_api/posts/${item.id}`,
headers: {
Referer: link,
},
});
return response.data.content.replace(/(https?:\/\/i\.imgur\.com\/(.*?)\.(jpg|png))/g, (match, p1) => `<img src="${p1}">`).replace(/(\r\n|\r|\n)+/g, '<br>');
});
const single = {
title: item.title,
link: link,
description: content,
author: item.school || '匿名',
guid: item.id,
};
return Promise.resolve(single);
})
);
return result;
},
};