songs remove complicated params that don't work

This commit is contained in:
2026-02-06 10:28:32 -08:00
parent 4b58d71b7c
commit 0faf98ee80
3 changed files with 30 additions and 149 deletions

View File

@@ -1,38 +1,9 @@
import { z } from "zod";
import { SongTypeMap } from "$lib/utils/amq";
// Base schema for raw URL search parameters as strings
const BaseSearchParamsSchema = z.object({
q: z.string().optional(),
artist: z.string().optional(),
anime: z.string().optional(),
gpm: z.string().optional(),
gpx: z.string().optional(),
cat: z.string().optional(),
export const SearchParamsSchema = z.object({
song: z.string().optional().default(""),
artist: z.string().optional().default(""),
anime: z.string().optional().default(""),
gpm: z.int().optional().default(0),
gpx: z.int().optional().default(100),
});
// Schema for +page.ts load function (parses comma-separated types into number array)
export const LoadSearchParamsSchema = BaseSearchParamsSchema.extend({
type: z
.string()
.optional()
.transform((s) => {
if (!s) return undefined;
return s
.split(",")
.map((t) => SongTypeMap[t.trim().toUpperCase()])
.filter((n) => n !== undefined);
}),
}).strict();
// Schema for +page.svelte useSearchParams (handles 'type' as an array of strings from URL)
export const SvelteSearchParamsSchema = BaseSearchParamsSchema.extend({
type: z.array(z.string()).default([]),
}).strict();
// Define the type for the Svelte form, which will have default values
export type SvelteSearchForm = z.infer<typeof SvelteSearchParamsSchema> & {
gpm: string; // To allow empty string in form input
gpx: string; // To allow empty string in form input
cat: string; // To allow empty string in form input
};