From e2b0d3b4bf48c8ae4e83b90be2934ef3775772c1 Mon Sep 17 00:00:00 2001
From: Xizeyoupan <44920131+xizeyoupan@users.noreply.github.com>
Date: Wed, 18 Mar 2020 10:38:06 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E9=85=B7=E5=AE=89=20(#4261)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/other.md | 6 ++++
lib/router.js | 3 ++
lib/routes/coolapk/tuwen.js | 60 +++++++++++++++++++++++++++++++++++++
lib/routes/coolapk/utils.js | 26 ++++++++++++++++
4 files changed, 95 insertions(+)
create mode 100644 lib/routes/coolapk/tuwen.js
create mode 100644 lib/routes/coolapk/utils.js
diff --git a/docs/other.md b/docs/other.md
index 1c6f1b1a2f..f939a0126b 100644
--- a/docs/other.md
+++ b/docs/other.md
@@ -601,3 +601,9 @@ type 为 all 时,category 参数不支持 cost 和 free
### はてな匿名ダイアリー - 人気記事アーカイブ
+
+## 酷安
+
+### 图文-编辑精选
+
+
diff --git a/lib/router.js b/lib/router.js
index f397f1134e..0bc9b87811 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -2380,6 +2380,9 @@ router.get('/moxingfans', require('./routes/moxingfans'));
// Chiphell
router.get('/chiphell/forum/:forumId?', require('./routes/chiphell/forum'));
+// 酷安
+router.get('/coolapk/tuwen', require('./routes/coolapk/tuwen'));
+
// CTFHub Event Calendar
router.get('/ctfhub/calendar/:limit?/:form?/:class?/:title?', require('./routes/ctfhub'));
diff --git a/lib/routes/coolapk/tuwen.js b/lib/routes/coolapk/tuwen.js
new file mode 100644
index 0000000000..efb7bf6bb6
--- /dev/null
+++ b/lib/routes/coolapk/tuwen.js
@@ -0,0 +1,60 @@
+const got = require('@/utils/got');
+const utils = require('./utils');
+
+module.exports = async (ctx) => {
+ const full_url = utils.base_url + '/v6/page/dataList?url=%23%2Ffeed%2FdigestList%3Ftype%3D12%26is_html_article%3D1%26recommend%3D3&title=%E5%9B%BE%E6%96%87&page=1';
+ const response = await got({
+ method: 'get',
+ url: full_url,
+ headers: utils.getHeaders(),
+ });
+ const data = response.data.data;
+
+ const out = await Promise.all(
+ data.map(async (item) => {
+ const title = item.title;
+ const pubdate = new Date(item.dateline * 1000).toUTCString();
+ const itemUrl = item.shareUrl;
+ const author = item.username;
+
+ const description = await ctx.cache.tryGet(itemUrl, async () => {
+ const result = await got({
+ method: 'get',
+ url: itemUrl.split('?')[0],
+ headers: utils.getHeaders(),
+ });
+
+ const raw = JSON.parse(result.data.data.message_raw_input);
+ const tags = raw.map((i) => {
+ if (i.type === 'text') {
+ return `
${i.message}
`;
+ } else if (i.type === 'image') {
+ return `
+ 
+ ${i.description}
`;
+ } else {
+ return i;
+ }
+ });
+
+ return tags.join('');
+ });
+
+ const single = {
+ title: title,
+ description: description,
+ pubDate: pubdate,
+ link: itemUrl,
+ author: author,
+ };
+ return Promise.resolve(single);
+ })
+ );
+
+ ctx.state.data = {
+ title: `酷安图文`,
+ link: full_url,
+ description: `酷安 - 编辑精选 - 图文`,
+ item: out,
+ };
+};
diff --git a/lib/routes/coolapk/utils.js b/lib/routes/coolapk/utils.js
new file mode 100644
index 0000000000..7cb98b0dba
--- /dev/null
+++ b/lib/routes/coolapk/utils.js
@@ -0,0 +1,26 @@
+const md5 = require('@/utils/md5');
+
+const get_app_token = () => {
+ const DEVICE_ID = '8513efac-09ea-3709-b214-95b366f1a185';
+ const now = Math.round(new Date().getTime() / 1000);
+ const hex_now = '0x' + now.toString(16);
+ const md5_now = md5(now.toString());
+ const s = 'token://com.coolapk.market/c67ef5943784d09750dcfbb31020f0ab?' + md5_now + '$' + DEVICE_ID + '&com.coolapk.market';
+ const md5_s = md5(Buffer.from(s).toString('base64'));
+ const token = md5_s + DEVICE_ID + hex_now;
+ return token;
+};
+
+const base_url = 'https://api.coolapk.com';
+
+const getHeaders = () => ({
+ 'X-Requested-With': 'XMLHttpRequest',
+ 'X-App-Id': 'com.coolapk.market',
+ 'X-App-Token': get_app_token(),
+});
+
+module.exports = {
+ get_app_token,
+ base_url,
+ getHeaders,
+};