fix(frontend): pass {size} param to fileSizeExceeded i18n on Nginx 413
The Nginx 413 error handler in request.ts calls t('error.fileSizeExceeded')
without the required {size} parameter, causing the toast to display
"文件大小不能超过 M!" instead of "文件大小不能超过 50M!".
Export MAX_FILE_SIZE_MB from utils/index.ts and pass it as {size} to the
i18n call, matching the sibling call site in kbFileTypeVerification().
This commit is contained in:
@@ -12,7 +12,7 @@ declare global {
|
|||||||
|
|
||||||
// 从运行时配置获取最大文件大小(MB),支持 Docker 环境动态配置
|
// 从运行时配置获取最大文件大小(MB),支持 Docker 环境动态配置
|
||||||
// 优先级:运行时配置 > 构建时环境变量 > 默认值 50MB
|
// 优先级:运行时配置 > 构建时环境变量 > 默认值 50MB
|
||||||
const MAX_FILE_SIZE_MB = window.__RUNTIME_CONFIG__?.MAX_FILE_SIZE_MB
|
export const MAX_FILE_SIZE_MB = window.__RUNTIME_CONFIG__?.MAX_FILE_SIZE_MB
|
||||||
|| Number(import.meta.env.VITE_MAX_FILE_SIZE_MB)
|
|| Number(import.meta.env.VITE_MAX_FILE_SIZE_MB)
|
||||||
|| 50;
|
|| 50;
|
||||||
const MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024;
|
const MAX_FILE_SIZE_BYTES = MAX_FILE_SIZE_MB * 1024 * 1024;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// src/utils/request.js
|
// src/utils/request.js
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { generateRandomString } from "./index";
|
import { generateRandomString, MAX_FILE_SIZE_MB } from "./index";
|
||||||
import i18n from '@/i18n'
|
import i18n from '@/i18n'
|
||||||
import { getApiBaseUrl } from './api-base';
|
import { getApiBaseUrl } from './api-base';
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ instance.interceptors.response.use(
|
|||||||
if (error.response.status === 413) {
|
if (error.response.status === 413) {
|
||||||
return Promise.reject({
|
return Promise.reject({
|
||||||
status: 413,
|
status: 413,
|
||||||
message: t('error.fileSizeExceeded'),
|
message: i18n.global.t('error.fileSizeExceeded', { size: MAX_FILE_SIZE_MB }),
|
||||||
success: false
|
success: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user