diff --git a/commands/command.go b/commands/command.go index ee4c9bc6..c13582c2 100644 --- a/commands/command.go +++ b/commands/command.go @@ -133,6 +133,9 @@ func RegisterFunction() { beego.AddFuncMap("cdn", func(p string) string { cdn := beego.AppConfig.DefaultString("cdn", "") + if strings.HasPrefix(p,"http://") || strings.HasPrefix(p,"https://") { + return p + } if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") { return cdn + string(p[1:]) } @@ -144,6 +147,9 @@ func RegisterFunction() { beego.AddFuncMap("cdnjs", func(p string) string { cdn := beego.AppConfig.DefaultString("cdnjs", "") + if strings.HasPrefix(p,"http://") || strings.HasPrefix(p,"https://") { + return p + } if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") { return cdn + string(p[1:]) } @@ -154,6 +160,9 @@ func RegisterFunction() { }) beego.AddFuncMap("cdncss", func(p string) string { cdn := beego.AppConfig.DefaultString("cdncss", "") + if strings.HasPrefix(p,"http://") || strings.HasPrefix(p,"https://") { + return p + } if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") { return cdn + string(p[1:]) } @@ -163,6 +172,9 @@ func RegisterFunction() { return cdn + p }) beego.AddFuncMap("cdnimg", func(p string) string { + if strings.HasPrefix(p,"http://") || strings.HasPrefix(p,"https://") { + return p + } cdn := beego.AppConfig.DefaultString("cdnimg", "") if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") { return cdn + string(p[1:]) diff --git a/conf/app.conf.example b/conf/app.conf.example index 312f7fcc..29d50423 100644 --- a/conf/app.conf.example +++ b/conf/app.conf.example @@ -6,6 +6,9 @@ sessionon = true sessionname = mindoc_id copyrequestbody = true +#是否自动发布文档,false 为否, true 保存文档后自动发布 +auto_release=false + #默认Session生成Key的秘钥 beegoserversessionkey=123456 @@ -47,8 +50,10 @@ avatar=/static/images/headimgurl.jpg #默认阅读令牌长度 token_size=12 -#上传文件的后缀 +#上传文件的后缀,如果不限制后缀可以设置为 * upload_file_ext=txt|doc|docx|xls|xlsx|ppt|pptx|pdf|7z|rar|jpg|jpeg|png|gif +#上传的文件大小限制,如果不填写,默认不限制,单位可以是 GB KB MB +upload_file_size=10MB ####################邮件配置###################### #是否启用邮件 diff --git a/conf/enumerate.go b/conf/enumerate.go index 96c3a9c9..5053241a 100644 --- a/conf/enumerate.go +++ b/conf/enumerate.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/astaxie/beego" + "strconv" ) // 登录用户的Session名 @@ -12,7 +13,7 @@ const LoginSessionName = "LoginSessionName" const CaptchaSessionName = "__captcha__" -const RegexpEmail = `^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$` +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])?)*$" //允许用户名中出现点号 @@ -101,6 +102,30 @@ func GetUploadFileExt() []string { } return exts } +// 获取上传文件允许的最大值 +func GetUploadFileSize() int64 { + size := beego.AppConfig.DefaultString("upload_file_size","0") + + 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,"GB") { + if s,e := strconv.ParseInt(size[0:len(size) - 2], 10, 64);e == nil { + return s * 1024 * 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 0 +} //判断是否是允许商城的文件类型. func IsAllowUploadFileExt(ext string) bool { diff --git a/controllers/base.go b/controllers/base.go index d6405ec8..cb58f8da 100644 --- a/controllers/base.go +++ b/controllers/base.go @@ -29,6 +29,7 @@ func (c *BaseController) Prepare (){ c.EnableDocumentHistory = false if member,ok := c.GetSession(conf.LoginSessionName).(models.Member); ok && member.MemberId > 0{ + c.Member = &member c.Data["Member"] = c.Member }else{ diff --git a/controllers/document.go b/controllers/document.go index 9cedddc4..0de9f105 100644 --- a/controllers/document.go +++ b/controllers/document.go @@ -392,9 +392,8 @@ func (c *DocumentController) Create() { document.MemberId = c.Member.MemberId document.BookId = book_id - if doc_identify != "" { - document.Identify = doc_identify - } + document.Identify = doc_identify + document.Version = time.Now().Unix() document.DocumentName = doc_name @@ -435,14 +434,26 @@ func (c *DocumentController) Upload() { defer file.Close() + type Size interface { + Size() int64 + } + beego.Info(conf.GetUploadFileSize()) + beego.Info(moreFile.Size) + if conf.GetUploadFileSize() > 0 && moreFile.Size > conf.GetUploadFileSize() { + c.JsonResult(6009,"查过文件允许的上传最大值") + } + + ext := filepath.Ext(moreFile.Filename) if ext == "" { c.JsonResult(6003, "无法解析文件的格式") } - - if !conf.IsAllowUploadFileExt(ext) { - c.JsonResult(6004, "不允许的文件类型") + //如果文件类型设置为 * 标识不限制文件类型 + if beego.AppConfig.DefaultString("upload_file_ext", "") != "*" { + if !conf.IsAllowUploadFileExt(ext) { + c.JsonResult(6004, "不允许的文件类型") + } } book_id := 0 @@ -806,6 +817,14 @@ func (c *DocumentController) Content() { beego.Error("DocumentHistory InsertOrUpdate => ", err) } } + if beego.AppConfig.DefaultBool("auto_release", false) { + go func(identify string) { + models.NewDocument().ReleaseContent(book_id) + + + }(identify) + } + c.JsonResult(0, "ok", doc) } diff --git a/logs/.gitignore b/logs/.gitignore deleted file mode 100644 index bfa6a22a..00000000 --- a/logs/.gitignore +++ /dev/null @@ -1 +0,0 @@ -# Created by .ignore support plugin (hsz.mobi) diff --git a/static/editor.md/plugins/image-dialog/image-dialog.js b/static/editor.md/plugins/image-dialog/image-dialog.js index ebc8d747..9909d6ed 100644 --- a/static/editor.md/plugins/image-dialog/image-dialog.js +++ b/static/editor.md/plugins/image-dialog/image-dialog.js @@ -51,7 +51,7 @@ "" + "" + (function(){ return (settings.imageUpload) ? "