upload base64 fix

This commit is contained in:
2025-11-10 11:24:50 +08:00
parent f79629e97e
commit 9c045f32ea
4 changed files with 53 additions and 5 deletions

View File

@@ -0,0 +1,42 @@
export function mimeToExtension(mimeType: string): string {
const map: Record<string, string> = {
"image/jpeg": "jpg",
"image/png": "png",
"image/gif": "gif",
"image/webp": "webp",
"image/svg+xml": "svg",
"image/bmp": "bmp",
"image/tiff": "tiff",
"video/mp4": "mp4",
"video/webm": "webm",
"video/ogg": "ogv",
"video/quicktime": "mov",
"audio/mpeg": "mp3",
"audio/wav": "wav",
"audio/ogg": "ogg",
"audio/webm": "weba",
"application/pdf": "pdf",
"application/zip": "zip",
"application/x-zip-compressed": "zip",
"application/json": "json",
"application/javascript": "js",
"application/x-httpd-php": "php",
"application/msword": "doc",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
"application/vnd.ms-excel": "xls",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
"application/vnd.ms-powerpoint": "ppt",
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
"text/plain": "txt",
"text/html": "html",
"text/css": "css",
"text/csv": "csv",
"text/xml": "xml",
};
return map[mimeType.toLowerCase()] || "bin"; // default jika tidak dikenal
}

View File

@@ -162,7 +162,7 @@ export async function uploadFile(config: Config, file: File): Promise<string> {
if (!res.ok) throw new Error(`Upload failed: ${text}`);
return `✅ Uploaded ${file.name} successfully`;
}
export async function uploadFileBase64(config: Config, base64File: { name: string; data: string }): Promise<string> {
export async function uploadFileBase64(config: Config, base64File: { name: string; data: string; }): Promise<string> {
const remoteName = path.basename(base64File.name);
// 1. Dapatkan upload link (pakai Authorization)