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

This commit is contained in:
gsw945
2023-03-20 14:30:27 +08:00
parent 5f3b2fa1ef
commit 4cdafc80b4
4 changed files with 45 additions and 34 deletions

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...)