diff --git a/docs/README.md b/docs/README.md index d20df3ca1..f4f11c268 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1570,6 +1570,14 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运 +### 甩甩尾巴 + + + +| 全部 | 电脑 | 手机 | 平板 | 相机 | 影音 | 外设 | 生活 | 公告 | +| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | +| 0 | 111 | 109 | 110 | 113 | 114 | 115 | 112 | 116 | + ## 网络小说 ### 笔趣阁 diff --git a/router.js b/router.js index 8ee74b2e3..b72d0d1d7 100644 --- a/router.js +++ b/router.js @@ -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; diff --git a/routes/dgtle/trade.js b/routes/dgtle/trade.js new file mode 100644 index 000000000..58be78fcf --- /dev/null +++ b/routes/dgtle/trade.js @@ -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 = `
`; + + 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, + }; +};