Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(portal): 增加文件上传限制可配置功能 #524

Merged
merged 7 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/many-humans-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@scow/portal-web": minor
"@scow/demo-vagrant": minor
"@scow/gateway": minor
"@scow/deploy-compose": minor
---

上传文件、请求最大体积限制可配置
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ out
dist
version.json
.pnpm-store
.DS_Store
3 changes: 2 additions & 1 deletion apps/gateway/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { envConfig, str } from "@scow/lib-config";

export const config = envConfig({
RESOLVER: str({ desc: "DNS地址", default: "127.0.0.11" }),
CLIENT_MAX_BODY_SIZE: str({ desc: "请求文件大小限制", default: "1g" }),

CLIENT_MAX_BODY_SIZE: str({ desc: "请求文件大小限制", default: "1G" }),

BASE_PATH: str({ desc: "base path", default: "" }),

Expand Down
4 changes: 4 additions & 0 deletions apps/portal-web/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const specs = {
MIS_URL: str({ desc: "如果部署了管理系统,管理系统的URL。如果和本系统域名相同,可以只写完整的路径。将会覆盖配置文件。空字符串等价于未部署管理系统", default: "" }),

NOVNC_CLIENT_URL: str({ desc: "novnc客户端的URL。如果和本系统域名相同,可以只写完整路径", default: "/vnc" }),

CLIENT_MAX_BODY_SIZE: str({ desc: "限制整个系统上传(请求)文件的大小,可接受的格式为nginx的client_max_body_size可接受的值", default: "1G" }),
};

const mockEnv = process.env.NEXT_PUBLIC_USE_MOCK === "1";
Expand Down Expand Up @@ -143,6 +145,8 @@ const buildRuntimeConfig = async (phase, basePath) => {
PASSWORD_PATTERN_MESSAGE: commonConfig.passwordPattern?.errorMessage,

BASE_PATH: basePath,

CLIENT_MAX_BODY_SIZE: config.CLIENT_MAX_BODY_SIZE,
}

if (!building && !testenv) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { App, Button, Modal, Upload } from "antd";
import { join } from "path";
import { api } from "src/apis";
import { urlToUpload } from "src/pageComponents/filemanager/api";
import { publicConfig } from "src/utils/config";

interface Props {
open: boolean;
Expand Down Expand Up @@ -44,6 +45,9 @@ export const UploadModal: React.FC<Props> = ({ open, onClose, path, reload, clus
<p>
文件将会上传到:<strong>{path}</strong>。同名文件将会被覆盖。
</p>
<p>
单个上传文件大小最大为:<strong>{publicConfig.CLIENT_MAX_BODY_SIZE}</strong>。
</p>
<Upload.Dragger
name="file"
multiple
Expand Down
3 changes: 2 additions & 1 deletion apps/portal-web/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export interface PublicRuntimeConfig {
PASSWORD_PATTERN_MESSAGE: string | undefined;

BASE_PATH: string;

// 上传(请求)文件的大小限制
CLIENT_MAX_BODY_SIZE: string;
}

export const runtimeConfig: ServerRuntimeConfig = getConfig().serverRuntimeConfig;
Expand Down
7 changes: 7 additions & 0 deletions deploy/local/config-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
"IMAGE_TAG": "master",
}

# ------- 网关配置 -------
#
# GATEWAY.UPLOAD_FILE_SIZE_LIMIT:限制整个系统上传(请求)文件的大小,可接受的格式为nginx的client_max_body_size可接受的值,默认为1G
# GATEWAY = {
# "UPLOAD_FILE_SIZE_LIMIT": "1G",
# }

# ------- 日志配置 -------
#
# LOG.LEVEL: 日志等级,可选trace, debug, info, warn, error。默认info
Expand Down
5 changes: 5 additions & 0 deletions deploy/local/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def check_path_format(name, value):
LOG_LEVEL = get_cfg(["LOG", "LEVEL"], "info")
LOG_PRETTY = json.dumps(get_cfg(["LOG", "PRETTY"], False))

# 设置上传(请求)文件大小限制
CLIENT_MAX_BODY_SIZE = get_cfg(["GATEWAY", "UPLOAD_FILE_SIZE_LIMIT"], "1G")

# easy migration from IMAGE_BASE to IMAGE
SCOW_IMAGE = get_cfg(["COMMON", "IMAGE"])
if not SCOW_IMAGE:
Expand Down Expand Up @@ -186,6 +189,7 @@ def create_gateway_service():
"BASE_PATH": "" if BASE_PATH == "/" else BASE_PATH,
"PORTAL_PATH": PORTAL_PATH,
"MIS_PATH": MIS_PATH,
"CLIENT_MAX_BODY_SIZE": CLIENT_MAX_BODY_SIZE,
}

gateway = Service("gateway", SCOW_IMAGE_NAME, gw_ports, {
Expand Down Expand Up @@ -261,6 +265,7 @@ def create_portal_web_service():
"MIS_DEPLOYED": "false" if cfg.MIS == False else "true",
"AUTH_EXTERNAL_URL": path_join(BASE_PATH, "/auth"),
"NOVNC_CLIENT_URL": path_join(BASE_PATH, "/vnc"),
"CLIENT_MAX_BODY_SIZE": CLIENT_MAX_BODY_SIZE,
}
pw_volumes = {
"/etc/hosts": "/etc/hosts",
Expand Down
8 changes: 8 additions & 0 deletions deploy/vagrant/scow/scow-deployment/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
"IMAGE_TAG": "master",
}


# ------- 网关配置 -------
#
# GATEWAY.UPLOAD_FILE_SIZE_LIMIT:限制整个系统上传(请求)文件的大小,可接受的格式为nginx的client_max_body_size可接受的值,默认为1G
# GATEWAY = {
# "UPLOAD_FILE_SIZE_LIMIT": "1G",
# }

#
# ------- 门户系统 -------
#
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/refs/env/gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: "gateway"

| 名字 | 类型 | 描述 | 默认值 |
| -- | -- | -- | -- |
|`CLIENT_MAX_BODY_SIZE`|字符串|请求body最大大小,nginx的client_max_body_size配置|1g|
|`CLIENT_MAX_BODY_SIZE`|字符串|请求body最大大小,nginx的client_max_body_size配置,从配置项UPLOAD_FILE_SIZE_LIMIT获取|1G|
|`ACCESS_LOG`|字符串|nginx的access_log配置|/var/log/nginx/access.log|
|`ERROR_LOG`|字符串|nginx的error_log配置|/var/log/nginx/error.log|
|`EXTRA`|字符串|更多的配置,将会应用到server块里||
Expand Down