diff options
Diffstat (limited to 'src/schemas/common.ts')
| -rw-r--r-- | src/schemas/common.ts | 17 |
1 files changed, 17 insertions, 0 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 | })); | ||
