增加:甩甩尾巴 (#916)

- 实现 #758 
- 暂时先放到`购物`下面了
This commit is contained in:
凉凉 2018-10-18 12:10:23 +08:00 committed by DIYgod
parent 465324b67d
commit 1b12e3f6c6
3 changed files with 92 additions and 0 deletions

View File

@ -1570,6 +1570,14 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
<route name="小米有品每日上新" author="xyqfer" example="/mi/youpin/new" path="/mi/youpin/new"/>
### 甩甩尾巴
<route name="甩甩尾巴" author="xyqfer" example="/dgtle/trade/111" path="/dgtle/trade/:typeId?" :paramsDesc="['分类 id默认为全部']"/>
| 全部 | 电脑 | 手机 | 平板 | 相机 | 影音 | 外设 | 生活 | 公告 |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| 0 | 111 | 109 | 110 | 113 | 114 | 115 | 112 | 116 |
## 网络小说
### 笔趣阁

View File

@ -661,4 +661,7 @@ router.get('/parcel/hermesuk/:tracking', require('./routes/parcel/hermesuk'));
// 腾讯大家
router.get('/dajia/index', require('./routes/dajia/'));
// 甩甩尾巴
router.get('/dgtle/trade/:typeId?', require('./routes/dgtle/trade'));
module.exports = router;

81
routes/dgtle/trade.js Normal file
View File

@ -0,0 +1,81 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
let { typeId = '' } = ctx.params;
if (typeId === 0) {
typeId = '';
}
const host = 'http://trade.dgtle.com';
const baseUrl = `${host}/dgtle_module.php?mod=trade&typeid=${typeId}`;
const res = await axios({
method: 'get',
url: baseUrl,
});
const $ = cheerio.load(res.data);
const tradeList = $('.tradebox');
const resultItem = await Promise.all(
tradeList
.map(async (_, tradeItem) => {
const $tradeItem = $(tradeItem);
const url = `${host}${$tradeItem.find('.tradetitle a').attr('href')}`;
const item = {
title: $tradeItem.find('.tradetitle').attr('title'),
description: '',
link: url,
author: $tradeItem.find('.tradeuser').text(),
};
const key = `dgtle-trade: ${url}`;
const value = await ctx.cache.get(key);
if (value) {
item.description = value.description;
item.pubDate = value.pubDate;
} else {
const tradeDetail = await axios({
method: 'get',
url: url,
});
const $ = cheerio.load(tradeDetail.data);
const pubDate = new Date(
$('.cr_date > em')
.last()
.text()
).toUTCString();
let description = `<img referrerpolicy="no-referrer" src="${$tradeItem
.find('.cover')
.attr('src')
.replace(/\?.+/g, '')}" /><br>`;
description += $tradeItem.find('.tradeprice').text();
description += $('#trade_info').html();
description += $('.pcb').html();
item.description = description;
item.pubDate = pubDate;
ctx.cache.set(
key,
{
pubDate,
description,
},
24 * 60 * 60
);
}
return Promise.resolve(item);
})
.get()
);
ctx.state.data = {
title: '甩甩尾巴',
description: '纯净,安全的玩家闲置物品交易平台',
link: baseUrl,
item: resultItem,
};
};