修复文件上传超过1GB报错的bug

pull/844/head
gsw945 2023-03-20 14:30:27 +08:00
parent 5f3b2fa1ef
commit 4cdafc80b4
4 changed files with 45 additions and 34 deletions

View File

@ -111,8 +111,8 @@ func RegisterModel() {
new(models.TeamMember),
new(models.TeamRelationship),
new(models.Itemsets),
new(models.Comment),
new(models.WorkWeixinAccount),
new(models.Comment),
new(models.WorkWeixinAccount),
)
gob.Register(models.Blog{})
gob.Register(models.Document{})
@ -207,7 +207,7 @@ func RegisterCommand() {
}
//注册模板函数
// 注册模板函数
func RegisterFunction() {
err := web.AddFuncMap("config", models.GetOptionValue)
@ -294,7 +294,7 @@ func RegisterFunction() {
}
}
//解析命令
// 解析命令
func ResolveCommand(args []string) {
flagSet := flag.NewFlagSet("MinDoc command: ", flag.ExitOnError)
flagSet.StringVar(&conf.ConfigurationFile, "config", "", "MinDoc configuration file.")
@ -343,6 +343,10 @@ func ResolveCommand(args []string) {
web.BConfig.WebConfig.StaticDir["/uploads"] = uploads
web.BConfig.WebConfig.ViewsPath = conf.WorkingDir("views")
web.BConfig.WebConfig.Session.SessionCookieSameSite = http.SameSiteDefaultMode
var upload_file_size = conf.GetUploadFileSize()
if upload_file_size > web.BConfig.MaxUploadSize {
web.BConfig.MaxUploadSize = upload_file_size
}
fonts := conf.WorkingDir("static", "fonts")
@ -362,7 +366,7 @@ func ResolveCommand(args []string) {
}
//注册缓存管道
// 注册缓存管道
func RegisterCache() {
isOpenCache := web.AppConfig.DefaultBool("cache", false)
if !isOpenCache {
@ -461,7 +465,7 @@ func RegisterCache() {
logs.Info("缓存初始化完成.")
}
//自动加载配置文件.修改了监听端口号和数据库配置无法自动生效.
// 自动加载配置文件.修改了监听端口号和数据库配置无法自动生效.
func RegisterAutoLoadConfig() {
if conf.AutoLoadDelay > 0 {
@ -502,7 +506,7 @@ func RegisterAutoLoadConfig() {
}
}
//注册错误处理方法.
// 注册错误处理方法.
func RegisterError() {
web.ErrorHandler("404", func(writer http.ResponseWriter, request *http.Request) {
var buf bytes.Buffer

View File

@ -77,7 +77,9 @@ token_size=12
#上传文件的后缀,如果不限制后缀可以设置为 *
upload_file_ext=txt|doc|docx|xls|xlsx|ppt|pptx|pdf|7z|rar|jpg|jpeg|png|gif
#上传的文件大小限制,如果不填写,默认不限制,单位可以是 GB KB MB
#上传的文件大小限制
# - 如果不填写, 则默认1GB如果希望超过1GB必须带单位
# - 如果填写,单位可以是 TB、GB、MB、KB不带单位表示字节
upload_file_size=10MB
####################邮件配置######################

View File

@ -19,7 +19,7 @@ const CaptchaSessionName = "__captcha__"
const RegexpEmail = "^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"
//允许用户名中出现点号
// 允许用户名中出现点号
const RegexpAccount = `^[a-zA-Z0-9][a-zA-Z0-9\.-]{2,50}$`
// PageSize 默认分页条数.
@ -35,7 +35,7 @@ const (
MemberGeneralRole
)
//系统角色
// 系统角色
type SystemRole int
const (
@ -51,7 +51,7 @@ const (
BookRoleNoSpecific
)
//项目角色
// 项目角色
type BookRole int
const (
@ -90,23 +90,23 @@ func GetDatabasePrefix() string {
return web.AppConfig.DefaultString("db_prefix", "md_")
}
//获取默认头像
// 获取默认头像
func GetDefaultAvatar() string {
return URLForWithCdnImage(web.AppConfig.DefaultString("avatar", "/static/images/headimgurl.jpg"))
}
//获取阅读令牌长度.
// 获取阅读令牌长度.
func GetTokenSize() int {
return web.AppConfig.DefaultInt("token_size", 12)
}
//获取默认文档封面.
// 获取默认文档封面.
func GetDefaultCover() string {
return URLForWithCdnImage(web.AppConfig.DefaultString("cover", "/static/images/book.jpg"))
}
//获取允许的商城文件的类型.
// 获取允许的商城文件的类型.
func GetUploadFileExt() []string {
ext := web.AppConfig.DefaultString("upload_file_ext", "png|jpg|jpeg|gif|txt|doc|docx|pdf")
@ -128,9 +128,9 @@ func GetUploadFileExt() []string {
func GetUploadFileSize() int64 {
size := web.AppConfig.DefaultString("upload_file_size", "0")
if strings.HasSuffix(size, "MB") {
if strings.HasSuffix(size, "TB") {
if s, e := strconv.ParseInt(size[0:len(size)-2], 10, 64); e == nil {
return s * 1024 * 1024
return s * 1024 * 1024 * 1024 * 1024
}
}
if strings.HasSuffix(size, "GB") {
@ -138,28 +138,33 @@ func GetUploadFileSize() int64 {
return s * 1024 * 1024 * 1024
}
}
if strings.HasSuffix(size, "MB") {
if s, e := strconv.ParseInt(size[0:len(size)-2], 10, 64); e == nil {
return s * 1024 * 1024
}
}
if strings.HasSuffix(size, "KB") {
if s, e := strconv.ParseInt(size[0:len(size)-2], 10, 64); e == nil {
return s * 1024
}
}
if s, e := strconv.ParseInt(size, 10, 64); e == nil {
return s * 1024
return s
}
return 0
}
//是否启用导出
// 是否启用导出
func GetEnableExport() bool {
return web.AppConfig.DefaultBool("enable_export", true)
}
//是否启用iframe
// 是否启用iframe
func GetEnableIframe() bool {
return web.AppConfig.DefaultBool("enable_iframe", false)
}
//同一项目导出线程的并发数
// 同一项目导出线程的并发数
func GetExportProcessNum() int {
exportProcessNum := web.AppConfig.DefaultInt("export_process_num", 1)
@ -169,7 +174,7 @@ func GetExportProcessNum() int {
return exportProcessNum
}
//导出项目队列的并发数量
// 导出项目队列的并发数量
func GetExportLimitNum() int {
exportLimitNum := web.AppConfig.DefaultInt("export_limit_num", 1)
@ -179,7 +184,7 @@ func GetExportLimitNum() int {
return exportLimitNum
}
//等待导出队列的长度
// 等待导出队列的长度
func GetExportQueueLimitNum() int {
exportQueueLimitNum := web.AppConfig.DefaultInt("export_queue_limit_num", 10)
@ -189,14 +194,14 @@ func GetExportQueueLimitNum() int {
return exportQueueLimitNum
}
//默认导出项目的缓存目录
// 默认导出项目的缓存目录
func GetExportOutputPath() string {
exportOutputPath := filepath.Join(web.AppConfig.DefaultString("export_output_path", filepath.Join(WorkingDirectory, "cache")), "books")
return exportOutputPath
}
//判断是否是允许商城的文件类型.
// 判断是否是允许商城的文件类型.
func IsAllowUploadFileExt(ext string) bool {
if strings.HasPrefix(ext, ".") {
@ -215,7 +220,7 @@ func IsAllowUploadFileExt(ext string) bool {
return false
}
//读取配置文件值
// 读取配置文件值
func CONF(key string, value ...string) string {
defaultValue := ""
if len(value) > 0 {
@ -224,7 +229,7 @@ func CONF(key string, value ...string) string {
return web.AppConfig.DefaultString(key, defaultValue)
}
//重写生成URL的方法加上完整的域名
// 重写生成URL的方法加上完整的域名
func URLFor(endpoint string, values ...interface{}) string {
baseUrl := web.AppConfig.DefaultString("baseurl", "")
pathUrl := web.URLFor(endpoint, values...)

View File

@ -34,7 +34,7 @@ func (c *BlogController) Prepare() {
}
}
//文章阅读
// 文章阅读
func (c *BlogController) Index() {
c.Prepare()
c.TplName = "blog/index.tpl"
@ -98,7 +98,7 @@ func (c *BlogController) Index() {
}
}
//文章列表
// 文章列表
func (c *BlogController) List() {
c.Prepare()
c.TplName = "blog/list.tpl"
@ -130,7 +130,7 @@ func (c *BlogController) List() {
c.Data["Lists"] = blogList
}
//管理后台文章列表
// 管理后台文章列表
func (c *BlogController) ManageList() {
c.Prepare()
c.TplName = "blog/manage_list.tpl"
@ -153,7 +153,7 @@ func (c *BlogController) ManageList() {
}
//文章设置
// 文章设置
func (c *BlogController) ManageSetting() {
c.Prepare()
c.TplName = "blog/manage_setting.tpl"
@ -290,7 +290,7 @@ func (c *BlogController) ManageSetting() {
}
}
//文章创建或编辑
// 文章创建或编辑
func (c *BlogController) ManageEdit() {
c.Prepare()
c.TplName = "blog/manage_edit.tpl"
@ -403,7 +403,7 @@ func (c *BlogController) ManageEdit() {
c.Data["Model"] = blog
}
//删除文章
// 删除文章
func (c *BlogController) ManageDelete() {
c.Prepare()
blogId, _ := c.GetInt("blog_id", 0)
@ -624,7 +624,7 @@ func (c *BlogController) RemoveAttachment() {
c.JsonResult(0, "ok", attach)
}
//下载附件
// 下载附件
func (c *BlogController) Download() {
c.Prepare()