From e8ca476d90221c8c8c9be2841af5fca712f61ae2 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sun, 8 Nov 2026 12:10:59 +0200 Subject: [PATCH] Replace the never-run videoSchema validator with a plain VideoBeingAdded type --- app/features/vods/vods-schemas.ts | 77 +------------------------------ app/features/vods/vods-types.ts | 25 ++++++++-- 2 files changed, 22 insertions(+), 80 deletions(-) diff --git a/app/features/vods/vods-schemas.ts b/app/features/vods/vods-schemas.ts index de34b1644..77e485336 100644 --- a/app/features/vods/vods-schemas.ts +++ b/app/features/vods/vods-schemas.ts @@ -15,87 +15,12 @@ import { weaponSelectOptional, } from "~/form/fields"; import { modesShort } from "~/modules/in-game-lists/modes"; -import { - dayMonthYear, - id, - modeShort, - nonEmptyString, - preprocess, - stageId, - weaponSplId, -} from "~/utils/schema"; -import { dayMonthYearToDate } from "../../utils/dates"; +import { id, nonEmptyString } from "~/utils/schema"; import { videoMatchTypes } from "./vods-constants"; import { extractYoutubeIdFromVideoUrl } from "./vods-utils"; export const HOURS_MINUTES_SECONDS_REGEX = /^(\d{1,2}:)?\d{1,2}:\d{2}$/; -const videoMatchSchema = v.object({ - startsAt: v.pipe( - v.string(), - v.regex( - HOURS_MINUTES_SECONDS_REGEX, - "Invalid time format. Use HH:MM:SS or MM:SS", - ), - ), - stageId, - mode: modeShort, - weapons: v.array(weaponSplId), -}); - -export const videoSchema = preprocess( - (val: any) => (val.type === "CAST" ? { ...val, pov: undefined } : val), - v.pipe( - v.object({ - type: v.picklist(videoMatchTypes), - eventId: v.optional(v.number()), - youtubeUrl: v.pipe( - v.string(), - v.check((val) => { - const videoId = extractYoutubeIdFromVideoUrl(val); - - return videoId !== null; - }, "Invalid YouTube URL"), - ), - title: v.pipe(nonEmptyString, v.maxLength(100)), - date: v.pipe( - dayMonthYear, - v.check((data) => { - const date = dayMonthYearToDate(data); - - return date < add(new Date(), { days: 1 }); - }, "Date must not be in the future"), - ), - pov: v.optional( - v.union([ - v.object({ - type: v.literal("USER"), - userId: id, - }), - v.object({ - type: v.literal("NAME"), - name: v.pipe(nonEmptyString, v.maxLength(100)), - }), - ]), - ), - teamSize: v.optional( - v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(4)), - ), - matches: v.array(videoMatchSchema), - }), - v.check((data) => { - if (data.type === "CAST") { - const teamSize = data.teamSize ?? 4; - return data.matches.every( - (match) => match.weapons.length === teamSize * 2, - ); - } - - return data.matches.every((match) => match.weapons.length === 1); - }), - ), -); - const povSchema = v.union([ v.object({ type: v.literal("USER"), diff --git a/app/features/vods/vods-types.ts b/app/features/vods/vods-types.ts index 604af23db..8d7a6ae7c 100644 --- a/app/features/vods/vods-types.ts +++ b/app/features/vods/vods-types.ts @@ -1,10 +1,27 @@ -import type * as v from "valibot"; import type { Tables } from "~/db/tables"; -import type { MainWeaponId } from "~/modules/in-game-lists/types"; +import type { + MainWeaponId, + ModeShort, + StageId, +} from "~/modules/in-game-lists/types"; import type { CommonUser } from "~/utils/kysely.server"; -import type { videoSchema } from "./vods-schemas"; +import type { DayMonthYear } from "~/utils/schema"; -export type VideoBeingAdded = v.InferOutput; +export interface VideoBeingAdded { + type: Tables["Video"]["type"]; + eventId?: number; + youtubeUrl: string; + title: string; + date: DayMonthYear; + pov?: { type: "USER"; userId: number } | { type: "NAME"; name: string }; + teamSize?: number; + matches: Array<{ + startsAt: string; + stageId: StageId; + mode: ModeShort; + weapons: MainWeaponId[]; + }>; +} export interface Vod { id: Tables["Video"]["id"];