From 5c899b4a5c2c07398151960b2b86d238b49d5bf4 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Sun, 26 Jul 2026 11:57:13 +0200 Subject: Better Strapi integration --- src/schemas/common.ts | 17 +++++++++++++++++ src/schemas/releases.ts | 7 ++++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/schemas/common.ts (limited to 'src/schemas') diff --git a/src/schemas/common.ts b/src/schemas/common.ts new file mode 100644 index 0000000..ef1fefd --- /dev/null +++ b/src/schemas/common.ts @@ -0,0 +1,17 @@ +import { fileAttributeSchema, imageAttributeSchema } from "$/deps/strapi.ts"; + +const publicUrl = Deno.env.get("STRAPI_PUBLIC_URL") ?? Deno.env.get("STRAPI_URL"); + +export const resolvedFileAttributeSchema = fileAttributeSchema.pipe( + ({ url, previewUrl, ...o }) => ({ + ...o, + url: new URL(url, publicUrl).href, + ...(previewUrl ? { previewUrl: new URL(previewUrl, publicUrl).href } : {}), + }), +); + +export const resolvedImageAttributeSchema = imageAttributeSchema.pipe((o) => ({ + ...o, + previewUrl: o.previewUrl ? new URL(o.previewUrl, publicUrl).href : undefined, + url: new URL(o.url, publicUrl).href, +})); diff --git a/src/schemas/releases.ts b/src/schemas/releases.ts index 0ccb6a6..529e8c9 100644 --- a/src/schemas/releases.ts +++ b/src/schemas/releases.ts @@ -1,13 +1,14 @@ import { type } from "arktype"; -import { nodeSchema } from "../deps/strapi.tsx"; -import { strapiLoader } from "../deps/strapi.tsx"; +import { resolvedFileAttributeSchema } from "$/schemas/common.ts"; + +import { nodeSchema } from "../deps/strapi.ts"; export const releaseStrapiSchema = type({ "version": "string", "date": "string.date.parse", "notes?": nodeSchema.array().or("null"), - "files": strapiLoader.resolvedFileAttributeSchema, + "files": resolvedFileAttributeSchema, }); export const releaseSchema = releaseStrapiSchema.merge({ -- cgit v1.3.1