diff --git a/docs/bbs.md b/docs/bbs.md index 5a6454d015..f67b34415e 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -8,7 +8,7 @@ pageClass: routes ### 串 - + | 综合版 1 | 围炉 | 欢乐恶搞 | 速报 2 | 推理 | 跑团 | 技术宅 | 料理 | 猫版 | 音乐 | 考试 | 社畜 | | -------- | ---- | -------- | ------ | ---- | ---- | ------ | ---- | ---- | ---- | ---- | ---- | diff --git a/lib/router.js b/lib/router.js index 78dc92b9fc..5d11946069 100755 --- a/lib/router.js +++ b/lib/router.js @@ -2564,7 +2564,7 @@ router.get('/hbut/cs/:type', require('./routes/universities/hbut/cs')); router.get('/acwifi', require('./routes/acwifi')); // a岛匿名版 -router.get('/adnmb/:pid/:page', require('./routes/adnmb/index')); +router.get('/adnmb/:pid', require('./routes/adnmb/index')); // MIT科技评论 router.get('/mittrchina/article', require('./routes/mittrchina')); diff --git a/lib/routes/adnmb/index.js b/lib/routes/adnmb/index.js index 07a9c4b643..c6277fc9f2 100644 --- a/lib/routes/adnmb/index.js +++ b/lib/routes/adnmb/index.js @@ -1,9 +1,30 @@ -// a岛匿名版 const got = require('@/utils/got'); + +async function getForumInfo(pid, ctx) { + const cache_key = `adnmb::forum::${pid}`; + const cache = await ctx.cache.get(cache_key); + if (cache) { + return JSON.parse(cache); + } + const forumListResponse = await got('https://adnmb2.com/Api/getForumList'); + const matchedForum = forumListResponse.data + .map((a) => a.forums) + .flat() + .filter((c) => c.id === pid || c.name === pid || c.showName === pid); + if (matchedForum.length === 0) { + throw 'Forum Not Found'; + } + const basicForumInfo = (({ id, name, showName, msg }) => ({ id, name, showName, msg }))(matchedForum[0]); + ctx.cache.set(cache_key, JSON.stringify(basicForumInfo)); + return basicForumInfo; +} + module.exports = async (ctx) => { const pid = ctx.params.pid; - const page = ctx.params.page; - const url = `https://adnmb2.com/Api/showf?id=${pid}&page=${page}`; + + const forumInfo = await getForumInfo(pid, ctx); + + const url = `https://adnmb2.com/Api/showf?id=${forumInfo.id}&page=1`; const response = await got({ method: 'get', url: url, @@ -12,11 +33,15 @@ module.exports = async (ctx) => { const items = []; data.forEach((item) => { - const newItems = { title: item.content, pubDate: '${item.now}', link: `https://adnmb2.com/t/${item.id}` }; - const img = item.img !== '' ? '' : ''; + const newItems = { + title: item.content, + pubDate: new Date(item.now.replace(/\(.*?\)/g, ' ') + ' +0800').toUTCString(), + link: `https://adnmb2.com/t/${item.id}`, + }; + const img = item.img !== '' ? '' : ''; let replys = ''; item.replys.forEach((reply) => { - const replyImg = reply.img !== '' ? '' : ''; + const replyImg = reply.img !== '' ? '' : ''; replys += `

${reply.title} ${reply.name} ${reply.now} ID:${reply.userid} No.${reply.id}


${reply.content} ${replyImg} @@ -33,13 +58,9 @@ module.exports = async (ctx) => { }); ctx.state.data = { - // 源标题 - title: `a岛匿名版`, - // 源链接 - link: `https://adnmb2.com/Forum`, - // 源说明 - description: `A岛是一个前台匿名后台实名的论坛`, - // 遍历此前获取的数据 + title: `${forumInfo.showName ? forumInfo.showName : forumInfo.name} - a岛匿名版`, + link: `https://adnmb2.com/f/${forumInfo.name}`, + description: forumInfo.msg, item: items, }; };