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
This commit is contained in:
Henry Wang
2019-07-03 05:10:36 +01:00
committed by DIYgod
parent 569100cdb0
commit 9c837f1bc2
8 changed files with 10 additions and 11 deletions

View File

@@ -7,8 +7,8 @@ module.exports = async (ctx, next) => {
throw Error('wrong path'); throw Error('wrong path');
} }
if (ctx.state.data && (!ctx.state.data.item || ctx.state.data.item.length === 0) && !ctx.state.allowEmpty) { 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 origin site or create an issue to feedback on https://github.com/DIYgod/RSSHub/issues/new/choose'); 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 // decode HTML entities

View File

@@ -48,6 +48,6 @@ module.exports = async (ctx) => {
title, title,
link, link,
item, item,
allowEmpty: true,
}; };
ctx.state.allowEmpty = true;
}; };

View File

@@ -12,8 +12,7 @@ module.exports = async (ctx) => {
const data = $('script#shoebox-ember-data-store').html(); const data = $('script#shoebox-ember-data-store').html();
const jsonObject = JSON.parse(data); const jsonObject = JSON.parse(data);
const versions = jsonObject.data.attributes.versionHistory; const versions = jsonObject.data.attributes.versionHistory;
let date; const date = versions[0].releaseDate;
date = versions[0].releaseDate;
const titleTags = $('h1').attr('class', 'product-header__title'); const titleTags = $('h1').attr('class', 'product-header__title');
titleTags.find('span').remove(); titleTags.find('span').remove();

View File

@@ -37,6 +37,6 @@ module.exports = async (ctx) => {
description: `${name} 直播间开播状态`, description: `${name} 直播间开播状态`,
lastBuildDate: new Date().toUTCString(), lastBuildDate: new Date().toUTCString(),
item: liveItem, item: liveItem,
allowEmpty: true,
}; };
ctx.state.allowEmpty = true;
}; };

View File

@@ -31,5 +31,5 @@ module.exports = async (ctx) => {
}) })
.filter((item) => item), .filter((item) => item),
}; };
ctx.state.allowEmpty = true; ctx.state.data.allowEmpty = true;
}; };

View File

@@ -24,7 +24,7 @@ module.exports = async (ctx) => {
}, },
]; ];
} else { } else {
ctx.state.allowEmpty = true; ctx.state.data.allowEmpty = true;
} }
ctx.state.data = { ctx.state.data = {

View File

@@ -30,7 +30,7 @@ module.exports = async (ctx) => {
title: `${title} - Konachan Anime Wallpapers`, title: `${title} - Konachan Anime Wallpapers`,
link: `${baseUrl}/post/popular_recent`, link: `${baseUrl}/post/popular_recent`,
item: posts item: posts
.filter((post) => !(safemode && post.rating != 's')) .filter((post) => !(safemode && post.rating !== 's'))
.map((post) => { .map((post) => {
const content = (url) => { const content = (url) => {
if (url.startsWith('//')) { if (url.startsWith('//')) {

View File

@@ -47,12 +47,12 @@ module.exports = async (ctx) => {
if (ctx.params.id === 'allow_empty') { if (ctx.params.id === 'allow_empty') {
item = null; item = null;
ctx.state.allowEmpty = true;
} }
ctx.state.data = { ctx.state.data = {
title: `Test ${ctx.params.id}`, title: `Test ${ctx.params.id}`,
link: 'https://github.com/DIYgod/RSSHub', link: 'https://github.com/DIYgod/RSSHub',
item: item, item,
allowEmpty: ctx.params.id === 'allow_empty',
}; };
}; };