diff --git a/docs/social-media.md b/docs/social-media.md index 735cb0b1d5..7bb7124376 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -598,6 +598,16 @@ pageClass: routes +## 龙空 + +### 分区 + + + +### 帖子 + + + ## 龙腾网 ### 转译网贴 diff --git a/lib/router.js b/lib/router.js index 6c8387aa7c..1377c35aa6 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1583,6 +1583,11 @@ router.get('/yidoutang/case/:type', require('./routes/yidoutang/case.js')); // 开眼 router.get('/kaiyan/index', require('./routes/kaiyan/index')); +// 龙空 +router.get('/lkong/forum/:id', require('./routes/lkong/forum')); +router.get('/lkong/thread/:id', require('./routes/lkong/thread')); +// router.get('/lkong/user/:id', require('./routes/lkong/user')); + // 乃木坂46官网 router.get('/nogizaka46/news', require('./routes/nogizaka46/news')); diff --git a/lib/routes/lkong/forum.js b/lib/routes/lkong/forum.js new file mode 100644 index 0000000000..23754a4212 --- /dev/null +++ b/lib/routes/lkong/forum.js @@ -0,0 +1,73 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const response = await got({ + method: 'get', + url: `http://lkong.cn/forum/index.php?mod=ajax&action=forumconfig_${id}`, + }); + const forumconfig = response.data; + + const response_forum_item = await got({ + method: 'get', + url: `http://lkong.cn/forum/index.php?mod=data&sars=forum/${id}`, + }); + + const data = response_forum_item.data; + + const items = await Promise.all( + data.data.map(async (i) => { + const item = { + title: i.subject, + pubDate: new Date(i.dateline + ' +8').toUTCString(), + }; + if (i.id.startsWith('thread_')) { + const thread_id = i.id.substr('thread_'.length); + + const thread_list_url = `http://lkong.cn/thread/index.php?mod=data&sars=thread/${thread_id}`; + const thread_config_url = `http://lkong.cn/forum/index.php?mod=ajax&action=threadconfig_${thread_id}`; + let thread_list; + let thread_config; + + const cache = await ctx.cache.get(thread_list_url); + if (cache) { + thread_list = JSON.parse(cache); + } else { + const response_thread_list = await got({ + method: 'get', + url: thread_list_url, + }); + thread_list = response_thread_list.data; + ctx.cache.set(thread_list_url, JSON.stringify(thread_list)); + } + + const cache1 = await ctx.cache.get(thread_config_url); + if (cache1) { + thread_config = JSON.parse(cache1); + } else { + const response_thread_config = await got({ + method: 'get', + url: thread_config_url, + }); + thread_config = response_thread_config.data; + ctx.cache.set(thread_config_url, JSON.stringify(thread_config)); + } + + item.link = `http://lkong.cn/thread/${thread_id}`; + item.description = thread_list.data[0].message; + item.title = thread_config.subject; + } + + return Promise.resolve(item); + }) + ); + + ctx.state.data = { + title: `龙空 ${forumconfig.name}`, + link: `http://lkong.cn/forum/${id}`, + description: forumconfig.blackboard, + image: `http://img.lkong.cn/forumavatar/000/00/00/${id}_avatar_middle.jpg`, + item: items, + }; +}; diff --git a/lib/routes/lkong/thread.js b/lib/routes/lkong/thread.js new file mode 100644 index 0000000000..0d734684de --- /dev/null +++ b/lib/routes/lkong/thread.js @@ -0,0 +1,56 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const response_thread_config = await got({ + method: 'get', + url: `http://lkong.cn/forum/index.php?mod=ajax&action=threadconfig_${id}`, + }); + const threadConfig = response_thread_config.data; + function* genPage(i) { + for (let a = 0; a < i; a++) { + yield a + 1; + } + } + + const thread_item = await Promise.all( + [...genPage(threadConfig.replies / 20)].map(async (page) => { + const thread_page_url = `http://lkong.cn/forum/index.php?mod=data&sars=thread/${id}/${page}`; + let thread_page; + + const cache = await ctx.cache.get(thread_page_url); + if (cache) { + thread_page = JSON.parse(cache); + } else { + const response = await got({ + method: 'get', + url: `http://lkong.cn/forum/index.php?mod=data&sars=thread/${id}/${page}`, + }); + thread_page = response.data; + ctx.cache.set(thread_page_url, JSON.stringify(thread_page)); + } + + const new_item = thread_page.data.map((i) => ({ + title: `${i.lou}楼`, + pubDate: new Date(i.dateline + ' +8').toUTCString(), + author: i.author, + description: i.message, + link: `http://lkong.cn/thread/${id}/${page}.p_${i.pid}`, + })); + return new_item; + }) + ); + + const thread_items = []; + thread_item.forEach((page_item) => { + page_item.forEach((item) => { + thread_items.push(item); + }); + }); + ctx.state.data = { + title: `龙空 ${threadConfig.forumname} ${threadConfig.subject}`, + link: `http://lkong.cn/thread/${id}`, + item: thread_items, + }; +};