diff --git a/lib/router.js b/lib/router.js
index 5cba2976e..c96f9d893 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -1,7 +1,5 @@
const Router = require('koa-router');
const router = new Router();
-const config = require('./config');
-const logger = require('./utils/logger');
// index
router.get('/', require('./routes/index'));
@@ -113,14 +111,10 @@ router.get('/mzitu/post/:id', require('./routes/mzitu/post'));
router.get('/mzitu/tag/:tag', require('./routes/mzitu/tag'));
// 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'));
- router.get('/pixiv/search/:keyword/:order?', require('./routes/pixiv/search'));
-} else {
- logger.warn('pixiv RSS is disabled due to the lack of token, api key or relevant config in config.js.');
-}
+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'));
+router.get('/pixiv/search/:keyword/:order?', require('./routes/pixiv/search'));
// 豆瓣
router.get('/douban/movie/playing', require('./routes/douban/playing'));
@@ -164,20 +158,12 @@ router.get('/zcfy/hot', require('./routes/zcfy/hot'));
router.get('/jinritoutiao/keyword/:keyword', require('./routes/jinritoutiao/keyword'));
// Disqus
-if (config.disqus && config.disqus.api_key) {
- router.get('/disqus/posts/:forum', require('./routes/disqus/posts'));
-} else {
- logger.warn('Disqus RSS is disabled due to the lack of token, api key or relevant config in config.js.');
-}
+router.get('/disqus/posts/:forum', require('./routes/disqus/posts'));
// Twitter
-if (config.twitter && config.twitter.consumer_key && config.twitter.consumer_secret) {
- router.get('/twitter/user/:id', require('./routes/twitter/user'));
- router.get('/twitter/list/:id/:name', require('./routes/twitter/list'));
- router.get('/twitter/likes/:id', require('./routes/twitter/likes'));
-} else {
- logger.warn('Twitter RSS is disabled due to the lack of token, api key or relevant config in config.js.');
-}
+router.get('/twitter/user/:id', require('./routes/twitter/user'));
+router.get('/twitter/list/:id/:name', require('./routes/twitter/list'));
+router.get('/twitter/likes/:id', require('./routes/twitter/likes'));
router.get('/twitter/followings/:id', require('./routes/twitter/followings'));
// Instagram
@@ -185,13 +171,9 @@ router.get('/instagram/user/:id', require('./routes/instagram/user'));
router.get('/instagram/tag/:tag', require('./routes/instagram/tag'));
// Youtube
-if (config.youtube && config.youtube.key) {
- router.get('/youtube/user/:username/:embed?', require('./routes/youtube/user'));
- router.get('/youtube/channel/:id/:embed?', require('./routes/youtube/channel'));
- router.get('/youtube/playlist/:id/:embed?', require('./routes/youtube/playlist'));
-} else {
- logger.warn('Youtube RSS is disabled due to the lack of token, api key or relevant config in config.js.');
-}
+router.get('/youtube/user/:username/:embed?', require('./routes/youtube/user'));
+router.get('/youtube/channel/:id/:embed?', require('./routes/youtube/channel'));
+router.get('/youtube/playlist/:id/:embed?', require('./routes/youtube/playlist'));
// 即刻
router.get('/jike/topic/:id', require('./routes/jike/topic'));
@@ -239,25 +221,13 @@ router.get('/v2ex/post/:postid', require('./routes/v2ex/post'));
// Telegram
router.get('/telegram/channel/:username', require('./routes/telegram/channel'));
-if (config.telegram && config.telegram.token) {
- if (config.imgur && config.imgur.clientId) {
- router.get('/telegram/stickerpack/:name', require('./routes/telegram/stickerpack'));
- } else {
- logger.warn('Telegram Sticker Pack RSS is disabled due to the lack of token, api key or relevant config in config.js.');
- }
-} else {
- logger.warn('Telegram RSS is disabled due to the lack of token, api key or relevant config in config.js.');
-}
+router.get('/telegram/stickerpack/:name', require('./routes/telegram/stickerpack'));
// readhub
router.get('/readhub/category/:category', require('./routes/readhub/category'));
// GitHub
-if (config.github && config.github.access_token) {
- router.get('/github/repos/:user', require('./routes/github/repos'));
-} else {
- logger.warn('GitHub Repos RSS is disabled due to the lack of token, api key or relevant config in config.js.');
-}
+router.get('/github/repos/:user', require('./routes/github/repos'));
router.get('/github/trending/:since/:language?', require('./routes/github/trending'));
router.get('/github/issue/:user/:repo', require('./routes/github/issue'));
router.get('/github/pull/:user/:repo', require('./routes/github/pulls'));
diff --git a/lib/routes/disqus/posts.js b/lib/routes/disqus/posts.js
index 17459ed5e..4d1fb2002 100644
--- a/lib/routes/disqus/posts.js
+++ b/lib/routes/disqus/posts.js
@@ -2,6 +2,9 @@ const got = require('@/utils/got');
const config = require('@/config');
module.exports = async (ctx) => {
+ if (!config.disqus || !config.disqus.api_key) {
+ throw 'Disqus RSS is disabled due to the lack of relevant config';
+ }
const forum = ctx.params.forum;
const response = await got({
diff --git a/lib/routes/github/branches.js b/lib/routes/github/branches.js
index 8a0bb0207..5404703ef 100644
--- a/lib/routes/github/branches.js
+++ b/lib/routes/github/branches.js
@@ -1,4 +1,5 @@
const got = require('@/utils/got');
+const config = require('@/config');
module.exports = async (ctx) => {
const user = ctx.params.user;
@@ -10,6 +11,9 @@ module.exports = async (ctx) => {
const response = await got({
method: 'get',
url,
+ params: {
+ access_token: config.github && config.github.access_token,
+ },
});
const data = response.data;
diff --git a/lib/routes/github/file.js b/lib/routes/github/file.js
index b34812569..556c417f2 100644
--- a/lib/routes/github/file.js
+++ b/lib/routes/github/file.js
@@ -9,16 +9,12 @@ module.exports = async (ctx) => {
const fileUrl = `https://github.com/${user}/${repo}/commits/${branch}/${filepath}`;
- const reqParams = {
- sha: branch,
- path: filepath,
- };
- if (config.github.access_token) {
- reqParams.access_token = config.github.access_token;
- }
-
const res = await got.get(`https://api.github.com/repos/${user}/${repo}/commits`, {
- params: reqParams,
+ params: {
+ sha: branch,
+ path: filepath,
+ access_token: config.github && config.github.access_token,
+ },
});
const list = res.data;
const count = [];
diff --git a/lib/routes/github/follower.js b/lib/routes/github/follower.js
index 7dc389cef..a42adbe37 100644
--- a/lib/routes/github/follower.js
+++ b/lib/routes/github/follower.js
@@ -2,6 +2,9 @@ const got = require('@/utils/got');
const config = require('@/config');
module.exports = async (ctx) => {
+ if (!config.github || !config.github.access_token) {
+ throw 'GitHub follower RSS is disabled due to the lack of relevant config';
+ }
const user = ctx.params.user;
const host = `https://github.com/${user}`;
diff --git a/lib/routes/github/issue.js b/lib/routes/github/issue.js
index 11c72f077..6878ec48c 100644
--- a/lib/routes/github/issue.js
+++ b/lib/routes/github/issue.js
@@ -16,7 +16,7 @@ module.exports = async (ctx) => {
url,
params: {
sort: 'created',
- access_token: config.github.access_token,
+ access_token: config.github && config.github.access_token,
},
});
const data = response.data;
diff --git a/lib/routes/github/pulls.js b/lib/routes/github/pulls.js
index 5bab0694e..f7ccbd864 100644
--- a/lib/routes/github/pulls.js
+++ b/lib/routes/github/pulls.js
@@ -16,7 +16,7 @@ module.exports = async (ctx) => {
url,
params: {
sort: 'created',
- access_token: config.github.access_token,
+ access_token: config.github && config.github.access_token,
},
});
const data = response.data;
diff --git a/lib/routes/github/repos.js b/lib/routes/github/repos.js
index 0d6edd54c..7745ac46d 100644
--- a/lib/routes/github/repos.js
+++ b/lib/routes/github/repos.js
@@ -9,7 +9,7 @@ module.exports = async (ctx) => {
url: `https://api.github.com/users/${user}/repos`,
params: {
sort: 'created',
- access_token: config.github.access_token,
+ access_token: config.github && config.github.access_token,
},
});
const data = response.data;
diff --git a/lib/routes/github/star.js b/lib/routes/github/star.js
index 5f80848cf..b89724ef1 100644
--- a/lib/routes/github/star.js
+++ b/lib/routes/github/star.js
@@ -2,6 +2,9 @@ const got = require('@/utils/got');
const config = require('@/config');
module.exports = async (ctx) => {
+ if (!config.github || !config.github.access_token) {
+ throw 'GitHub star RSS is disabled due to the lack of relevant config';
+ }
const user = ctx.params.user;
const repo = ctx.params.repo;
diff --git a/lib/routes/pixiv/bookmarks.js b/lib/routes/pixiv/bookmarks.js
index 24a828ca7..623edd66d 100644
--- a/lib/routes/pixiv/bookmarks.js
+++ b/lib/routes/pixiv/bookmarks.js
@@ -1,8 +1,13 @@
const getToken = require('./token');
const getBookmarks = require('./api/getBookmarks');
const getUserDetail = require('./api/getUserDetail');
+const config = require('@/config');
module.exports = async (ctx) => {
+ if (!config.pixiv || !config.pixiv.client_id || !config.pixiv.client_secret || !config.pixiv.username || !config.pixiv.password) {
+ throw 'pixiv RSS is disabled due to the lack of relevant config';
+ }
+
const id = ctx.params.id;
if (!getToken()) {
diff --git a/lib/routes/pixiv/ranking.js b/lib/routes/pixiv/ranking.js
index fce48bb12..c77bd5971 100644
--- a/lib/routes/pixiv/ranking.js
+++ b/lib/routes/pixiv/ranking.js
@@ -1,5 +1,6 @@
const getToken = require('./token');
const getRanking = require('./api/getRanking');
+const config = require('@/config');
const titles = {
day: 'pixiv 日排行',
@@ -32,6 +33,10 @@ const links = {
};
module.exports = async (ctx) => {
+ if (!config.pixiv || !config.pixiv.client_id || !config.pixiv.client_secret || !config.pixiv.username || !config.pixiv.password) {
+ throw 'pixiv RSS is disabled due to the lack of relevant config';
+ }
+
const mode = ctx.params.mode;
const date = ctx.params.date ? new Date(ctx.params.date) : new Date();
diff --git a/lib/routes/pixiv/search.js b/lib/routes/pixiv/search.js
index cd542fa21..7cae21cc3 100644
--- a/lib/routes/pixiv/search.js
+++ b/lib/routes/pixiv/search.js
@@ -1,8 +1,13 @@
const getToken = require('./token');
const searchPopularIllust = require('./api/searchPopularIllust');
const searchIllust = require('./api/searchIllust');
+const config = require('@/config');
module.exports = async (ctx) => {
+ if (!config.pixiv || !config.pixiv.client_id || !config.pixiv.client_secret || !config.pixiv.username || !config.pixiv.password) {
+ throw 'pixiv RSS is disabled due to the lack of relevant config';
+ }
+
const keyword = ctx.params.keyword;
const order = ctx.params.order || 'date';
diff --git a/lib/routes/pixiv/token.js b/lib/routes/pixiv/token.js
index 040b9a6aa..b44dd2829 100644
--- a/lib/routes/pixiv/token.js
+++ b/lib/routes/pixiv/token.js
@@ -94,7 +94,9 @@ async function tokenLoop() {
}
}
-tokenLoop();
+if (config.pixiv && config.pixiv.client_id && config.pixiv.client_secret && config.pixiv.username && config.pixiv.password) {
+ tokenLoop();
+}
module.exports = function getToken() {
return token;
diff --git a/lib/routes/pixiv/user.js b/lib/routes/pixiv/user.js
index c06079667..b1dcfe97b 100644
--- a/lib/routes/pixiv/user.js
+++ b/lib/routes/pixiv/user.js
@@ -1,7 +1,12 @@
const getToken = require('./token');
const getIllusts = require('./api/getIllusts');
+const config = require('@/config');
module.exports = async (ctx) => {
+ if (!config.pixiv || !config.pixiv.client_id || !config.pixiv.client_secret || !config.pixiv.username || !config.pixiv.password) {
+ throw 'pixiv RSS is disabled due to the lack of relevant config';
+ }
+
const id = ctx.params.id;
if (!getToken()) {
diff --git a/lib/routes/telegram/stickerpack.js b/lib/routes/telegram/stickerpack.js
index c1f08b9db..eba9c3cd6 100644
--- a/lib/routes/telegram/stickerpack.js
+++ b/lib/routes/telegram/stickerpack.js
@@ -10,6 +10,9 @@ if (config.imgur && config.imgur.clientId) {
}
module.exports = async (ctx) => {
+ if (!config.telegram || !config.telegram.token || !config.imgur || !config.imgur.clientId) {
+ throw 'Telegram Sticker Pack RSS is disabled due to the lack of relevant config';
+ }
const name = ctx.params.name;
const cacheDays = 30;
diff --git a/lib/routes/twitter/likes.js b/lib/routes/twitter/likes.js
index 3f177a9f2..63de3b522 100644
--- a/lib/routes/twitter/likes.js
+++ b/lib/routes/twitter/likes.js
@@ -1,6 +1,10 @@
const utils = require('./utils');
+const config = require('@/config');
module.exports = async (ctx) => {
+ if (!config.twitter || !config.twitter.consumer_key || !config.twitter.consumer_secret) {
+ throw 'Twitter RSS is disabled due to the lack of relevant config';
+ }
const id = ctx.params.id;
const result = await utils.getTwit().get('favorites/list', {
screen_name: id,
diff --git a/lib/routes/twitter/list.js b/lib/routes/twitter/list.js
index 284f31272..dc4b29ef8 100644
--- a/lib/routes/twitter/list.js
+++ b/lib/routes/twitter/list.js
@@ -1,6 +1,10 @@
const utils = require('./utils');
+const config = require('@/config');
module.exports = async (ctx) => {
+ if (!config.twitter || !config.twitter.consumer_key || !config.twitter.consumer_secret) {
+ throw 'Twitter RSS is disabled due to the lack of relevant config';
+ }
const { id, name } = ctx.params;
const result = await utils.getTwit().get('lists/statuses', {
owner_screen_name: id,
diff --git a/lib/routes/twitter/user.js b/lib/routes/twitter/user.js
index 6f1515b8a..10b263dd0 100644
--- a/lib/routes/twitter/user.js
+++ b/lib/routes/twitter/user.js
@@ -1,6 +1,11 @@
const utils = require('./utils');
+const config = require('@/config');
module.exports = async (ctx) => {
+ if (!config.twitter || !config.twitter.consumer_key || !config.twitter.consumer_secret) {
+ throw 'Twitter RSS is disabled due to the lack of relevant config';
+ }
+
const id = ctx.params.id;
const result = await utils.getTwit().get('statuses/user_timeline', {
screen_name: id,
diff --git a/lib/routes/youtube/channel.js b/lib/routes/youtube/channel.js
index 8aa29586d..aa9060630 100644
--- a/lib/routes/youtube/channel.js
+++ b/lib/routes/youtube/channel.js
@@ -1,6 +1,10 @@
const utils = require('./utils');
+const config = require('@/config');
module.exports = async (ctx) => {
+ if (!config.youtube || !config.youtube.key) {
+ throw 'Youtube RSS is disabled due to the lack of relevant config';
+ }
const id = ctx.params.id;
const embed = !ctx.params.embed;
diff --git a/lib/routes/youtube/playlist.js b/lib/routes/youtube/playlist.js
index 66a3dd019..7be645884 100644
--- a/lib/routes/youtube/playlist.js
+++ b/lib/routes/youtube/playlist.js
@@ -1,6 +1,10 @@
const utils = require('./utils');
+const config = require('@/config');
module.exports = async (ctx) => {
+ if (!config.youtube || !config.youtube.key) {
+ throw 'Youtube RSS is disabled due to the lack of relevant config';
+ }
const id = ctx.params.id;
const embed = !ctx.params.embed;
diff --git a/lib/routes/youtube/user.js b/lib/routes/youtube/user.js
index 6130d205f..9d810f31b 100644
--- a/lib/routes/youtube/user.js
+++ b/lib/routes/youtube/user.js
@@ -1,6 +1,10 @@
const utils = require('./utils');
+const config = require('@/config');
module.exports = async (ctx) => {
+ if (!config.youtube || !config.youtube.key) {
+ throw 'Youtube RSS is disabled due to the lack of relevant config';
+ }
const username = ctx.params.username;
const embed = !ctx.params.embed;