diff --git a/docs/social-media.md b/docs/social-media.md index 9ca1b317b4..ae4836eb98 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -494,6 +494,8 @@ pageClass: routes + + ## 好奇心日报 ### 分类 diff --git a/lib/router.js b/lib/router.js index f6c61d35b8..e3369f23c7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1210,6 +1210,7 @@ router.get('/bupt/yz/:type', require('./routes/universities/bupt/yz')); // VOCUS 方格子 router.get('/vocus/publication/:id', require('./routes/vocus/publication')); +router.get('/vocus/user/:id', require('./routes/vocus/user')); // 一亩三分地 1point3acres router.get('/1point3acres/user/:id/threads', require('./routes/1point3acres/threads')); diff --git a/lib/routes/vocus/user.js b/lib/routes/vocus/user.js new file mode 100644 index 0000000000..cce81d23d1 --- /dev/null +++ b/lib/routes/vocus/user.js @@ -0,0 +1,60 @@ +const axios = require('@/utils/axios'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + const link = `https://vocus.cc/user/@${id}`; + + const { _id, fullname, intro } = (await axios({ + method: 'get', + url: `https://api.sosreader.com/api/users/${id}`, + headers: { + Referer: link, + }, + })).data; + + const { articles } = (await axios({ + method: 'get', + url: `https://api.sosreader.com/api/articles?userId=${_id}&num=10&status=2&sort=lastPublishAt`, + headers: { + Referer: link, + }, + })).data; + + const items = await Promise.all( + articles.map(async (item) => { + const itemUrl = `https://api.sosreader.com/api/article/${item._id}`; + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await axios({ + method: 'get', + url: itemUrl, + headers: { + Referer: link, + }, + }); + + const description = response.data.article.content; + + const single = { + title: item.title, + link: `https://vocus.cc/@${id}/${item._id}`, + author: item.user.fullname, + description: description, + pubDate: new Date(item.updatedAt).toUTCString(), + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `${fullname}的个人文章 - 方格子`, + link: link, + description: intro, + item: items, + }; +};