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.
This commit is contained in:
wizardchen
2026-07-23 19:42:02 +08:00
committed by lyingbug
parent b2ae22c4eb
commit c28cd05c0c
3 changed files with 28 additions and 18 deletions
+9 -1
View File
@@ -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()
}
+11 -8
View File
@@ -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<File, 'size'>, 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);
}
+8 -9
View File
@@ -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))