diff --git a/docs/other.md b/docs/other.md index f8d3c8cf93..b77d0fd543 100644 --- a/docs/other.md +++ b/docs/other.md @@ -491,6 +491,14 @@ type 为 all 时,category 参数不支持 cost 和 free +### 用户创作 + + + +### 用户收藏 + + + ## 福利资源-met.red ### 福利资源-met.red diff --git a/lib/router.js b/lib/router.js index 8a00f22f74..747938b3f7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1372,6 +1372,8 @@ router.get('/yuque/doc/:repo_id', require('./routes/yuque/doc')); // 飞地 router.get('/enclavebooks/category/:id?', require('./routes/enclavebooks/category')); +router.get('/enclavebooks/user/:uid', require('./routes/enclavebooks/user.js')); +router.get('/enclavebooks/collection/:uid', require('./routes/enclavebooks/collection.js')); // 色花堂 - 色花图片版块 router.get('/dsndsht23/picture/:subforumid', require('./routes/dsndsht23/pictures')); diff --git a/lib/routes/enclavebooks/collection.js b/lib/routes/enclavebooks/collection.js new file mode 100644 index 0000000000..c6e5f14843 --- /dev/null +++ b/lib/routes/enclavebooks/collection.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const uid = ctx.params.uid; + + const authorUrl = 'https://app.enclavebooks.cn/v2/getOtherUserInformation?otherUserId%5B%5D=' + uid; + const authorResponse = await got(authorUrl); + const autherName = authorResponse.data.result[0].nickname; + + const url = 'https://app.enclavebooks.cn/v2/getCollectionList?page=1&userId=' + uid; + const response = await got({ method: 'get', url }); + const responseList = response.data.result.data; + + const list = responseList.map((item) => ({ + artId: item.artId, + title: item.artTitle, + description: item.artDescription, + // pubDate: new Date(item.artTime * 1000).toUTCString(),// 收藏顺序不是文章的创作时间 + link: `http://www.enclavebooks.cn/article.html?art_id=${item.artId}`, + })); + + const result = await Promise.all( + list.map(async (item) => { + const link = 'https://app.enclavebooks.cn/v2/article?id=' + item.artId; + + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const itemReponse = await got.get(link); + item.description = itemReponse.data.result.artContent; + + ctx.cache.set(link, JSON.stringify(item)); + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: '飞地 - ' + autherName + '的收藏', + link: url, + item: result.reverse(), + }; +}; diff --git a/lib/routes/enclavebooks/user.js b/lib/routes/enclavebooks/user.js new file mode 100644 index 0000000000..607553b8c3 --- /dev/null +++ b/lib/routes/enclavebooks/user.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const uid = ctx.params.uid; + + const authorUrl = 'https://app.enclavebooks.cn/v2/getOtherUserInformation?otherUserId%5B%5D=' + uid; + const authorResponse = await got(authorUrl); + const autherName = authorResponse.data.result[0].nickname; + + const url = 'https://app.enclavebooks.cn/v2/writeListByOther?page=1&otherUserId=' + uid; + const response = await got({ method: 'get', url }); + const responseList = response.data.result.data; + + const list = responseList.map((item) => ({ + artId: item.artId, + title: item.artTitle, + description: item.artDescription, + pubDate: new Date(item.artTime * 1000).toUTCString(), + link: `http://www.enclavebooks.cn/article.html?art_id=${item.artId}`, + })); + + const result = await Promise.all( + list.map(async (item) => { + const link = 'https://app.enclavebooks.cn/v2/article?id=' + item.artId; + + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const itemReponse = await got.get(link); + item.description = itemReponse.data.result.artContent; + + ctx.cache.set(link, JSON.stringify(item)); + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: '飞地 - ' + autherName, + link: url, + item: result, + }; +};