fix(route/bilibili): only get subtitle for jsonfeed (#20377)

* fix(route/bilibili): only get subtitle for jsonfeed

* Update lib/middleware/cache.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/middleware/cache.ts

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

---------
This commit is contained in:
Stephen Zhou
2025-10-29 15:32:20 +08:00
committed by GitHub
co-authored by Tony
parent cb1cf517c7
commit a0c5b08936
5 changed files with 12 additions and 6 deletions
+3 -2
View File
@@ -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);
+2 -1
View File
@@ -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('<br>');
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,
+2 -1
View File
@@ -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),
+3 -1
View File
@@ -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),
+2 -1
View File
@@ -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),