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 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/schemas/common.ts (limited to 'src/schemas/common.ts') 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, +})); -- cgit v1.3.1