feat: add 酷安 (#4261)

This commit is contained in:
Xizeyoupan
2020-03-18 10:38:06 +08:00
committed by GitHub
parent 1d151ebf6f
commit e2b0d3b4bf
4 changed files with 95 additions and 0 deletions

View File

@@ -601,3 +601,9 @@ type 为 all 时category 参数不支持 cost 和 free
### はてな匿名ダイアリー - 人気記事アーカイブ ### はてな匿名ダイアリー - 人気記事アーカイブ
<Route author="masakichi" example="/hatena/anonymous_diary/archive" path="/hatena/anonymous_diary/archive"/> <Route author="masakichi" example="/hatena/anonymous_diary/archive" path="/hatena/anonymous_diary/archive"/>
## 酷安
### 图文-编辑精选
<Route author="xizeyoupan" example="/coolapk/tuwen" path="/coolapk/tuwen" />

View File

@@ -2380,6 +2380,9 @@ router.get('/moxingfans', require('./routes/moxingfans'));
// Chiphell // Chiphell
router.get('/chiphell/forum/:forumId?', require('./routes/chiphell/forum')); router.get('/chiphell/forum/:forumId?', require('./routes/chiphell/forum'));
// 酷安
router.get('/coolapk/tuwen', require('./routes/coolapk/tuwen'));
// CTFHub Event Calendar // CTFHub Event Calendar
router.get('/ctfhub/calendar/:limit?/:form?/:class?/:title?', require('./routes/ctfhub')); router.get('/ctfhub/calendar/:limit?/:form?/:class?/:title?', require('./routes/ctfhub'));

View File

@@ -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 `<p>${i.message}</p>`;
} else if (i.type === 'image') {
return `<p class="img-container" style="text-align:center">
<img src="${i.url}"><br>
<span class="image-caption">${i.description}</span></p>`;
} 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,
};
};

View File

@@ -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,
};