songs page refactor schema
This commit is contained in:
@@ -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()),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user