From 54b51d7c27828e71c00007af8455315a6ecb5287 Mon Sep 17 00:00:00 2001 From: Minho Date: Thu, 18 Jan 2018 19:54:05 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=A7=A3=E5=86=B3=E5=88=86=E9=A1=B5B?= =?UTF-8?q?UG=202=E3=80=81=E8=A7=A3=E5=86=B3=E5=88=87=E6=8D=A2=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E4=B8=8A=E4=BC=A0=E9=99=84=E4=BB=B6=E6=B7=B7=E4=B9=B1?= =?UTF-8?q?=E7=9A=84BUG=203=E3=80=81=E6=97=A0=E6=B3=95=E6=B8=85=E7=A9=BA?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E6=A0=87=E8=AF=86=E7=9A=84BUG=204=E3=80=81?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E4=B8=8D?= =?UTF-8?q?=E9=99=90=E5=88=B6=E5=90=8E=E7=BC=80=205=E3=80=81=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E9=99=90=E5=88=B6=206=E3=80=81=E5=AE=9E=E7=8E=B0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=8F=91=E5=B8=83=E5=8A=9F=E8=83=BD=207=E3=80=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=99=BB=E5=BD=95=E6=97=B6=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E6=A1=86=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=E4=B8=8D=E6=B6=88?= =?UTF-8?q?=E5=A4=B1=E9=97=AE=E9=A2=98=208=E3=80=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=BD=91=E7=AB=99=E9=A6=96=E9=A1=B5=E9=99=90=E5=88=B6=E7=BD=91?= =?UTF-8?q?=E7=AB=99title?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/command.go | 12 +++++++ conf/app.conf.example | 7 ++++- conf/enumerate.go | 27 +++++++++++++++- controllers/base.go | 1 + controllers/document.go | 31 +++++++++++++++---- logs/.gitignore | 1 - .../plugins/image-dialog/image-dialog.js | 2 +- static/js/markdown.js | 16 +++++++--- utils/pager.go | 2 +- views/account/login.tpl | 3 +- views/document/markdown_edit_template.tpl | 5 +-- views/home/index.tpl | 4 +-- views/widgets/header.tpl | 2 +- 13 files changed, 92 insertions(+), 21 deletions(-) delete mode 100644 logs/.gitignore 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) ? "
" + - "" + + "" + "" + "
" : ""; })() + diff --git a/static/js/markdown.js b/static/js/markdown.js index a6b7f0c6..d3699a3b 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -144,11 +144,16 @@ $(function () { resetEditor(); if (res.errcode === 0) { window.isLoad = true; - window.editor.clear(); - window.editor.insertValue(res.data.markdown); - window.editor.setCursor({ line : 0, ch : 0 }); + try { + window.editor.clear(); + window.editor.insertValue(res.data.markdown); + window.editor.setCursor({line: 0, ch: 0}); + }catch(e){ + console.log(e); + } var node = { "id": res.data.doc_id, 'parent': res.data.parent_id === 0 ? '#' : res.data.parent_id, "text": res.data.doc_name, "identify": res.data.identify, "version": res.data.version }; pushDocumentCategory(node); + console.log(node); window.selectNode = node; pushVueLists(res.data.attach); } else { @@ -351,6 +356,7 @@ $(function () { }).on('loaded.jstree', function () { window.treeCatalog = $(this).jstree(); }).on('select_node.jstree', function (node, selected, event) { + if ($("#markdown-save").hasClass('change')) { if (confirm("编辑内容未保存,需要保存吗?")) { saveDocument(false, function () { @@ -362,7 +368,9 @@ $(function () { loadDocument(selected); }).on("move_node.jstree", jstree_save); - + /** + * 打开文档模板 + */ $("#documentTemplateModal").on("click", ".section>a[data-type]", function () { var $this = $(this).attr("data-type"); var body = $("#template-" + $this).html(); diff --git a/utils/pager.go b/utils/pager.go index 1a9ec51e..c71571b3 100644 --- a/utils/pager.go +++ b/utils/pager.go @@ -166,7 +166,7 @@ func DealUri(po *PageOptions, requestURI string) { func fun4(po *PageOptions, totalPages int) string { rs := "" rs += getHeader(po, totalPages) - rs += "
  • " + con.Itoa(1) + "
  • " + rs += "
  • " + con.Itoa(1) + "
  • " rs += "
  • ...
  • " for i := totalPages - po.LinkItemCount; i <= totalPages; i++ { if po.CurrentPage != i { diff --git a/views/account/login.tpl b/views/account/login.tpl index 12e3a032..17dd4e3b 100644 --- a/views/account/login.tpl +++ b/views/account/login.tpl @@ -92,7 +92,7 @@