chore: editor images

This commit is contained in:
Aslam H
2024-10-30 04:08:59 +07:00
parent fa03facf64
commit 41743d6a22
12 changed files with 364 additions and 188 deletions

View File

@@ -1,15 +1,8 @@
import { getAuth } from "@clerk/tanstack-start/server"
import { createServerFn } from "@tanstack/start"
import { create } from "ronin"
import { create, drop } from "ronin"
import { z } from "zod"
const MAX_FILE_SIZE = 1 * 1024 * 1024
const ALLOWED_FILE_TYPES = [
"image/jpeg",
"image/png",
"image/gif",
"image/webp",
]
import { ALLOWED_FILE_TYPES, MAX_FILE_SIZE } from "./constants"
const ImageRuleSchema = z.object({
file: z
@@ -39,8 +32,23 @@ export const storeImageFn = createServerFn(
name: file.name,
type: file.type,
size: file.size,
width: data.get("width") ? Number(data.get("width")) : undefined,
height: data.get("height") ? Number(data.get("height")) : undefined,
})
return { fileModel }
},
)
export const deleteImageFn = createServerFn(
"POST",
async (data: { id: string }, { request }) => {
const auth = await getAuth(request)
if (!auth.userId) {
throw new Error("Unauthorized")
}
await drop.image.with.id(data.id)
},
)