From 9c837f1bc2365ddcb5d11bcf8508d007eac45bd9 Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Wed, 3 Jul 2019 05:10:36 +0100 Subject: [PATCH] fix: retain allowEmpty in ctx.state (#2542) * fix: retain allowEmpty in ctx.state See: https://github.com/koajs/koa/issues/1172 * fix: pass test case allow_empty * chore: get rid of eslint warning --- lib/middleware/parameter.js | 4 ++-- lib/routes/apple/appstore/price.js | 2 +- lib/routes/apple/appstore/update.js | 3 +-- lib/routes/bilibili/liveRoom.js | 2 +- lib/routes/douban/playing.js | 2 +- lib/routes/douyu/room.js | 2 +- lib/routes/konachan/post_popular_recent.js | 2 +- lib/routes/test/index.js | 4 ++-- 8 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/middleware/parameter.js b/lib/middleware/parameter.js index e2a0b2461c..a7b21d5ed6 100644 --- a/lib/middleware/parameter.js +++ b/lib/middleware/parameter.js @@ -7,8 +7,8 @@ module.exports = async (ctx, next) => { throw Error('wrong path'); } - if (ctx.state.data && (!ctx.state.data.item || ctx.state.data.item.length === 0) && !ctx.state.allowEmpty) { - throw Error('this route is empty, please check the origin site or create an issue to feedback on https://github.com/DIYgod/RSSHub/issues/new/choose'); + if (ctx.state.data && (!ctx.state.data.item || ctx.state.data.item.length === 0) && !ctx.state.data.allowEmpty) { + throw Error('this route is empty, please check the original site or create an issue on https://github.com/DIYgod/RSSHub/issues/new/choose'); } // decode HTML entities diff --git a/lib/routes/apple/appstore/price.js b/lib/routes/apple/appstore/price.js index 6bcbdbb63c..2ba51ff284 100644 --- a/lib/routes/apple/appstore/price.js +++ b/lib/routes/apple/appstore/price.js @@ -48,6 +48,6 @@ module.exports = async (ctx) => { title, link, item, + allowEmpty: true, }; - ctx.state.allowEmpty = true; }; diff --git a/lib/routes/apple/appstore/update.js b/lib/routes/apple/appstore/update.js index b27e3bd7c3..3115163535 100644 --- a/lib/routes/apple/appstore/update.js +++ b/lib/routes/apple/appstore/update.js @@ -12,8 +12,7 @@ module.exports = async (ctx) => { const data = $('script#shoebox-ember-data-store').html(); const jsonObject = JSON.parse(data); const versions = jsonObject.data.attributes.versionHistory; - let date; - date = versions[0].releaseDate; + const date = versions[0].releaseDate; const titleTags = $('h1').attr('class', 'product-header__title'); titleTags.find('span').remove(); diff --git a/lib/routes/bilibili/liveRoom.js b/lib/routes/bilibili/liveRoom.js index dbfb844d1b..7fc305089e 100644 --- a/lib/routes/bilibili/liveRoom.js +++ b/lib/routes/bilibili/liveRoom.js @@ -37,6 +37,6 @@ module.exports = async (ctx) => { description: `${name} 直播间开播状态`, lastBuildDate: new Date().toUTCString(), item: liveItem, + allowEmpty: true, }; - ctx.state.allowEmpty = true; }; diff --git a/lib/routes/douban/playing.js b/lib/routes/douban/playing.js index e1ecf56450..8bf474b734 100644 --- a/lib/routes/douban/playing.js +++ b/lib/routes/douban/playing.js @@ -31,5 +31,5 @@ module.exports = async (ctx) => { }) .filter((item) => item), }; - ctx.state.allowEmpty = true; + ctx.state.data.allowEmpty = true; }; diff --git a/lib/routes/douyu/room.js b/lib/routes/douyu/room.js index 36ad93787a..df6da27b82 100644 --- a/lib/routes/douyu/room.js +++ b/lib/routes/douyu/room.js @@ -24,7 +24,7 @@ module.exports = async (ctx) => { }, ]; } else { - ctx.state.allowEmpty = true; + ctx.state.data.allowEmpty = true; } ctx.state.data = { diff --git a/lib/routes/konachan/post_popular_recent.js b/lib/routes/konachan/post_popular_recent.js index f52848eb06..d81b54f44c 100644 --- a/lib/routes/konachan/post_popular_recent.js +++ b/lib/routes/konachan/post_popular_recent.js @@ -30,7 +30,7 @@ module.exports = async (ctx) => { title: `${title} - Konachan Anime Wallpapers`, link: `${baseUrl}/post/popular_recent`, item: posts - .filter((post) => !(safemode && post.rating != 's')) + .filter((post) => !(safemode && post.rating !== 's')) .map((post) => { const content = (url) => { if (url.startsWith('//')) { diff --git a/lib/routes/test/index.js b/lib/routes/test/index.js index 34a0115481..2a34384395 100644 --- a/lib/routes/test/index.js +++ b/lib/routes/test/index.js @@ -47,12 +47,12 @@ module.exports = async (ctx) => { if (ctx.params.id === 'allow_empty') { item = null; - ctx.state.allowEmpty = true; } ctx.state.data = { title: `Test ${ctx.params.id}`, link: 'https://github.com/DIYgod/RSSHub', - item: item, + item, + allowEmpty: ctx.params.id === 'allow_empty', }; };