上传控制

dev
truthhun 2 years ago
parent 69a242bab5
commit c7eec0e04c

@ -71,6 +71,7 @@ message ConfigSecurity {
bool enable_captcha_comment = 6;
bool enable_captcha_find_password = 7;
bool enable_captcha_upload = 8;
int32 max_document_size = 9;
}
message Settings {

@ -88,13 +88,19 @@ func (s *ConfigAPIService) GetSettings(ctx context.Context, req *emptypb.Empty)
// util.CopyStruct(&captcha, res.Captcha)
system := s.dbModel.GetConfigOfSystem()
util.CopyStruct(&system, res.System)
if err := util.CopyStruct(&system, res.System); err != nil {
s.logger.Error("util.CopyStruct", zap.Any("system", system), zap.Any("res.System", res.System), zap.Error(err))
}
footer := s.dbModel.GetConfigOfFooter()
util.CopyStruct(&footer, res.Footer)
if err := util.CopyStruct(&footer, res.Footer); err != nil {
s.logger.Error("util.CopyStruct", zap.Any("footer", footer), zap.Any("res.Footer", res.Footer), zap.Error(err))
}
security := s.dbModel.GetConfigOfSecurity()
util.CopyStruct(&security, res.Security)
if err := util.CopyStruct(&security, res.Security); err != nil {
s.logger.Error("util.CopyStruct", zap.Any("security", security), zap.Any("res.Security", res.Security), zap.Error(err))
}
return res, nil
}

@ -253,6 +253,7 @@ func (m *DBModel) GetConfigOfSystem() (config ConfigSystem) {
}
const (
ConfigSecurityMaxDocumentSize = "max_document_size" // 是否关闭注册
ConfigSecurityIsClose = "is_close" // 是否关闭注册
ConfigSecurityCloseStatement = "close_statement" // 闭站说明
ConfigSecurityEnableRegister = "enable_register" // 是否允许注册
@ -263,6 +264,7 @@ const (
)
type ConfigSecurity struct {
MaxDocumentSize int32 `json:"max_document_size"` // 允许上传的最大文档大小
IsClose bool `json:"is_close"` // 是否闭站
CloseStatement string `json:"close_statement"` // 闭站说明
EnableRegister bool `json:"enable_register"` // 是否启用注册
@ -291,6 +293,8 @@ func (m *DBModel) GetConfigOfSecurity(name ...string) (config ConfigSecurity) {
case "is_close", "enable_register", "enable_captcha_login", "enable_captcha_register", "enable_captcha_comment", "enable_captcha_find_password", "enable_captcha_upload":
value, _ := strconv.ParseBool(cfg.Value)
data[cfg.Name] = value
case "max_document_size":
data[cfg.Name], _ = strconv.Atoi(cfg.Value)
default:
data[cfg.Name] = cfg.Value
}
@ -359,6 +363,7 @@ func (m *DBModel) initConfig() (err error) {
{Category: ConfigCategoryCaptcha, Name: ConfigCaptchaType, Label: "验证码类型", Value: "digit", Placeholder: "请选择验证码类型,默认为数字", InputType: "select", Sort: 16, Options: captcha.CaptchaTypeOptions},
// 安全配置项
{Category: ConfigCategorySecurity, Name: ConfigSecurityMaxDocumentSize, Label: "最大文档大小(MB)", Value: "50", Placeholder: "允许用户上传的最大文档大小默认为50即50MB", InputType: "number", Sort: 15, Options: ""},
{Category: ConfigCategorySecurity, Name: ConfigSecurityIsClose, Label: "是否关闭网站", Value: "false", Placeholder: "请选择是否关闭网站", InputType: "switch", Sort: 16, Options: ""},
{Category: ConfigCategorySecurity, Name: ConfigSecurityCloseStatement, Label: "闭站说明", Value: "false", Placeholder: "关闭网站后,页面提示的内容", InputType: "textarea", Sort: 17, Options: ""},
{Category: ConfigCategorySecurity, Name: ConfigSecurityEnableRegister, Label: "是否允许注册", Value: "true", Placeholder: "请选择是否允许用户注册", InputType: "switch", Sort: 18, Options: ""},

@ -1,5 +1,12 @@
<template>
<div class="com-form-group-permission">
<el-alert
title="风险提示:当前权限仅针对管理组,普通用户不需要设置此授权!"
show-icon
type="warning"
:closable="false"
>
</el-alert>
<el-form label-position="top" label-width="80px" :model="groupPermission">
<el-form-item>
<el-checkbox

@ -168,7 +168,11 @@
<!-- 应该从管理后台的配置中查询 -->
2. 允许上传的最大单个文档大小为<span
class="el-link el-link--primary"
>50.00 MB</span
>{{
settings.security.max_document_size.toFixed(2) ||
'50.00'
}}
MB</span
>
</li>
@ -250,6 +254,7 @@ export default {
price: 0,
overwrite: false,
},
maxDocumentSize: 50 * 1024 * 1024,
fileList: [],
filesMap: {},
loading: false,
@ -287,19 +292,27 @@ export default {
},
computed: {
...mapGetters('category', ['categoryTrees']),
...mapGetters('setting', ['settings']),
},
async created() {
const res = await canIUploadDocument()
if (res.status === 200) {
this.canIUploadDocument = true
}
this.maxDocumentSize =
(this.settings.security.max_document_size || 50) * 1024 * 1024
},
methods: {
formatBytes,
handleChange(file) {
const name = file.name.toLowerCase()
const ext = file.name.substring(file.name.lastIndexOf('.')).toLowerCase()
if (!this.filesMap[name] && this.allowExt.includes(ext)) {
//
if (
!this.filesMap[name] &&
this.allowExt.includes(ext) &&
file.size <= this.maxDocumentSize
) {
const item = {
...file,
title: file.name.substring(0, file.name.lastIndexOf('.')),

@ -2,7 +2,11 @@ import { getSettings } from '~/api/config'
export const setting = {
namespaced: true,
state: {
settings: {},
settings: {
system: {},
footer: {},
security: {},
},
},
mutations: {
setSettings(state, settings) {

Loading…
Cancel
Save