diff --git a/lib/middleware/cache.ts b/lib/middleware/cache.ts index ca8821b32..35876a969 100644 --- a/lib/middleware/cache.ts +++ b/lib/middleware/cache.ts @@ -17,10 +17,11 @@ const middleware: MiddlewareHandler = async (ctx, next) => { } const requestPath = ctx.req.path; + const format = `:${ctx.req.query('format') || 'rss'}`; const limit = ctx.req.query('limit') ? `:${ctx.req.query('limit')}` : ''; const { h64ToString } = await xxhash(); - const key = 'rsshub:koa-redis-cache:' + h64ToString(requestPath + limit); - const controlKey = 'rsshub:path-requested:' + h64ToString(requestPath + limit); + const key = 'rsshub:koa-redis-cache:' + h64ToString(requestPath + format + limit); + const controlKey = 'rsshub:path-requested:' + h64ToString(requestPath + format + limit); const isRequesting = await cacheModule.globalCache.get(controlKey); diff --git a/lib/routes/bilibili/dynamic.ts b/lib/routes/bilibili/dynamic.ts index 9d4bb1f72..8a7cf4419 100644 --- a/lib/routes/bilibili/dynamic.ts +++ b/lib/routes/bilibili/dynamic.ts @@ -259,6 +259,7 @@ const getUrl = (item?: Item2, useAvid = false) => { }; async function handler(ctx) { + const isJsonFeed = ctx.req.query('format') === 'json'; const uid = ctx.req.param('uid'); const routeParams = Object.fromEntries(new URLSearchParams(ctx.req.param('routeParams'))); const showEmoji = fallback(undefined, queryToBoolean(routeParams.showEmoji), false); @@ -421,7 +422,7 @@ async function handler(ctx) { .filter(Boolean) .join('
'); - const subtitles = !config.bilibili.excludeSubtitles && bvid ? await cacheIn.getVideoSubtitleAttachment(bvid) : []; + const subtitles = isJsonFeed && !config.bilibili.excludeSubtitles && bvid ? await cacheIn.getVideoSubtitleAttachment(bvid) : []; return { title: title || originalDescription, diff --git a/lib/routes/bilibili/ranking.ts b/lib/routes/bilibili/ranking.ts index cf5e8be52..5cdcad699 100644 --- a/lib/routes/bilibili/ranking.ts +++ b/lib/routes/bilibili/ranking.ts @@ -185,6 +185,7 @@ function getAPI(ridIndex: number) { } async function handler(ctx) { + const isJsonFeed = ctx.req.query('format') === 'json'; const args = ctx.req.param(); if (args.redirect1 || args.redirect2) { // redirect old routes like /bilibili/ranking/0/3/1 or /bilibili/ranking/0/3/1/xxx @@ -216,7 +217,7 @@ async function handler(ctx) { link, item: await Promise.all( list.map(async (item) => { - const subtitles = !config.bilibili.excludeSubtitles && item.bvid ? await cache.getVideoSubtitleAttachment(item.bvid) : []; + const subtitles = isJsonFeed && !config.bilibili.excludeSubtitles && item.bvid ? await cache.getVideoSubtitleAttachment(item.bvid) : []; return { title: item.title, description: utils.renderUGCDescription(embed, item.pic, item.description || item.title, item.aid, undefined, item.bvid), diff --git a/lib/routes/bilibili/video.ts b/lib/routes/bilibili/video.ts index f149cb7cc..84108c47f 100644 --- a/lib/routes/bilibili/video.ts +++ b/lib/routes/bilibili/video.ts @@ -33,6 +33,8 @@ export const route: Route = { }; async function handler(ctx: Context) { + const isJsonFeed = ctx.req.query('format') === 'json'; + const uid = ctx.req.param('uid'); const embed = !ctx.req.param('embed'); const cookie = await cache.getCookie(); @@ -74,7 +76,7 @@ async function handler(ctx: Context) { data.data.list.vlist && (await Promise.all( data.data.list.vlist.map(async (item) => { - const subtitles = !config.bilibili.excludeSubtitles && item.bvid ? await cache.getVideoSubtitleAttachment(item.bvid) : []; + const subtitles = isJsonFeed && !config.bilibili.excludeSubtitles && item.bvid ? await cache.getVideoSubtitleAttachment(item.bvid) : []; return { title: item.title, description: utils.renderUGCDescription(embed, item.pic, item.description, item.aid, undefined, item.bvid), diff --git a/lib/routes/bilibili/weekly-recommend.ts b/lib/routes/bilibili/weekly-recommend.ts index 56756bc06..60484f501 100644 --- a/lib/routes/bilibili/weekly-recommend.ts +++ b/lib/routes/bilibili/weekly-recommend.ts @@ -24,6 +24,7 @@ export const route: Route = { }; async function handler(ctx) { + const isJsonFeed = ctx.req.query('format') === 'json'; const embed = !ctx.req.param('embed'); const status_response = await got({ @@ -50,7 +51,7 @@ async function handler(ctx) { link: 'https://www.bilibili.com/h5/weekly-recommend', description: 'B站每周必看', item: data.map(async (item) => { - const subtitles = !config.bilibili.excludeSubtitles && item.bvid ? await cache.getVideoSubtitleAttachment(item.bvid) : []; + const subtitles = isJsonFeed && !config.bilibili.excludeSubtitles && item.bvid ? await cache.getVideoSubtitleAttachment(item.bvid) : []; return { title: item.title, description: utils.renderUGCDescription(embed, item.cover, `${weekly_name} ${item.title} - ${item.rcmd_reason}`, item.param, undefined, item.bvid),