* feat(BOOK-609): Updated refs handling for assets inside content pages Approved-by: Linus Flood
90 lines
2.2 KiB
TypeScript
90 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,
|
|
url: z.string(),
|
|
}),
|
|
})
|
|
),
|
|
}),
|
|
})
|
|
|
|
export type Video = z.output<typeof transformedVideoSchema>
|
|
export type VideoCaptions = NonNullable<Video>["captions"]
|