Merge pull request #81 from Qixingchen/master

添加 腾讯的吐个槽
This commit is contained in:
DIYgod 2018-05-05 23:02:46 +08:00 committed by GitHub
commit d1da3d0b9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 0 deletions

View File

@ -459,6 +459,20 @@ city: 城市的中文名,可选,默认北京
参数: 无
### 腾讯吐个槽
#### 吐槽新帖
举例: https://rss.now.sh/tucaoqq/post/28564/CdRI0728
路由: `/tucaoqq/post/:project/:key`
参数
project: 产品ID
key: 产品密钥
## 搭建
环境:需要 Node.js v7.6.0 或更高版本,若启用 Redis 缓存需要先启动 Redis

View File

@ -27,6 +27,7 @@
"crypto": "1.0.1",
"eslint": "4.19.1",
"form-data": "^2.3.2",
"js-md5": "^0.7.3",
"json-bigint": "0.2.3",
"koa": "2.5.0",
"koa-redis-cache": "3.0.0",

View File

@ -77,4 +77,7 @@ router.get('/dapenti/tugua', require('./routes/dapenti/tugua'));
// Dockone
router.get('/dockone/weekly', require('./routes/dockone/weekly'));
// 腾讯吐个槽
router.get('/tucaoqq/post/:project/:key', require('./routes/tucaoqq/post'));
module.exports = router;

43
routes/tucaoqq/post.js Normal file
View File

@ -0,0 +1,43 @@
const axios = require('axios');
const art = require('art-template');
const path = require('path');
const config = require('../../config');
const md5 = require('js-md5');
module.exports = async (ctx) => {
const projectID = ctx.params.project;
const key = ctx.params.key;
const response = await axios({
method: 'get',
url: `https://support.qq.com/api/v1/${projectID}/posts`,
headers: {
'User-Agent': config.ua,
'Timestamp': Math.round(+new Date() / 1000).toString(),
'Signature': md5(Math.round(+new Date() / 1000).toString() + key)
}
});
const data = response.data.data;
ctx.body = art(path.resolve(__dirname, '../../views/rss.art'), {
title: `${projectID} 的 吐个槽新帖`,
link: `https://support.qq.com/product/${projectID}`,
description: `${projectID} 的 吐个槽新帖`,
lastBuildDate: new Date().toUTCString(),
item: data.map((item) => {
let pubdate = new Date(item.created_at.replace(' ', 'T') + "+08:00");
let imgHTML = '';
if (data.images) {
for (let i = 0; i < data.images.length; i++) {
imgHTML += `<img referrerpolicy="no-referrer" src="${data.images[i]}">`;
}
}
return {
title: item.nick_name + ' 的吐槽',
description: `${item.content}${imgHTML}`,
pubDate: pubdate.toUTCString(),
link: `https://support.qq.com/products/${projectID}`
};
}),
});
};