All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 50s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import type {
|
|
CreatePlaylistRequest,
|
|
ReorderPlaylistRequest,
|
|
UpdatePlaylistRequest,
|
|
} from "../../shared/playlist.ts";
|
|
import { VALIDATION } from "../../shared/validation.ts";
|
|
|
|
export function isCreatePlaylistRequest(
|
|
obj: unknown,
|
|
): obj is CreatePlaylistRequest {
|
|
if (
|
|
!obj || typeof obj !== "object" ||
|
|
!("title" in obj) || typeof obj.title !== "string" ||
|
|
!("isPublic" in obj) || typeof obj.isPublic !== "boolean"
|
|
) return false;
|
|
const o = obj as Record<string, unknown>;
|
|
if (
|
|
(o.title as string).length === 0 ||
|
|
(o.title as string).length > VALIDATION.PLAYLIST_TITLE_MAX
|
|
) return false;
|
|
if (
|
|
"description" in o && typeof o.description !== "string" &&
|
|
o.description !== null
|
|
) return false;
|
|
if (
|
|
typeof o.description === "string" &&
|
|
(o.description as string).length > VALIDATION.PLAYLIST_DESCRIPTION_MAX
|
|
) return false;
|
|
return true;
|
|
}
|
|
|
|
export function isUpdatePlaylistRequest(
|
|
obj: unknown,
|
|
): obj is UpdatePlaylistRequest {
|
|
if (!obj || typeof obj !== "object") return false;
|
|
const o = obj as Record<string, unknown>;
|
|
if ("title" in o) {
|
|
if (typeof o.title !== "string") return false;
|
|
if (
|
|
(o.title as string).length === 0 ||
|
|
(o.title as string).length > VALIDATION.PLAYLIST_TITLE_MAX
|
|
) return false;
|
|
}
|
|
if (
|
|
"description" in o && typeof o.description !== "string" &&
|
|
o.description !== null
|
|
) return false;
|
|
if (
|
|
typeof o.description === "string" &&
|
|
(o.description as string).length > VALIDATION.PLAYLIST_DESCRIPTION_MAX
|
|
) return false;
|
|
if ("isPublic" in o && typeof o.isPublic !== "boolean") return false;
|
|
return true;
|
|
}
|
|
|
|
export function isReorderPlaylistRequest(
|
|
obj: unknown,
|
|
): obj is ReorderPlaylistRequest {
|
|
return !!obj && typeof obj === "object" &&
|
|
"dumpIds" in obj && Array.isArray(obj.dumpIds) &&
|
|
(obj.dumpIds as unknown[]).every((id) => typeof id === "string");
|
|
}
|