feat: vite文件大小限制
This commit is contained in:
+4
-1
@@ -1,7 +1,10 @@
|
|||||||
services:
|
services:
|
||||||
frontend:
|
frontend:
|
||||||
image: wechatopenai/weknora-ui:latest
|
image: wechatopenai/weknora-ui:latest
|
||||||
build: ./frontend
|
build:
|
||||||
|
context: ./frontend
|
||||||
|
args:
|
||||||
|
- MAX_FILE_SIZE_MB=${MAX_FILE_SIZE_MB:-50}
|
||||||
container_name: WeKnora-frontend
|
container_name: WeKnora-frontend
|
||||||
ports:
|
ports:
|
||||||
- "${FRONTEND_PORT:-80}:80"
|
- "${FRONTEND_PORT:-80}:80"
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ WORKDIR /app
|
|||||||
ENV NODE_OPTIONS="--max-old-space-size=4096"
|
ENV NODE_OPTIONS="--max-old-space-size=4096"
|
||||||
ENV VITE_IS_DOCKER=true
|
ENV VITE_IS_DOCKER=true
|
||||||
|
|
||||||
|
# 文件大小限制(MB),通过构建参数传入
|
||||||
|
ARG MAX_FILE_SIZE_MB=50
|
||||||
|
ENV VITE_MAX_FILE_SIZE_MB=${MAX_FILE_SIZE_MB}
|
||||||
|
|
||||||
# 复制依赖文件
|
# 复制依赖文件
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
COPY packages/xlsx-0.20.2.tgz ./packages/xlsx-0.20.2.tgz
|
COPY packages/xlsx-0.20.2.tgz ./packages/xlsx-0.20.2.tgz
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
import { MessagePlugin } from "tdesign-vue-next";
|
import { MessagePlugin } from "tdesign-vue-next";
|
||||||
|
|
||||||
|
// 从环境变量获取最大文件大小(MB),默认30MB
|
||||||
|
const 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 function generateRandomString(length: number) {
|
export function generateRandomString(length: number) {
|
||||||
let result = "";
|
let result = "";
|
||||||
const characters =
|
const characters =
|
||||||
@@ -33,16 +38,16 @@ export function kbFileTypeVerification(file: any, silent = false) {
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
(type == "pdf" || type == "docx" || type == "doc") &&
|
(type == "pdf" || type == "docx" || type == "doc") &&
|
||||||
file.size > 31457280
|
file.size > MAX_FILE_SIZE_BYTES
|
||||||
) {
|
) {
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
MessagePlugin.error("pdf/doc文件不能超过30M!");
|
MessagePlugin.error(`pdf/doc文件不能超过${MAX_FILE_SIZE_MB}M!`);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((type == "txt" || type == "md") && file.size > 31457280) {
|
if ((type == "txt" || type == "md") && file.size > MAX_FILE_SIZE_BYTES) {
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
MessagePlugin.error("txt/md文件不能超过30M!");
|
MessagePlugin.error(`txt/md文件不能超过${MAX_FILE_SIZE_MB}M!`);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user