From c28cd05c0ca6994a49a83d173c542cf47527a3d7 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Thu, 23 Jul 2026 19:42:02 +0800 Subject: [PATCH] fix(models): align model debug upload limit with global MAX_FILE_SIZE Use the deploy-time file size configuration for model debugger uploads instead of a hardcoded 20 MB cap, and validate file size on the frontend before sending the request. --- frontend/src/components/ModelDebugDrawer.vue | 10 +++++++++- frontend/src/utils/index.ts | 19 +++++++++++-------- internal/handler/model.go | 17 ++++++++--------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/ModelDebugDrawer.vue b/frontend/src/components/ModelDebugDrawer.vue index 844155ba..45269904 100644 --- a/frontend/src/components/ModelDebugDrawer.vue +++ b/frontend/src/components/ModelDebugDrawer.vue @@ -197,6 +197,7 @@ import { MessagePlugin } from 'tdesign-vue-next' import { useI18n } from 'vue-i18n' import SettingDrawer from '@/components/settings/SettingDrawer.vue' import { debugModel, type ModelConfig, type ModelDebugResult } from '@/api/model' +import { fileSizeVerification } from '@/utils' import { modelSupportsThinking } from '@/utils/thinkingControl' const props = defineProps<{ @@ -389,7 +390,14 @@ const selectModelType = (type: DebugModelType) => { const onNativeFileChange = (event: Event) => { const target = event.target as HTMLInputElement - file.value = target.files?.[0] || null + const selectedFile = target.files?.[0] || null + if (selectedFile && fileSizeVerification(selectedFile)) { + target.value = '' + file.value = null + resetResult() + return + } + file.value = selectedFile resetResult() } diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index 814829b5..2cbca4ac 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -15,7 +15,7 @@ declare global { export const MAX_FILE_SIZE_MB = window.__RUNTIME_CONFIG__?.MAX_FILE_SIZE_MB || Number(import.meta.env.VITE_MAX_FILE_SIZE_MB) || 50; -const MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024; +export const MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024; export function generateRandomString(length: number) { let result = ""; @@ -42,6 +42,15 @@ export function formatStringDate(date: any) { } const DEFAULT_VALID_TYPES = new Set(["pdf", "txt", "md", "docx", "doc", "pptx", "ppt", "epub", "mhtml", "jpg", "jpeg", "png", "csv", "xlsx", "xls", "mp3", "wav", "m4a", "flac", "ogg"]); +/** Returns true when the file exceeds the deploy-time upload limit. */ +export function fileSizeVerification(file: Pick, silent = false) { + if (file.size <= MAX_FILE_SIZE_BYTES) return false; + if (!silent) { + MessagePlugin.error(i18n.global.t('error.fileSizeExceeded', { size: MAX_FILE_SIZE_MB })); + } + return true; +} + /** * Returns true when the file should be **rejected**. * @param validTypes - override the default extension whitelist with a dynamic set (e.g. from engine registry). @@ -61,11 +70,5 @@ export function kbFileTypeVerification(file: any, silent = false, validTypes?: S } return true; } - if (file.size > MAX_FILE_SIZE_BYTES) { - if (!silent) { - MessagePlugin.error(i18n.global.t('error.fileSizeExceeded', { size: MAX_FILE_SIZE_MB })); - } - return true; - } - return false; + return fileSizeVerification(file, silent); } diff --git a/internal/handler/model.go b/internal/handler/model.go index a91482ad..4f823389 100644 --- a/internal/handler/model.go +++ b/internal/handler/model.go @@ -205,10 +205,7 @@ func (h *ModelHandler) ListModels(c *gin.Context) { }) } -const ( - modelDebugMaxInputBytes = 64 * 1024 - modelDebugMaxFileBytes = 20 * 1024 * 1024 -) +const modelDebugMaxInputBytes = 64 * 1024 // ModelDebugOptions contains the cross-provider parameters exposed by the // model debugger. Pointer fields preserve explicit zero/false values. @@ -397,17 +394,19 @@ func (h *ModelHandler) DebugModel(c *gin.Context) { defer file.Close() fileName = header.Filename fileSize = header.Size - if fileSize > modelDebugMaxFileBytes { - c.Error(errors.NewBadRequestError("file cannot exceed 20 MB")) + maxFileBytes := secutils.GetMaxFileSize() + maxFileSizeMB := secutils.GetMaxFileSizeMB() + if fileSize > maxFileBytes { + c.Error(errors.NewBadRequestError(fmt.Sprintf("file cannot exceed %d MB", maxFileSizeMB))) return } - fileBytes, err = io.ReadAll(io.LimitReader(file, modelDebugMaxFileBytes+1)) + fileBytes, err = io.ReadAll(io.LimitReader(file, maxFileBytes+1)) if err != nil { c.Error(errors.NewBadRequestError("failed to read uploaded file")) return } - if len(fileBytes) > modelDebugMaxFileBytes { - c.Error(errors.NewBadRequestError("file cannot exceed 20 MB")) + if int64(len(fileBytes)) > maxFileBytes { + c.Error(errors.NewBadRequestError(fmt.Sprintf("file cannot exceed %d MB", maxFileSizeMB))) return } fileSize = int64(len(fileBytes))