路由优化 (#711)

3DM,简书,苹果维修计划
This commit is contained in:
Henry Wang 2018-09-16 15:44:09 +01:00 committed by DIYgod
parent 658a58278c
commit cafed499b8
7 changed files with 34 additions and 107 deletions

View File

@ -350,8 +350,6 @@ RSSHub 提供下列 API 接口:
<route name="用户动态" author="DIYgod" example="/jike/user/82D23B32-CF36-4C59-AD6F-D05E3552CBF3" path="/jike/user/:id" :paramsDesc="['用户 id, 可在即刻 web 端用户页 URL 中找到']"/>
<route name="用户动态" author="DIYgod" example="/jike/user/82D23B32-CF36-4C59-AD6F-D05E3552CBF3" path="/jike/user/:id" :paramsDesc="['用户 id, 可在即刻 web 端用户页 URL 中找到']"/>
<route name="即刻小报" author="Andiedie" example="/jike/daily" path="/jike/daily"/>
### 微信
@ -370,9 +368,7 @@ RSSHub 提供下列 API 接口:
<route name="首页" author="DIYgod" example="/jianshu/home" path="/jianshu/home"/>
<route name="7 日热门" author="DIYgod" example="/jianshu/trending/weekly" path="/jianshu/trending/weekly"/>
<route name="30 日热门" author="DIYgod" example="/jianshu/trending/monthly" path="/jianshu/trending/monthly"/>
<route name="热门" author="DIYgod HenryQW" example="/jianshu/trending/weekly" path="/jianshu/trending/:timeframe" :paramsDesc="['按周 `weekly` 或 按月 `monthly`']"/>
<route name="专题" author="DIYgod" example="/jianshu/collection/xYuZYD" path="/jianshu/collection/:id" :paramsDesc="['专题 id, 可在专题页 URL 中找到']"/>
@ -1485,11 +1481,13 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
<route name="新闻中心" author="zhboner" example="/3dm/news" path="/3dm/news"/>
<route name="新闻" author="sinchang jacky2001114" example="/3dm/detroitbecomehuman/news" path="/3dm/:name/news" :paramsDesc="['游戏的编号可以在专题页的 url 中找到']"/>
<route name="游戏资讯" author="sinchang jacky2001114 HenryQW" example="/3dm/detroitbecomehuman/news" path="/3dm/:name/:type" :paramsDesc="['游戏的名字, 可以在专题页的 url 中找到', '资讯类型']">
<route name="攻略" author="sinchang jacky2001114" example="/j3dm/detroitbecomehuman/gl" path="/3dm/:name/gl" :paramsDesc="['游戏的编号可以在专题页的 url 中找到']"/>
| 新闻 | 攻略 | 下载资源 | 区块链快讯 |
| ---- | ---- | -------- | ---------- |
| news | gl | resource | blockchain |
<route name="下载" author="sinchang" example="/3dm/detroitbecomehuman/download" path="/3dm/:name/download" :paramsDesc="['游戏的编号可以在专题页的 url 中找到']"/>
</route>
### 机核网
@ -1558,7 +1556,7 @@ IATA 国际航空运输协会机场代码, 参见[维基百科 国际航空运
### Apple
<route name="更换和维修扩展计划" author="metowolf" example="/apple/exchange_repair" path="/apple/exchange_repair"/>
<route name="更换和维修扩展计划" author="metowolf" example="/apple/exchange_repair" path="/apple/exchange_repair/:country?" :paramsDesc="['苹果官网 URL 中的国家代码, 默认 `cn`']/>
#### App Store/Mac App Store

View File

@ -145,8 +145,7 @@ router.get('/express/:company/:number', require('./routes/express/express'));
// 简书
router.get('/jianshu/home', require('./routes/jianshu/home'));
router.get('/jianshu/trending/weekly', require('./routes/jianshu/weekly'));
router.get('/jianshu/trending/monthly', require('./routes/jianshu/monthly'));
router.get('/jianshu/trending/:timeframe', require('./routes/jianshu/trending'));
router.get('/jianshu/collection/:id', require('./routes/jianshu/collection'));
router.get('/jianshu/user/:id', require('./routes/jianshu/user'));
@ -306,8 +305,7 @@ router.get('/yande.re/post/popular_recent/:period', require('./routes/yande.re/p
router.get('/nytimes/morning_post', require('./routes/nytimes/morning_post'));
// 3dm
router.get('/3dm/:name/download', require('./routes/3dm/download'));
router.get('/3dm/:name/:type', require('./routes/3dm/news'));
router.get('/3dm/:name/:type', require('./routes/3dm/game'));
router.get('/3dm/news', require('./routes/3dm/news_center'));
// 喜马拉雅
@ -538,7 +536,7 @@ router.get('/zaobao/realtime/:type?', require('./routes/zaobao/realtime'));
router.get('/zaobao/znews/:type?', require('./routes/zaobao/znews'));
// Apple
router.get('/apple/exchange_repair', require('./routes/apple/exchange_repair'));
router.get('/apple/exchange_repair/:country?', require('./routes/apple/exchange_repair'));
// Minecraft CurseForge
router.get('/curseforge/files/:project', require('./routes/curseforge/files'));

View File

@ -3,7 +3,7 @@ const cheerio = require('cheerio');
module.exports = async (ctx) => {
const name = ctx.params.name;
const type = 'download';
const type = ctx.params.type;
const url = `http://www.3dmgame.com/games/${name}/${type}`;
const response = await axios({
@ -14,7 +14,14 @@ module.exports = async (ctx) => {
const data = response.data;
const $ = cheerio.load(data);
const list = $('.ZQ_Left .Llis_4 li').get();
let list;
if (type === 'resource') {
list = $('.ZQ_Left .Llis_4 .lis:first-of-type li').get();
} else {
list = $('.ZQ_Left .lis')
.slice(0, 10)
.get();
}
const items = await Promise.all(
list.map(async (i) => {

View File

@ -1,49 +0,0 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const name = ctx.params.name;
const type = ctx.params.type;
const url = `http://www.3dmgame.com/games/${name}/${type}`;
const response = await axios({
method: 'get',
url: url,
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('.ZQ_Left .lis');
const items = await Promise.all(
list.map(async (i) => {
const item = $(i);
const url = item.find('.bt').attr('href');
const cache = await ctx.cache.get(url);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const single = {
title: item.find('.bt').text(),
pubDate: item.find('.time p').text(),
description: item.find('.miaoshu').text(),
link: url,
guid: url,
};
ctx.cache.set(url, JSON.stringify(item), 24 * 60 * 60);
return Promise.resolve(single);
})
);
ctx.state.data = {
title: $('title')
.text()
.split('_')[0],
link: url,
item: items,
};
};

View File

@ -5,7 +5,14 @@ const url = require('url');
const host = 'https://www.apple.com/';
module.exports = async (ctx) => {
const link = url.resolve(host, 'cn/support/exchange_repair/');
let link;
if (!ctx.params.country) {
ctx.params.country = 'cn';
}
ctx.params.country === 'us' ? (link = url.resolve(host, '/support/exchange_repair/')) : (link = url.resolve(host, `${ctx.params.country}/support/exchange_repair/`));
const response = await axios.get(link);
const $ = cheerio.load(response.data);

View File

@ -2,11 +2,13 @@ const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const link = `https://www.jianshu.com/trending/${ctx.params.timeframe}`;
const response = await axios({
method: 'get',
url: 'https://www.jianshu.com/trending/monthly',
url: link,
headers: {
Referer: 'https://www.jianshu.com/trending/monthly',
Referer: link,
},
});
@ -16,9 +18,9 @@ module.exports = async (ctx) => {
const list = $('.note-list li');
ctx.state.data = {
title: '简书 30 日热门',
link: 'https://www.jianshu.com/trending/monthly',
description: '简书 30 日热门',
title: `简书 ${ctx.params.timeframe === 'weekly' ? '7' : '30'} 日热门`,
link,
description: `简书 ${ctx.params.timeframe === 'weekly' ? '7' : '30'} 日热门`,
item:
list &&
list

View File

@ -1,36 +0,0 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const response = await axios({
method: 'get',
url: 'https://www.jianshu.com/trending/weekly',
headers: {
Referer: 'https://www.jianshu.com/trending/weekly',
},
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('.note-list li');
ctx.state.data = {
title: '简书 7 日热门',
link: 'https://www.jianshu.com/trending/weekly',
description: '简书 7 日热门',
item:
list &&
list
.map((index, item) => {
item = $(item);
return {
title: item.find('.title').text(),
description: `作者:${item.find('.nickname').text()}<br>描述:${item.find('.abstract').text()}<br><img referrerpolicy="no-referrer" src="https:${item.find('.img-blur').data('echo')}">`,
pubDate: new Date(item.find('.time').data('shared-at')).toUTCString(),
link: `https://www.jianshu.com${item.find('.title').attr('href')}`,
};
})
.get(),
};
};