From d7fa14b4c50869cc7bccffd6d12fee072dda7055 Mon Sep 17 00:00:00 2001 From: Sara Vieira Date: Fri, 15 Jul 2022 23:09:42 +0200 Subject: [PATCH] more pr fixes --- apps/designer/app/routes/designer/$id.tsx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/apps/designer/app/routes/designer/$id.tsx b/apps/designer/app/routes/designer/$id.tsx index 3b91829e6f..03bcda0e65 100644 --- a/apps/designer/app/routes/designer/$id.tsx +++ b/apps/designer/app/routes/designer/$id.tsx @@ -10,7 +10,7 @@ import { Designer, links } from "~/designer"; import * as db from "~/shared/db"; import config from "~/config"; import env from "~/env.server"; - +import { z } from "zod"; export { links }; export const loader: LoaderFunction = async ({ params }) => { @@ -35,10 +35,11 @@ type Error = { errors: "string"; }; -type ImageUpload = { - type: string; - name: string; -}; +const ImageUpload = z.object({ + name: z.string(), + type: z.string(), +}); +type ImageUpload = z.infer; export const action: ActionFunction = async ({ request, params }) => { if (params.id === undefined) throw new Error("Project id undefined"); @@ -50,12 +51,15 @@ export const action: ActionFunction = async ({ request, params }) => { file: ({ filename }) => filename, }) ); - const imageInfo = formData.get("image") as ImageUpload; + const imageInfo = formData.get("image"); + ImageUpload.parse(imageInfo); + if (imageInfo) { + const info = imageInfo as ImageUpload; const data = { - type: imageInfo.type, - name: imageInfo.name, - path: `/uploads/${imageInfo.name}`, + type: info.type, + name: info.name, + path: `/uploads/${info.name}`, }; db.assets.create(params.id, data); }