feat: heic support

This commit is contained in:
Raul Lugo
2026-09-12 23:50:10 +02:00
parent b78d1ee094
commit 5aa35e7d18
18 changed files with 336 additions and 153 deletions
+26 -1
View File
@@ -1,8 +1,33 @@
import { z } from "zod"
export const allowedImageContentTypes = ["image/jpeg", "image/png", "image/webp"] as const
export const allowedImageContentTypes = [
"image/jpeg",
"image/png",
"image/webp",
"image/heic",
"image/heif",
] as const
export const allowedImageExtensions = [".jpg", ".jpeg", ".png", ".webp", ".heic", ".heif"] as const
export const maxUploadSizeBytes = 10 * 1024 * 1024
export type AllowedImageContentType = (typeof allowedImageContentTypes)[number]
export function getUploadContentType(file: File): AllowedImageContentType | null {
const type = file.type.toLowerCase()
if (type === "image/jpg") return "image/jpeg"
if (allowedImageContentTypes.includes(type as AllowedImageContentType)) {
return type as AllowedImageContentType
}
const extension = `.${file.name.split(".").pop()?.toLowerCase() ?? ""}`
if ([".jpg", ".jpeg"].includes(extension)) return "image/jpeg"
if (extension === ".png") return "image/png"
if (extension === ".webp") return "image/webp"
if (extension === ".heic") return "image/heic"
if (extension === ".heif") return "image/heif"
return null
}
export const presignUploadSchema = z.object({
token: z.string().min(1),
filename: z.string().trim().min(1).max(255),