fix: incorrect schema check for numbers

This commit is contained in:
alikia2x (寒寒) 2025-03-31 06:05:59 +08:00
parent 9c0783c607
commit aa75fdd63e
Signed by: alikia2x
GPG Key ID: 56209E0CCD8420C6
2 changed files with 7 additions and 6 deletions

View File

@ -17,4 +17,4 @@ export default {
fetch, fetch,
} satisfies Deno.ServeDefaultExport; } satisfies Deno.ServeDefaultExport;
export const VERSION = "0.2.1"; export const VERSION = "0.2.2";

View File

@ -6,9 +6,9 @@ import type { VideoSnapshotType } from "@core/db/schema.d.ts";
import { boolean, mixed, number, object, ValidationError } from "yup"; import { boolean, mixed, number, object, ValidationError } from "yup";
const SnapshotQueryParamsSchema = object({ const SnapshotQueryParamsSchema = object({
ps: number().optional().positive(), ps: number().integer().optional().positive(),
pn: number().optional().positive(), pn: number().integer().optional().positive(),
offset: number().optional().positive(), offset: number().integer().optional().positive(),
reverse: boolean().optional(), reverse: boolean().optional(),
}); });
@ -16,8 +16,9 @@ const idSchema = mixed().test(
"is-valid-id", "is-valid-id",
'id must be a string starting with "av" followed by digits, or "BV" followed by 10 alphanumeric characters, or a positive integer', 'id must be a string starting with "av" followed by digits, or "BV" followed by 10 alphanumeric characters, or a positive integer',
async (value) => { async (value) => {
if (value && await number().isValid(value)) { if (value && await number().integer().isValid(value)) {
return Number.isInteger(value) && (value as number) > 0; const v = parseInt(value as string);
return Number.isInteger(v) && v > 0;
} }
if (typeof value === "string") { if (typeof value === "string") {