fix(route/bilibili): duration for video route

This commit is contained in:
Stephen Zhou
2025-10-09 10:44:18 +08:00
parent b5623a8f11
commit f8c1415b8e
2 changed files with 6 additions and 1 deletions
+2
View File
@@ -1,5 +1,6 @@
import { Route, ViewType } from '@/types';
import got from '@/utils/got';
import { parseDuration } from '@/utils/helpers';
import logger from '@/utils/logger';
import type { Context } from 'hono';
import cache from './cache';
@@ -86,6 +87,7 @@ async function handler(ctx: Context) {
{
url: getVideoUrl(item.bvid),
mime_type: 'text/html',
duration_in_seconds: parseDuration(item.length),
},
...subtitles,
]
+4 -1
View File
@@ -46,7 +46,10 @@ export function getSearchParamsString(searchParams: any) {
* @param {string} timeStr - duration string like "01:01:01" / "01:01" / "59"
* @returns {number} - total seconds
*/
export function parseDuration(timeStr: string) {
export function parseDuration(timeStr: string | undefined | null): number | undefined {
if (!timeStr) {
return;
}
const clean = timeStr.trim().replaceAll(/[^\d:]/g, '');
return clean
.split(':')