feat:update form
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
export const MAX_FORM_ANSWER_IMAGE_BYTES = 50 * 1024 * 1024;
|
||||
|
||||
const ALLOWED_IMAGE_MIME_TYPES = new Set([
|
||||
"image/png",
|
||||
"image/jpeg",
|
||||
"image/webp",
|
||||
"image/gif",
|
||||
]);
|
||||
|
||||
const ALLOWED_IMAGE_EXTENSIONS = new Set(["png", "jpg", "jpeg", "webp", "gif"]);
|
||||
|
||||
export function validateImageUploadFile(file: Pick<File, "name" | "type" | "size">) {
|
||||
if (!ALLOWED_IMAGE_MIME_TYPES.has(file.type)) {
|
||||
throw new Error("Only PNG, JPG, WebP, and GIF images are allowed");
|
||||
}
|
||||
|
||||
if (file.size > MAX_FORM_ANSWER_IMAGE_BYTES) {
|
||||
throw new Error("Image must be 50MB or smaller");
|
||||
}
|
||||
|
||||
const extension = (file.name.split(".").pop() || "").toLowerCase();
|
||||
if (!ALLOWED_IMAGE_EXTENSIONS.has(extension)) {
|
||||
throw new Error("Invalid image extension");
|
||||
}
|
||||
}
|
||||
|
||||
export function cdnUrl(id: string | null | undefined) {
|
||||
return id ? `/cdn/${id}` : "";
|
||||
}
|
||||
Reference in New Issue
Block a user