fix: detect actual MIME type for save-logo extension instead of hardcoded png
This commit is contained in:
1 parent
a84cbfa4f0
commit
073f8e1b6a
1 file changed
+2
-1
@@ -13,7 +13,8 @@ export async function saveLogo(formData: FormData): Promise<{ success: boolean;
|
|||||||
const file = formData.get("file") as File | null;
|
const file = formData.get("file") as File | null;
|
||||||
if (!file) return { success: false, error: "No file provided" };
|
if (!file) return { success: false, error: "No file provided" };
|
||||||
|
|
||||||
const ext = "png";
|
const mimeExt: Record<string, string> = { "image/png": "png", "image/gif": "gif", "image/jpeg": "jpg", "image/webp": "webp" };
|
||||||
|
const ext = mimeExt[file.type] ?? "png";
|
||||||
const filename = `logo-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.${ext}`;
|
const filename = `logo-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.${ext}`;
|
||||||
const dir = path.join(process.cwd(), MEDIA_DIR);
|
const dir = path.join(process.cwd(), MEDIA_DIR);
|
||||||
const filePath = path.join(dir, filename);
|
const filePath = path.join(dir, filename);
|
||||||
|
|||||||
Reference in new issue
Block a user