From cf33c4922d39f43d57b7df48b703ce3b27c7683f Mon Sep 17 00:00:00 2001 From: alikia2x Date: Mon, 31 Mar 2025 06:09:28 +0800 Subject: [PATCH] fix: incorrect parsing for id in API route /video/:id/snapshots --- packages/backend/snapshots.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/backend/snapshots.ts b/packages/backend/snapshots.ts index 6be9d70..952e290 100644 --- a/packages/backend/snapshots.ts +++ b/packages/backend/snapshots.ts @@ -43,10 +43,13 @@ export const getSnapshotsHanlder = createHandlers(async (c: ContextType) => { try { const idParam = await idSchema.validate(c.req.param("id")); - let videoId: number | string = idParam as string | number; - if (typeof videoId === "string" && videoId.startsWith("av")) { - videoId = videoId.slice(2); + let videoId: string | number = idParam as string; + if (videoId.startsWith("av")) { + videoId = parseInt(videoId.slice(2)); } + else if (await number().validate(videoId)) { + videoId = parseInt(videoId); + } const queryParams = await SnapshotQueryParamsSchema.validate(c.req.query()); const { ps, pn, offset, reverse = false } = queryParams;