base: handle lacking config situation
This commit is contained in:
parent
a7b20283ec
commit
ca38c4de65
54
router.js
54
router.js
|
|
@ -2,6 +2,8 @@ const Router = require('koa-router');
|
|||
const router = new Router();
|
||||
const art = require('art-template');
|
||||
const path = require('path');
|
||||
const config = require('./config');
|
||||
const logger = require('./utils/logger');
|
||||
|
||||
router.get('/', async (ctx) => {
|
||||
ctx.set({
|
||||
|
|
@ -10,7 +12,7 @@ router.get('/', async (ctx) => {
|
|||
ctx.body = art(path.resolve(__dirname, './views/welcome.art'), {});
|
||||
});
|
||||
|
||||
// // bilibili
|
||||
// bilibili
|
||||
router.get('/bilibili/user/video/:uid', require('./routes/bilibili/video'));
|
||||
router.get('/bilibili/user/fav/:uid', require('./routes/bilibili/fav'));
|
||||
router.get('/bilibili/user/coin/:uid', require('./routes/bilibili/coin'));
|
||||
|
|
@ -26,51 +28,55 @@ router.get('/bilibili/live/search/:key/:order', require('./routes/bilibili/liveS
|
|||
router.get('/bilibili/live/area/:areaID/:order', require('./routes/bilibili/liveArea'));
|
||||
|
||||
|
||||
// // 微博
|
||||
// 微博
|
||||
router.get('/weibo/user/:uid', require('./routes/weibo/user'));
|
||||
router.get('/weibo/keyword/:keyword', require('./routes/weibo/keyword'));
|
||||
|
||||
// // 网易云音乐
|
||||
// 网易云音乐
|
||||
router.get('/ncm/playlist/:id', require('./routes/ncm/playlist'));
|
||||
router.get('/ncm/user/playlist/:uid', require('./routes/ncm/userplaylist'));
|
||||
router.get('/ncm/artist/:id', require('./routes/ncm/artist'));
|
||||
|
||||
// // 掘金
|
||||
// 掘金
|
||||
router.get('/juejin/category/:category', require('./routes/juejin/category'));
|
||||
|
||||
// // 自如
|
||||
// 自如
|
||||
router.get('/ziroom/room/:city/:iswhole/:room/:keyword', require('./routes/ziroom/room'));
|
||||
|
||||
// // 快递
|
||||
// 快递
|
||||
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/collection/:id', require('./routes/jianshu/collection'));
|
||||
router.get('/jianshu/user/:id', require('./routes/jianshu/user'));
|
||||
|
||||
// // 知乎
|
||||
// 知乎
|
||||
router.get('/zhihu/collection/:id', require('./routes/zhihu/collection'));
|
||||
router.get('/zhihu/people/activities/:id', require('./routes/zhihu/activities'));
|
||||
router.get('/zhihu/people/answers/:id', require('./routes/zhihu/answers'));
|
||||
router.get('/zhihu/zhuanlan/:id', require('./routes/zhihu/zhuanlan'));
|
||||
|
||||
// // 贴吧
|
||||
// 贴吧
|
||||
router.get('/tieba/forum/:kw', require('./routes/tieba/forum'));
|
||||
|
||||
// // 妹子图
|
||||
// 妹子图
|
||||
router.get('/mzitu', require('./routes/mzitu/category'));
|
||||
router.get('/mzitu/tags', require('./routes/mzitu/tags'));
|
||||
router.get('/mzitu/category/:category', require('./routes/mzitu/category'));
|
||||
router.get('/mzitu/post/:id', require('./routes/mzitu/post'));
|
||||
router.get('/mzitu/tag/:tag', require('./routes/mzitu/tag'));
|
||||
|
||||
// // Pixiv
|
||||
router.get('/pixiv/user/bookmarks/:id', require('./routes/pixiv/bookmarks'));
|
||||
router.get('/pixiv/user/:id/', require('./routes/pixiv/user'));
|
||||
router.get('/pixiv/ranking/:mode/:date?', require('./routes/pixiv/ranking'));
|
||||
// pixiv
|
||||
if (config.pixiv && config.pixiv.client_id && config.pixiv.client_secret && config.pixiv.username && config.pixiv.password) {
|
||||
router.get('/pixiv/user/bookmarks/:id', require('./routes/pixiv/bookmarks'));
|
||||
router.get('/pixiv/user/:id/', require('./routes/pixiv/user'));
|
||||
router.get('/pixiv/ranking/:mode/:date?', require('./routes/pixiv/ranking'));
|
||||
} else {
|
||||
logger.warn('pixiv RSS is disabled for lacking config.');
|
||||
}
|
||||
|
||||
// 豆瓣
|
||||
router.get('/douban/movie/playing', require('./routes/douban/playing'));
|
||||
|
|
@ -99,17 +105,29 @@ router.get('/toutiao/today', require('./routes/toutiao/today'));
|
|||
router.get('/toutiao/user/:id', require('./routes/toutiao/user'));
|
||||
|
||||
// Disqus
|
||||
router.get('/disqus/posts/:forum', require('./routes/disqus/posts'));
|
||||
if (config.disqus && config.disqus.api_key) {
|
||||
router.get('/disqus/posts/:forum', require('./routes/disqus/posts'));
|
||||
} else {
|
||||
logger.warn('Disqus RSS is disabled for lacking config.');
|
||||
}
|
||||
|
||||
// Twitter
|
||||
router.get('/twitter/user/:id', require('./routes/twitter/user'));
|
||||
if (config.twitter && config.twitter.consumer_key && config.twitter.consumer_secret && config.twitter.access_token && config.twitter.access_token_secret) {
|
||||
router.get('/twitter/user/:id', require('./routes/twitter/user'));
|
||||
} else {
|
||||
logger.warn('Twitter RSS is disabled for lacking config.');
|
||||
}
|
||||
|
||||
// Instagram
|
||||
router.get('/instagram/user/:id', require('./routes/instagram/user'));
|
||||
|
||||
// Youtube
|
||||
router.get('/youtube/user/:username', require('./routes/youtube/user'));
|
||||
router.get('/youtube/channel/:id', require('./routes/youtube/channel'));
|
||||
if (config.youtube && config.youtube.key) {
|
||||
router.get('/youtube/user/:username', require('./routes/youtube/user'));
|
||||
router.get('/youtube/channel/:id', require('./routes/youtube/channel'));
|
||||
} else {
|
||||
logger.warn('Youtube RSS is disabled for lacking config.');
|
||||
}
|
||||
|
||||
// 即刻
|
||||
router.get('/jike/topic/:id', require('./routes/jike/topic'));
|
||||
|
|
|
|||
|
|
@ -1,12 +1,3 @@
|
|||
const config = require('../../config');
|
||||
|
||||
const pixivConfig = config.pixiv;
|
||||
|
||||
if (!pixivConfig) {
|
||||
module.exports = () => {};
|
||||
return;
|
||||
}
|
||||
|
||||
const getToken = require('./token');
|
||||
const getBookmarks = require('./api/getBookmarks');
|
||||
const getUserDetail = require('./api/getUserDetail');
|
||||
|
|
@ -14,7 +5,7 @@ const getUserDetail = require('./api/getUserDetail');
|
|||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
if (typeof getToken() === 'null') {
|
||||
if (!getToken()) {
|
||||
ctx.throw(500);
|
||||
return;
|
||||
}
|
||||
|
|
@ -25,19 +16,19 @@ module.exports = async (ctx) => {
|
|||
]);
|
||||
|
||||
const illusts = bookmarksResponse.data.illusts;
|
||||
const username = userDetailResponse.data.user.name
|
||||
const username = userDetailResponse.data.user.name;
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${username} 的收藏`,
|
||||
link: `https://www.pixiv.net/bookmark.php?id=${id}`,
|
||||
description: `${username} 的 pixiv 最新收藏`,
|
||||
item: illusts.map((illust, index) => {
|
||||
item: illusts.map((illust) => {
|
||||
const images = [];
|
||||
if (illust.page_count === 1) {
|
||||
images.push(`<p><img referrerpolicy="no-referrer" src="https://pixiv.cat/${illust.id}.jpg"/></p>`);
|
||||
} else {
|
||||
for (let i = 0; i < illust.page_count; i++) {
|
||||
images.push(`<p><img referrerpolicy="no-referrer" src="https://pixiv.cat/${illust.id}-${i+1}.jpg"/></p>`);
|
||||
images.push(`<p><img referrerpolicy="no-referrer" src="https://pixiv.cat/${illust.id}-${i + 1}.jpg"/></p>`);
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
exports.modules = {
|
||||
maskHeader: {
|
||||
'App-OS': 'ios',
|
||||
'App-OS-Version': '10.3.1',
|
||||
'App-Version': '6.7.1',
|
||||
'User-Agent': 'PixivIOSApp/6.7.1 (iOS 10.3.1; iPhone8,1)'
|
||||
}
|
||||
maskHeader: {
|
||||
'App-OS': 'ios',
|
||||
'App-OS-Version': '10.3.1',
|
||||
'App-Version': '6.7.1',
|
||||
'User-Agent': 'PixivIOSApp/6.7.1 (iOS 10.3.1; iPhone8,1)'
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,51 +1,41 @@
|
|||
const config = require('../../config');
|
||||
|
||||
const pixivConfig = config.pixiv;
|
||||
|
||||
if (!pixivConfig) {
|
||||
logger.info('Pixiv RSS disable.');
|
||||
module.exports = () => {};
|
||||
return;
|
||||
}
|
||||
|
||||
const getToken = require('./token');
|
||||
const getRanking = require('./api/getRanking');
|
||||
|
||||
const titles = {
|
||||
'day': 'pixiv 日排行',
|
||||
'week': 'pixiv 周排行',
|
||||
'month': 'pixiv 月排行',
|
||||
'day_male': 'pixiv 受男性欢迎排行',
|
||||
'day_female': 'pixiv 受女性欢迎排行',
|
||||
'week_original': 'pixiv 原创作品排行',
|
||||
'week_rookie': 'pixiv 新人排行',
|
||||
'day_r18': 'pixiv R-18 日排行',
|
||||
'day_male_r18': 'pixiv R-18 受男性欢迎排行',
|
||||
'day_female_r18': 'pixiv R-18 受女性欢迎排行',
|
||||
'week_r18': 'pixiv R-18 周排行',
|
||||
'week_r18g': 'pixiv R-18G 排行'
|
||||
'day': 'pixiv 日排行',
|
||||
'week': 'pixiv 周排行',
|
||||
'month': 'pixiv 月排行',
|
||||
'day_male': 'pixiv 受男性欢迎排行',
|
||||
'day_female': 'pixiv 受女性欢迎排行',
|
||||
'week_original': 'pixiv 原创作品排行',
|
||||
'week_rookie': 'pixiv 新人排行',
|
||||
'day_r18': 'pixiv R-18 日排行',
|
||||
'day_male_r18': 'pixiv R-18 受男性欢迎排行',
|
||||
'day_female_r18': 'pixiv R-18 受女性欢迎排行',
|
||||
'week_r18': 'pixiv R-18 周排行',
|
||||
'week_r18g': 'pixiv R-18G 排行'
|
||||
};
|
||||
|
||||
const links = {
|
||||
'day': 'https://www.pixiv.net/ranking.php?mode=daily',
|
||||
'week': 'https://www.pixiv.net/ranking.php?mode=weekly',
|
||||
'month': 'https://www.pixiv.net/ranking.php?mode=monthly',
|
||||
'day_male': 'https://www.pixiv.net/ranking.php?mode=male',
|
||||
'day_female': 'https://www.pixiv.net/ranking.php?mode=female',
|
||||
'week_original': 'https://www.pixiv.net/ranking.php?mode=original',
|
||||
'week_rookie': 'https://www.pixiv.net/ranking.php?mode=rookie',
|
||||
'day_r18': 'https://www.pixiv.net/ranking.php?mode=daily_r18',
|
||||
'day_male_r18': 'https://www.pixiv.net/ranking.php?mode=male_r18',
|
||||
'day_female_r18': 'https://www.pixiv.net/ranking.php?mode=female_r18',
|
||||
'week_r18': 'https://www.pixiv.net/ranking.php?mode=weekly_r18',
|
||||
'week_r18g': 'https://www.pixiv.net/ranking.php?mode=r18g'
|
||||
'day': 'https://www.pixiv.net/ranking.php?mode=daily',
|
||||
'week': 'https://www.pixiv.net/ranking.php?mode=weekly',
|
||||
'month': 'https://www.pixiv.net/ranking.php?mode=monthly',
|
||||
'day_male': 'https://www.pixiv.net/ranking.php?mode=male',
|
||||
'day_female': 'https://www.pixiv.net/ranking.php?mode=female',
|
||||
'week_original': 'https://www.pixiv.net/ranking.php?mode=original',
|
||||
'week_rookie': 'https://www.pixiv.net/ranking.php?mode=rookie',
|
||||
'day_r18': 'https://www.pixiv.net/ranking.php?mode=daily_r18',
|
||||
'day_male_r18': 'https://www.pixiv.net/ranking.php?mode=male_r18',
|
||||
'day_female_r18': 'https://www.pixiv.net/ranking.php?mode=female_r18',
|
||||
'week_r18': 'https://www.pixiv.net/ranking.php?mode=weekly_r18',
|
||||
'week_r18g': 'https://www.pixiv.net/ranking.php?mode=r18g'
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const mode = ctx.params.mode;
|
||||
const date = ctx.params.date ? new Date(ctx.params.date) : new Date();
|
||||
|
||||
if (typeof getToken() === 'null') {
|
||||
if (!getToken()) {
|
||||
ctx.throw(500);
|
||||
return;
|
||||
}
|
||||
|
|
@ -66,7 +56,7 @@ module.exports = async (ctx) => {
|
|||
images.push(`<p><img referrerpolicy="no-referrer" src="https://pixiv.cat/${illust.id}.jpg"/></p>`);
|
||||
} else {
|
||||
for (let i = 0; i < illust.page_count; i++) {
|
||||
images.push(`<p><img referrerpolicy="no-referrer" src="https://pixiv.cat/${illust.id}-${i+1}.jpg"/></p>`);
|
||||
images.push(`<p><img referrerpolicy="no-referrer" src="https://pixiv.cat/${illust.id}-${i + 1}.jpg"/></p>`);
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,20 +1,10 @@
|
|||
const config = require('../../config');
|
||||
|
||||
const pixivConfig = config.pixiv;
|
||||
|
||||
if (!pixivConfig) {
|
||||
logger.info('Pixiv RSS disable.');
|
||||
module.exports = () => {};
|
||||
return;
|
||||
}
|
||||
|
||||
const getToken = require('./token');
|
||||
const getIllusts = require('./api/getIllusts');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
if (typeof getToken() === 'null') {
|
||||
if (!getToken()) {
|
||||
ctx.throw(500);
|
||||
return;
|
||||
}
|
||||
|
|
@ -22,7 +12,7 @@ module.exports = async (ctx) => {
|
|||
const response = await getIllusts(id, getToken());
|
||||
|
||||
const illusts = response.data.illusts;
|
||||
const username = illusts[0].user.name
|
||||
const username = illusts[0].user.name;
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${username} 的 pixiv 动态`,
|
||||
|
|
@ -34,7 +24,7 @@ module.exports = async (ctx) => {
|
|||
images.push(`<p><img referrerpolicy="no-referrer" src="https://pixiv.cat/${illust.id}.jpg"/></p>`);
|
||||
} else {
|
||||
for (let i = 0; i < illust.page_count; i++) {
|
||||
images.push(`<p><img referrerpolicy="no-referrer" src="https://pixiv.cat/${illust.id}-${i+1}.jpg"/></p>`);
|
||||
images.push(`<p><img referrerpolicy="no-referrer" src="https://pixiv.cat/${illust.id}-${i + 1}.jpg"/></p>`);
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
|
|
|||
Loading…
Reference in New Issue