diff options
| author | Volpeon <git@volpeon.ink> | 2026-07-26 11:57:13 +0200 |
|---|---|---|
| committer | Volpeon <git@volpeon.ink> | 2026-07-26 11:57:13 +0200 |
| commit | 5c899b4a5c2c07398151960b2b86d238b49d5bf4 (patch) | |
| tree | ccc743f27ba234a25396cb24b6124c139d13b027 /src/schemas | |
| parent | Use Corvos 0.1.4 (diff) | |
| download | corvos-website-5c899b4a5c2c07398151960b2b86d238b49d5bf4.tar.gz corvos-website-5c899b4a5c2c07398151960b2b86d238b49d5bf4.tar.bz2 corvos-website-5c899b4a5c2c07398151960b2b86d238b49d5bf4.zip | |
Diffstat (limited to 'src/schemas')
| -rw-r--r-- | src/schemas/common.ts | 17 | ||||
| -rw-r--r-- | src/schemas/releases.ts | 7 |
2 files changed, 21 insertions, 3 deletions
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 @@ | |||
| 1 | import { fileAttributeSchema, imageAttributeSchema } from "$/deps/strapi.ts"; | ||
| 2 | |||
| 3 | const publicUrl = Deno.env.get("STRAPI_PUBLIC_URL") ?? Deno.env.get("STRAPI_URL"); | ||
| 4 | |||
| 5 | export const resolvedFileAttributeSchema = fileAttributeSchema.pipe( | ||
| 6 | ({ url, previewUrl, ...o }) => ({ | ||
| 7 | ...o, | ||
| 8 | url: new URL(url, publicUrl).href, | ||
| 9 | ...(previewUrl ? { previewUrl: new URL(previewUrl, publicUrl).href } : {}), | ||
| 10 | }), | ||
| 11 | ); | ||
| 12 | |||
| 13 | export const resolvedImageAttributeSchema = imageAttributeSchema.pipe((o) => ({ | ||
| 14 | ...o, | ||
| 15 | previewUrl: o.previewUrl ? new URL(o.previewUrl, publicUrl).href : undefined, | ||
| 16 | url: new URL(o.url, publicUrl).href, | ||
| 17 | })); | ||
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 @@ | |||
| 1 | import { type } from "arktype"; | 1 | import { type } from "arktype"; |
| 2 | 2 | ||
| 3 | import { nodeSchema } from "../deps/strapi.tsx"; | 3 | import { resolvedFileAttributeSchema } from "$/schemas/common.ts"; |
| 4 | import { strapiLoader } from "../deps/strapi.tsx"; | 4 | |
| 5 | import { nodeSchema } from "../deps/strapi.ts"; | ||
| 5 | 6 | ||
| 6 | export const releaseStrapiSchema = type({ | 7 | export const releaseStrapiSchema = type({ |
| 7 | "version": "string", | 8 | "version": "string", |
| 8 | "date": "string.date.parse", | 9 | "date": "string.date.parse", |
| 9 | "notes?": nodeSchema.array().or("null"), | 10 | "notes?": nodeSchema.array().or("null"), |
| 10 | "files": strapiLoader.resolvedFileAttributeSchema, | 11 | "files": resolvedFileAttributeSchema, |
| 11 | }); | 12 | }); |
| 12 | 13 | ||
| 13 | export const releaseSchema = releaseStrapiSchema.merge({ | 14 | export const releaseSchema = releaseStrapiSchema.merge({ |
