feat(core): first attempt to init script standard (#8224)

- lazy load
- rate limit per path
- init .debug.json support
- docs
- maintainer
- radar
This commit is contained in:
NeverBehave
2021-09-22 05:41:00 -07:00
committed by GitHub
parent d77a039f05
commit 0792f7ba25
51 changed files with 737 additions and 331 deletions

View File

@@ -1,14 +1,9 @@
const art = require('art-template');
const path = require('path');
const config = require('@/config').value;
const typeRegex = /\.(atom|rss)$/;
const unsupportedRegex = /\.json$/;
const typeRegex = /\.(atom|rss|debug\.json)$/;
module.exports = async (ctx, next) => {
if (ctx.request.path.match(unsupportedRegex)) {
throw Error('<b>JSON output had been removed, see: <a href="https://github.com/DIYgod/RSSHub/issues/1114">https://github.com/DIYgod/RSSHub/issues/1114</a></b>');
}
if (ctx.headers['user-agent'] && ctx.headers['user-agent'].includes('Reeder')) {
ctx.request.path = ctx.request.path.replace(/.com$/, '');
}
@@ -18,6 +13,17 @@ module.exports = async (ctx, next) => {
await next();
if (ctx.state.type[1] === 'debug.json' && config.debugInfo) {
ctx.set({
'Content-Type': 'application/json; charset=UTF-8',
});
if (ctx.state.json) {
ctx.body = JSON.stringify(ctx.state.json, null, 4);
} else {
ctx.body = JSON.stringify({ message: "plugin does not set json" });
}
}
if (!ctx.body) {
let template;