mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 14:40:23 +08:00
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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user