Files
web/packages/trpc/lib/routers/contentstack/schemas/video.ts
Erik Tiekstra c21aa2dc73 Merged in fix/BOOK-257-video-player (pull request #3373)
Fix/BOOK-257 video player

* fix(BOOK-257): Fixes to VideoPlayerButton and added stories

* fix(BOOK-257): Hiding mute button when the user has interacted with it

* fix(BOOK-257): Added support for poster image

* fix(BOOK-257): add crossOrigin attr to videoplayer

* fix(BOOK-257): comment


Approved-by: Anton Gunnarsson
2025-12-19 12:41:00 +00:00

89 lines
2.2 KiB
TypeScript

import { z } from "zod"
import { Lang } from "@scandic-hotels/common/constants/language"
import { focalPointSchema } from "@scandic-hotels/common/utils/focalPoint"
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
import { assetSystemSchema } from "./system"
export const videoSchema = z.object({
sourceConnection: z.object({
edges: z.array(
z.object({
node: z.object({
url: z.string().url(),
content_type: z.string(),
}),
})
),
}),
poster_image: transformedImageVaultAssetSchema.nullish(),
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 sources =
video?.sourceConnection.edges.map((edge) => ({
src: edge.node.url,
type: edge.node.content_type,
})) || []
if (!video || !sources.length) {
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 {
sources,
poster: video.poster_image?.url
? {
src: video.poster_image.url,
dimensions: video.poster_image.dimensions,
}
: null,
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"]