mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 23:00:48 +08:00
feat: adnmb optimization (#4693)
This commit is contained in:
@@ -8,7 +8,7 @@ pageClass: routes
|
||||
|
||||
### 串
|
||||
|
||||
<Route author="zcx1218029121" example="/adnmb/20/1" path="/adnmb/:pid/page" :paramsDesc="['板块列表,见下表','页数, 1开始必填']" >
|
||||
<Route author="zcx1218029121" example="/adnmb/20" path="/adnmb/:pid" :paramsDesc="['板块 id 或者板块名称,例如`/adnmb/20`等价于`/adnmb/欢乐恶搞`,现有板块请参考下表']" >
|
||||
|
||||
| 综合版 1 | 围炉 | 欢乐恶搞 | 速报 2 | 推理 | 跑团 | 技术宅 | 料理 | 猫版 | 音乐 | 考试 | 社畜 |
|
||||
| -------- | ---- | -------- | ------ | ---- | ---- | ------ | ---- | ---- | ---- | ---- | ---- |
|
||||
|
||||
@@ -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'));
|
||||
|
||||
@@ -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 !== '' ? '<img src="https://nmbimg.fastmirror.org/thumb/' + item.img + item.ext + '"/>' : '';
|
||||
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 !== '' ? '<img style="max-width: 100%" src="https://nmbimg.fastmirror.org/image/' + item.img + item.ext + '"/>' : '';
|
||||
let replys = '';
|
||||
item.replys.forEach((reply) => {
|
||||
const replyImg = reply.img !== '' ? '<img src="https://nmbimg.fastmirror.org/thumb/' + reply.img + reply.ext + '"/>' : '';
|
||||
const replyImg = reply.img !== '' ? '<img style="max-width: 100%" src="https://nmbimg.fastmirror.org/image/' + reply.img + reply.ext + '"/>' : '';
|
||||
replys += `<h4>${reply.title} ${reply.name} ${reply.now} ID:${reply.userid} No.${reply.id}</h4> </br>
|
||||
${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,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user