feat: better Reeder support (#6510)

This commit is contained in:
Henry Wang
2020-12-23 18:08:28 +00:00
committed by GitHub
parent 7d1e0b3a84
commit 3426f8a1f4

View File

@@ -1,16 +1,20 @@
const art = require('art-template'); const art = require('art-template');
const path = require('path'); const path = require('path');
const config = require('@/config').value; const config = require('@/config').value;
const typeRegrx = /\.(atom|rss)$/; const typeRegex = /\.(atom|rss)$/;
const unsupportedRegrx = /\.json$/; const unsupportedRegex = /\.json$/;
module.exports = async (ctx, next) => { module.exports = async (ctx, next) => {
if (ctx.request.path.match(unsupportedRegrx)) { 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>'); 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>');
} }
ctx.state.type = ctx.request.path.match(typeRegrx) || ['', '']; if (ctx.headers['user-agent'].includes('Reeder')) {
ctx.request.path = ctx.request.path.replace(typeRegrx, ''); ctx.request.path = ctx.request.path.replace(/.com$/, '');
}
ctx.state.type = ctx.request.path.match(typeRegex) || ['', ''];
ctx.request.path = ctx.request.path.replace(typeRegex, '');
await next(); await next();