Skip to content

Commit

Permalink
feat(portal): 增加文件上传限制可配置功能 (#524)
Browse files Browse the repository at this point in the history
用户部署配置:
修改scow-deployment/config.py文件中的网关配置,取消对GATEWAY
的注释,修改UPLOAD_FILE_SIZE_LIMIT的值,如将默认的1G改为50M:
```py
# ------- 网关配置 -------
#
# GATEWAY.UPLOAD_FILE_SIZE_LIMIT:限制整个系统上传(请求)文件的大小,可接受的格式为nginx的client_max_body_size可接受的值,默认为1G
# GATEWAY = {
#   "UPLOAD_FILE_SIZE_LIMIT": "1G",
# }

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




PR合并前测试步骤,用户部署无需关注:
1、与正常流程一样拉取镜像
2、修改scow-deployment
下的config.py文件,参照用户部署配置,可将UPLOAD_FILE_SIZE_LIMIT的值改为其它值,例如5M。
3、PR未被合并前,还需要修改scow-deployment
下的generate.py,增加了对UPLOAD_FILE_SIZE_LIMIT的配置,具体参考此PR对deploy/local/generate.py文件的修改,复制即可。
4、进入文件管理,点击文件上传,展示了文件上传的最大限制。尝试上传1个10M的文件,失败


![image](https://user-images.githubusercontent.com/25954437/227121002-df50b29a-c65c-48cb-89ff-138a9c6b899a.png)
  • Loading branch information
tongchong authored Mar 28, 2023
1 parent 613c26e commit 523b4f8
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 3 deletions.
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

0 comments on commit 523b4f8

Please sign in to comment.