mirror of https://github.com/mindoc-org/mindoc.git
修复文件上传超过1GB报错的bug
parent
5f3b2fa1ef
commit
4cdafc80b4
|
@ -111,8 +111,8 @@ func RegisterModel() {
|
||||||
new(models.TeamMember),
|
new(models.TeamMember),
|
||||||
new(models.TeamRelationship),
|
new(models.TeamRelationship),
|
||||||
new(models.Itemsets),
|
new(models.Itemsets),
|
||||||
new(models.Comment),
|
new(models.Comment),
|
||||||
new(models.WorkWeixinAccount),
|
new(models.WorkWeixinAccount),
|
||||||
)
|
)
|
||||||
gob.Register(models.Blog{})
|
gob.Register(models.Blog{})
|
||||||
gob.Register(models.Document{})
|
gob.Register(models.Document{})
|
||||||
|
@ -207,7 +207,7 @@ func RegisterCommand() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//注册模板函数
|
// 注册模板函数
|
||||||
func RegisterFunction() {
|
func RegisterFunction() {
|
||||||
err := web.AddFuncMap("config", models.GetOptionValue)
|
err := web.AddFuncMap("config", models.GetOptionValue)
|
||||||
|
|
||||||
|
@ -294,7 +294,7 @@ func RegisterFunction() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//解析命令
|
// 解析命令
|
||||||
func ResolveCommand(args []string) {
|
func ResolveCommand(args []string) {
|
||||||
flagSet := flag.NewFlagSet("MinDoc command: ", flag.ExitOnError)
|
flagSet := flag.NewFlagSet("MinDoc command: ", flag.ExitOnError)
|
||||||
flagSet.StringVar(&conf.ConfigurationFile, "config", "", "MinDoc configuration file.")
|
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.StaticDir["/uploads"] = uploads
|
||||||
web.BConfig.WebConfig.ViewsPath = conf.WorkingDir("views")
|
web.BConfig.WebConfig.ViewsPath = conf.WorkingDir("views")
|
||||||
web.BConfig.WebConfig.Session.SessionCookieSameSite = http.SameSiteDefaultMode
|
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")
|
fonts := conf.WorkingDir("static", "fonts")
|
||||||
|
|
||||||
|
@ -362,7 +366,7 @@ func ResolveCommand(args []string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//注册缓存管道
|
// 注册缓存管道
|
||||||
func RegisterCache() {
|
func RegisterCache() {
|
||||||
isOpenCache := web.AppConfig.DefaultBool("cache", false)
|
isOpenCache := web.AppConfig.DefaultBool("cache", false)
|
||||||
if !isOpenCache {
|
if !isOpenCache {
|
||||||
|
@ -461,7 +465,7 @@ func RegisterCache() {
|
||||||
logs.Info("缓存初始化完成.")
|
logs.Info("缓存初始化完成.")
|
||||||
}
|
}
|
||||||
|
|
||||||
//自动加载配置文件.修改了监听端口号和数据库配置无法自动生效.
|
// 自动加载配置文件.修改了监听端口号和数据库配置无法自动生效.
|
||||||
func RegisterAutoLoadConfig() {
|
func RegisterAutoLoadConfig() {
|
||||||
if conf.AutoLoadDelay > 0 {
|
if conf.AutoLoadDelay > 0 {
|
||||||
|
|
||||||
|
@ -502,7 +506,7 @@ func RegisterAutoLoadConfig() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//注册错误处理方法.
|
// 注册错误处理方法.
|
||||||
func RegisterError() {
|
func RegisterError() {
|
||||||
web.ErrorHandler("404", func(writer http.ResponseWriter, request *http.Request) {
|
web.ErrorHandler("404", func(writer http.ResponseWriter, request *http.Request) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
|
@ -77,7 +77,9 @@ token_size=12
|
||||||
#上传文件的后缀,如果不限制后缀可以设置为 *
|
#上传文件的后缀,如果不限制后缀可以设置为 *
|
||||||
upload_file_ext=txt|doc|docx|xls|xlsx|ppt|pptx|pdf|7z|rar|jpg|jpeg|png|gif
|
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
|
upload_file_size=10MB
|
||||||
|
|
||||||
####################邮件配置######################
|
####################邮件配置######################
|
||||||
|
|
|
@ -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 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}$`
|
const RegexpAccount = `^[a-zA-Z0-9][a-zA-Z0-9\.-]{2,50}$`
|
||||||
|
|
||||||
// PageSize 默认分页条数.
|
// PageSize 默认分页条数.
|
||||||
|
@ -35,7 +35,7 @@ const (
|
||||||
MemberGeneralRole
|
MemberGeneralRole
|
||||||
)
|
)
|
||||||
|
|
||||||
//系统角色
|
// 系统角色
|
||||||
type SystemRole int
|
type SystemRole int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -51,7 +51,7 @@ const (
|
||||||
BookRoleNoSpecific
|
BookRoleNoSpecific
|
||||||
)
|
)
|
||||||
|
|
||||||
//项目角色
|
// 项目角色
|
||||||
type BookRole int
|
type BookRole int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -90,23 +90,23 @@ func GetDatabasePrefix() string {
|
||||||
return web.AppConfig.DefaultString("db_prefix", "md_")
|
return web.AppConfig.DefaultString("db_prefix", "md_")
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取默认头像
|
// 获取默认头像
|
||||||
func GetDefaultAvatar() string {
|
func GetDefaultAvatar() string {
|
||||||
return URLForWithCdnImage(web.AppConfig.DefaultString("avatar", "/static/images/headimgurl.jpg"))
|
return URLForWithCdnImage(web.AppConfig.DefaultString("avatar", "/static/images/headimgurl.jpg"))
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取阅读令牌长度.
|
// 获取阅读令牌长度.
|
||||||
func GetTokenSize() int {
|
func GetTokenSize() int {
|
||||||
return web.AppConfig.DefaultInt("token_size", 12)
|
return web.AppConfig.DefaultInt("token_size", 12)
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取默认文档封面.
|
// 获取默认文档封面.
|
||||||
func GetDefaultCover() string {
|
func GetDefaultCover() string {
|
||||||
|
|
||||||
return URLForWithCdnImage(web.AppConfig.DefaultString("cover", "/static/images/book.jpg"))
|
return URLForWithCdnImage(web.AppConfig.DefaultString("cover", "/static/images/book.jpg"))
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取允许的商城文件的类型.
|
// 获取允许的商城文件的类型.
|
||||||
func GetUploadFileExt() []string {
|
func GetUploadFileExt() []string {
|
||||||
ext := web.AppConfig.DefaultString("upload_file_ext", "png|jpg|jpeg|gif|txt|doc|docx|pdf")
|
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 {
|
func GetUploadFileSize() int64 {
|
||||||
size := web.AppConfig.DefaultString("upload_file_size", "0")
|
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 {
|
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") {
|
if strings.HasSuffix(size, "GB") {
|
||||||
|
@ -138,28 +138,33 @@ func GetUploadFileSize() int64 {
|
||||||
return s * 1024 * 1024 * 1024
|
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 strings.HasSuffix(size, "KB") {
|
||||||
if s, e := strconv.ParseInt(size[0:len(size)-2], 10, 64); e == nil {
|
if s, e := strconv.ParseInt(size[0:len(size)-2], 10, 64); e == nil {
|
||||||
return s * 1024
|
return s * 1024
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if s, e := strconv.ParseInt(size, 10, 64); e == nil {
|
if s, e := strconv.ParseInt(size, 10, 64); e == nil {
|
||||||
return s * 1024
|
return s
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
//是否启用导出
|
// 是否启用导出
|
||||||
func GetEnableExport() bool {
|
func GetEnableExport() bool {
|
||||||
return web.AppConfig.DefaultBool("enable_export", true)
|
return web.AppConfig.DefaultBool("enable_export", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
//是否启用iframe
|
// 是否启用iframe
|
||||||
func GetEnableIframe() bool {
|
func GetEnableIframe() bool {
|
||||||
return web.AppConfig.DefaultBool("enable_iframe", false)
|
return web.AppConfig.DefaultBool("enable_iframe", false)
|
||||||
}
|
}
|
||||||
|
|
||||||
//同一项目导出线程的并发数
|
// 同一项目导出线程的并发数
|
||||||
func GetExportProcessNum() int {
|
func GetExportProcessNum() int {
|
||||||
exportProcessNum := web.AppConfig.DefaultInt("export_process_num", 1)
|
exportProcessNum := web.AppConfig.DefaultInt("export_process_num", 1)
|
||||||
|
|
||||||
|
@ -169,7 +174,7 @@ func GetExportProcessNum() int {
|
||||||
return exportProcessNum
|
return exportProcessNum
|
||||||
}
|
}
|
||||||
|
|
||||||
//导出项目队列的并发数量
|
// 导出项目队列的并发数量
|
||||||
func GetExportLimitNum() int {
|
func GetExportLimitNum() int {
|
||||||
exportLimitNum := web.AppConfig.DefaultInt("export_limit_num", 1)
|
exportLimitNum := web.AppConfig.DefaultInt("export_limit_num", 1)
|
||||||
|
|
||||||
|
@ -179,7 +184,7 @@ func GetExportLimitNum() int {
|
||||||
return exportLimitNum
|
return exportLimitNum
|
||||||
}
|
}
|
||||||
|
|
||||||
//等待导出队列的长度
|
// 等待导出队列的长度
|
||||||
func GetExportQueueLimitNum() int {
|
func GetExportQueueLimitNum() int {
|
||||||
exportQueueLimitNum := web.AppConfig.DefaultInt("export_queue_limit_num", 10)
|
exportQueueLimitNum := web.AppConfig.DefaultInt("export_queue_limit_num", 10)
|
||||||
|
|
||||||
|
@ -189,14 +194,14 @@ func GetExportQueueLimitNum() int {
|
||||||
return exportQueueLimitNum
|
return exportQueueLimitNum
|
||||||
}
|
}
|
||||||
|
|
||||||
//默认导出项目的缓存目录
|
// 默认导出项目的缓存目录
|
||||||
func GetExportOutputPath() string {
|
func GetExportOutputPath() string {
|
||||||
exportOutputPath := filepath.Join(web.AppConfig.DefaultString("export_output_path", filepath.Join(WorkingDirectory, "cache")), "books")
|
exportOutputPath := filepath.Join(web.AppConfig.DefaultString("export_output_path", filepath.Join(WorkingDirectory, "cache")), "books")
|
||||||
|
|
||||||
return exportOutputPath
|
return exportOutputPath
|
||||||
}
|
}
|
||||||
|
|
||||||
//判断是否是允许商城的文件类型.
|
// 判断是否是允许商城的文件类型.
|
||||||
func IsAllowUploadFileExt(ext string) bool {
|
func IsAllowUploadFileExt(ext string) bool {
|
||||||
|
|
||||||
if strings.HasPrefix(ext, ".") {
|
if strings.HasPrefix(ext, ".") {
|
||||||
|
@ -215,7 +220,7 @@ func IsAllowUploadFileExt(ext string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
//读取配置文件值
|
// 读取配置文件值
|
||||||
func CONF(key string, value ...string) string {
|
func CONF(key string, value ...string) string {
|
||||||
defaultValue := ""
|
defaultValue := ""
|
||||||
if len(value) > 0 {
|
if len(value) > 0 {
|
||||||
|
@ -224,7 +229,7 @@ func CONF(key string, value ...string) string {
|
||||||
return web.AppConfig.DefaultString(key, defaultValue)
|
return web.AppConfig.DefaultString(key, defaultValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
//重写生成URL的方法,加上完整的域名
|
// 重写生成URL的方法,加上完整的域名
|
||||||
func URLFor(endpoint string, values ...interface{}) string {
|
func URLFor(endpoint string, values ...interface{}) string {
|
||||||
baseUrl := web.AppConfig.DefaultString("baseurl", "")
|
baseUrl := web.AppConfig.DefaultString("baseurl", "")
|
||||||
pathUrl := web.URLFor(endpoint, values...)
|
pathUrl := web.URLFor(endpoint, values...)
|
||||||
|
|
|
@ -34,7 +34,7 @@ func (c *BlogController) Prepare() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//文章阅读
|
// 文章阅读
|
||||||
func (c *BlogController) Index() {
|
func (c *BlogController) Index() {
|
||||||
c.Prepare()
|
c.Prepare()
|
||||||
c.TplName = "blog/index.tpl"
|
c.TplName = "blog/index.tpl"
|
||||||
|
@ -98,7 +98,7 @@ func (c *BlogController) Index() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//文章列表
|
// 文章列表
|
||||||
func (c *BlogController) List() {
|
func (c *BlogController) List() {
|
||||||
c.Prepare()
|
c.Prepare()
|
||||||
c.TplName = "blog/list.tpl"
|
c.TplName = "blog/list.tpl"
|
||||||
|
@ -130,7 +130,7 @@ func (c *BlogController) List() {
|
||||||
c.Data["Lists"] = blogList
|
c.Data["Lists"] = blogList
|
||||||
}
|
}
|
||||||
|
|
||||||
//管理后台文章列表
|
// 管理后台文章列表
|
||||||
func (c *BlogController) ManageList() {
|
func (c *BlogController) ManageList() {
|
||||||
c.Prepare()
|
c.Prepare()
|
||||||
c.TplName = "blog/manage_list.tpl"
|
c.TplName = "blog/manage_list.tpl"
|
||||||
|
@ -153,7 +153,7 @@ func (c *BlogController) ManageList() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//文章设置
|
// 文章设置
|
||||||
func (c *BlogController) ManageSetting() {
|
func (c *BlogController) ManageSetting() {
|
||||||
c.Prepare()
|
c.Prepare()
|
||||||
c.TplName = "blog/manage_setting.tpl"
|
c.TplName = "blog/manage_setting.tpl"
|
||||||
|
@ -290,7 +290,7 @@ func (c *BlogController) ManageSetting() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//文章创建或编辑
|
// 文章创建或编辑
|
||||||
func (c *BlogController) ManageEdit() {
|
func (c *BlogController) ManageEdit() {
|
||||||
c.Prepare()
|
c.Prepare()
|
||||||
c.TplName = "blog/manage_edit.tpl"
|
c.TplName = "blog/manage_edit.tpl"
|
||||||
|
@ -403,7 +403,7 @@ func (c *BlogController) ManageEdit() {
|
||||||
c.Data["Model"] = blog
|
c.Data["Model"] = blog
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除文章
|
// 删除文章
|
||||||
func (c *BlogController) ManageDelete() {
|
func (c *BlogController) ManageDelete() {
|
||||||
c.Prepare()
|
c.Prepare()
|
||||||
blogId, _ := c.GetInt("blog_id", 0)
|
blogId, _ := c.GetInt("blog_id", 0)
|
||||||
|
@ -624,7 +624,7 @@ func (c *BlogController) RemoveAttachment() {
|
||||||
c.JsonResult(0, "ok", attach)
|
c.JsonResult(0, "ok", attach)
|
||||||
}
|
}
|
||||||
|
|
||||||
//下载附件
|
// 下载附件
|
||||||
func (c *BlogController) Download() {
|
func (c *BlogController) Download() {
|
||||||
c.Prepare()
|
c.Prepare()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue