diff --git a/lib/config.ts b/lib/config.ts index e19ab2b50..077dcf19a 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -67,6 +67,7 @@ type ConfigEnvKeys = | 'DISABLE_NSFW' | 'SUFFIX' | 'TITLE_LENGTH_LIMIT' + | 'FORMAT' // OpenAI | 'OPENAI_API_KEY' | 'OPENAI_MODEL' @@ -340,6 +341,7 @@ export type Config = { }; suffix?: string; titleLengthLimit: number; + format: string; openai: { apiKey?: string; model?: string; @@ -842,6 +844,7 @@ const calculateValue = () => { }, suffix: envs.SUFFIX, titleLengthLimit: toInt(envs.TITLE_LENGTH_LIMIT, 150), + format: envs.FORMAT || 'rss', openai: { apiKey: envs.OPENAI_API_KEY, model: envs.OPENAI_MODEL || 'gpt-3.5-turbo-16k', diff --git a/lib/middleware/cache.ts b/lib/middleware/cache.ts index fe5acf34d..0a9d28cb8 100644 --- a/lib/middleware/cache.ts +++ b/lib/middleware/cache.ts @@ -19,7 +19,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => { } const requestPath = ctx.req.path; - const format = `:${ctx.req.query('format') || 'rss'}`; + const format = `:${ctx.req.query('format') || config.format}`; const limit = ctx.req.query('limit') ? `:${ctx.req.query('limit')}` : ''; const key = 'rsshub:koa-redis-cache:' + h64ToString(requestPath + format + limit); const controlKey = 'rsshub:path-requested:' + h64ToString(requestPath + format + limit); diff --git a/lib/middleware/template.tsx b/lib/middleware/template.tsx index ecc947ee5..8983b8c2d 100644 --- a/lib/middleware/template.tsx +++ b/lib/middleware/template.tsx @@ -20,7 +20,7 @@ const middleware: MiddlewareHandler = async (ctx, next) => { } const data: Data = ctx.get('data'); - const outputType = ctx.req.query('format') || 'rss'; + const outputType = ctx.req.query('format') || config.format; // only enable when debugInfo=true if (config.debugInfo) {