f06e466827
Approved-by: Chuma Mcphoy (We Ahead) Approved-by: Christel Westerberg
76 lines
1.7 KiB
TypeScript
76 lines
1.7 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { Lang } from "@scandic-hotels/common/constants/language"
|
|
import { focalPointSchema } from "@scandic-hotels/common/utils/focalPoint"
|
|
|
|
import { assetSystemSchema } from "./system"
|
|
|
|
export const videoSchema = z.object({
|
|
sourceConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: z.object({
|
|
url: z.string().url(),
|
|
}),
|
|
})
|
|
),
|
|
}),
|
|
focal_point: focalPointSchema.nullish(),
|
|
captions: z.array(
|
|
z.object({
|
|
is_default: z.boolean(),
|
|
fileConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: z.object({
|
|
url: z.string().url(),
|
|
}),
|
|
})
|
|
),
|
|
}),
|
|
language: z.nativeEnum(Lang),
|
|
})
|
|
),
|
|
})
|
|
|
|
export const transformedVideoSchema = videoSchema
|
|
.nullish()
|
|
.transform((video) => {
|
|
const src = video?.sourceConnection.edges[0]?.node.url || ""
|
|
|
|
if (!video || !src) {
|
|
return null
|
|
}
|
|
|
|
const captions = video.captions
|
|
.filter((caption) => caption.fileConnection.edges[0]?.node.url)
|
|
.map((caption) => ({
|
|
src: caption.fileConnection.edges[0]?.node.url || "",
|
|
srcLang: caption.language,
|
|
isDefault: caption.is_default,
|
|
}))
|
|
|
|
return {
|
|
src,
|
|
focalPoint: video.focal_point
|
|
? { x: video.focal_point.x, y: video.focal_point.y }
|
|
: { x: 50, y: 50 },
|
|
captions,
|
|
}
|
|
})
|
|
|
|
export const videoRefSchema = z.object({
|
|
sourceConnection: z.object({
|
|
edges: z.array(
|
|
z.object({
|
|
node: z.object({
|
|
system: assetSystemSchema,
|
|
}),
|
|
})
|
|
),
|
|
}),
|
|
})
|
|
|
|
export type Video = z.output<typeof transformedVideoSchema>
|
|
export type VideoCaptions = NonNullable<Video>["captions"]
|