From 4141df7c08b36d7d74f5f010f221c2553b3f4598 Mon Sep 17 00:00:00 2001 From: Rogee Date: Thu, 22 Jan 2026 17:49:21 +0800 Subject: [PATCH] fix: normalize upload types --- frontend/portal/src/api/common.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/frontend/portal/src/api/common.js b/frontend/portal/src/api/common.js index 541ea94..98ad0ea 100644 --- a/frontend/portal/src/api/common.js +++ b/frontend/portal/src/api/common.js @@ -2,18 +2,35 @@ import { request } from "../utils/request"; import { getTenantCode } from "../utils/tenant"; export const commonApi = { + normalizeUploadType: (type, file) => { + const normalized = (type || "").toLowerCase(); + const mime = (file && file.type) || ""; + + if ( + normalized === "video" || + normalized === "audio" || + normalized === "image" + ) { + return normalized; + } + if (mime.startsWith("video/")) return "video"; + if (mime.startsWith("audio/")) return "audio"; + return "image"; + }, getOptions: () => request("/common/options"), checkHash: (hash) => request(`/upload/check?hash=${hash}`), deleteMedia: (id) => request(`/media-assets/${id}`, { method: "DELETE" }), upload: (file, type) => { + const normalizedType = commonApi.normalizeUploadType(type, file); const formData = new FormData(); formData.append("file", file); - formData.append("type", type); + formData.append("type", normalizedType); return request("/upload", { method: "POST", body: formData }); }, uploadMultipart: (file, hash, type, onProgress) => { const controller = new AbortController(); const signal = controller.signal; + const normalizedType = commonApi.normalizeUploadType(type, file); const promise = (async () => { // 1. Check Hash @@ -37,7 +54,7 @@ export const commonApi = { size: file.size, mime_type: file.type, hash: hash, - type: type, + type: normalizedType, }, signal, }); @@ -82,11 +99,12 @@ export const commonApi = { return { promise, abort: () => controller.abort() }; }, uploadWithProgress: (file, type, onProgress) => { + const normalizedType = commonApi.normalizeUploadType(type, file); let xhr; const promise = new Promise((resolve, reject) => { const formData = new FormData(); formData.append("file", file); - formData.append("type", type); + formData.append("type", normalizedType); xhr = new XMLHttpRequest(); const tenantCode = getTenantCode();