feat: heic support
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user