From 3c652fe1599275b3f913f1bf7c2abbcced7c54d2 Mon Sep 17 00:00:00 2001
From: ma jia cong <9a6c5609806a@gmail.com>
Date: Thu, 1 Aug 2019 18:22:11 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E9=BE=99=E7=A9=BA?=
=?UTF-8?q?=E5=88=86=E5=8C=BA=E3=80=81=E5=B8=96=E5=AD=90=20(#2707)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/social-media.md | 10 ++++++
lib/router.js | 5 +++
lib/routes/lkong/forum.js | 73 ++++++++++++++++++++++++++++++++++++++
lib/routes/lkong/thread.js | 56 +++++++++++++++++++++++++++++
4 files changed, 144 insertions(+)
create mode 100644 lib/routes/lkong/forum.js
create mode 100644 lib/routes/lkong/thread.js
diff --git a/docs/social-media.md b/docs/social-media.md
index 735cb0b1d..7bb712437 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 6c8387aa7..1377c35aa 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 000000000..23754a421
--- /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 000000000..0d734684d
--- /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,
+ };
+};