songs page refactor schema

This commit is contained in:
2026-02-06 08:51:01 -08:00
parent 0531a1f5c0
commit 4b58d71b7c
3 changed files with 44 additions and 63 deletions

View File

@@ -1,47 +1,12 @@
import { z } from "zod";
import type { SongFilters } from "$lib/db/client-db";
import { db, ensureSeeded, getSongsWithFilters } from "$lib/db/client-db";
import {
SongCategoryMap,
SongTypeMap,
SongTypeReverseMap,
} from "$lib/utils/amq";
import type { PageLoad } from "./$types";
const SearchSchema = z
.object({
q: z.string().optional(), // song name
artist: z.string().optional(), // artist name
anime: z.string().optional(), // anime mainName
type: z
.string()
.optional()
.transform((s) => {
if (!s) return undefined;
return s
.split(",")
.map((t) => SongTypeMap[t.trim().toUpperCase()])
.filter((n) => n !== undefined);
}),
gpm: z
.string()
.optional()
.transform((s) => (s ? parseInt(s, 10) : undefined)), // global percent min
gpx: z
.string()
.optional()
.transform((s) => (s ? parseInt(s, 10) : undefined)), // global percent max
cat: z
.string()
.optional()
.transform((s) => (s ? parseInt(s, 10) : undefined)), // category
})
.strict();
import { LoadSearchParamsSchema } from "./schema";
export const load: PageLoad = async ({ url, fetch, depends }) => {
depends("clientdb:songs");
const parsed = SearchSchema.safeParse(
const parsed = LoadSearchParamsSchema.safeParse(
Object.fromEntries(url.searchParams.entries()),
);