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');
}
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

View File

@@ -48,6 +48,6 @@ module.exports = async (ctx) => {
title,
link,
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 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();

View File

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

View File

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

View File

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

View File

@@ -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('//')) {

View File

@@ -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',
};
};