mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
chore: editor images
This commit is contained in:
@@ -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)
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user