1、解决分页BUG

2、解决切换文档上传附件混乱的BUG
3、无法清空文档标识的BUG
4、实现上传文件不限制后缀
5、实现上传文件大小限制
6、实现自动发布功能
7、优化登录时密码框错误提示不消失问题
8、优化网站首页限制网站title
pull/219/head
Minho 2018-01-18 19:54:05 +08:00
parent 848d3752e3
commit 54b51d7c27
13 changed files with 92 additions and 21 deletions

View File

@ -133,6 +133,9 @@ func RegisterFunction() {
beego.AddFuncMap("cdn", func(p string) string { beego.AddFuncMap("cdn", func(p string) string {
cdn := beego.AppConfig.DefaultString("cdn", "") cdn := beego.AppConfig.DefaultString("cdn", "")
if strings.HasPrefix(p,"http://") || strings.HasPrefix(p,"https://") {
return p
}
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") { if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
return cdn + string(p[1:]) return cdn + string(p[1:])
} }
@ -144,6 +147,9 @@ func RegisterFunction() {
beego.AddFuncMap("cdnjs", func(p string) string { beego.AddFuncMap("cdnjs", func(p string) string {
cdn := beego.AppConfig.DefaultString("cdnjs", "") cdn := beego.AppConfig.DefaultString("cdnjs", "")
if strings.HasPrefix(p,"http://") || strings.HasPrefix(p,"https://") {
return p
}
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") { if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
return cdn + string(p[1:]) return cdn + string(p[1:])
} }
@ -154,6 +160,9 @@ func RegisterFunction() {
}) })
beego.AddFuncMap("cdncss", func(p string) string { beego.AddFuncMap("cdncss", func(p string) string {
cdn := beego.AppConfig.DefaultString("cdncss", "") cdn := beego.AppConfig.DefaultString("cdncss", "")
if strings.HasPrefix(p,"http://") || strings.HasPrefix(p,"https://") {
return p
}
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") { if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
return cdn + string(p[1:]) return cdn + string(p[1:])
} }
@ -163,6 +172,9 @@ func RegisterFunction() {
return cdn + p return cdn + p
}) })
beego.AddFuncMap("cdnimg", func(p string) string { beego.AddFuncMap("cdnimg", func(p string) string {
if strings.HasPrefix(p,"http://") || strings.HasPrefix(p,"https://") {
return p
}
cdn := beego.AppConfig.DefaultString("cdnimg", "") cdn := beego.AppConfig.DefaultString("cdnimg", "")
if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") { if strings.HasPrefix(p, "/") && strings.HasSuffix(cdn, "/") {
return cdn + string(p[1:]) return cdn + string(p[1:])

View File

@ -6,6 +6,9 @@ sessionon = true
sessionname = mindoc_id sessionname = mindoc_id
copyrequestbody = true copyrequestbody = true
#是否自动发布文档false 为否, true 保存文档后自动发布
auto_release=false
#默认Session生成Key的秘钥 #默认Session生成Key的秘钥
beegoserversessionkey=123456 beegoserversessionkey=123456
@ -47,8 +50,10 @@ avatar=/static/images/headimgurl.jpg
#默认阅读令牌长度 #默认阅读令牌长度
token_size=12 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
upload_file_size=10MB
####################邮件配置###################### ####################邮件配置######################
#是否启用邮件 #是否启用邮件

View File

@ -5,6 +5,7 @@ import (
"strings" "strings"
"github.com/astaxie/beego" "github.com/astaxie/beego"
"strconv"
) )
// 登录用户的Session名 // 登录用户的Session名
@ -12,7 +13,7 @@ const LoginSessionName = "LoginSessionName"
const CaptchaSessionName = "__captcha__" 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 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 { func IsAllowUploadFileExt(ext string) bool {

View File

@ -29,6 +29,7 @@ func (c *BaseController) Prepare (){
c.EnableDocumentHistory = false c.EnableDocumentHistory = false
if member,ok := c.GetSession(conf.LoginSessionName).(models.Member); ok && member.MemberId > 0{ if member,ok := c.GetSession(conf.LoginSessionName).(models.Member); ok && member.MemberId > 0{
c.Member = &member c.Member = &member
c.Data["Member"] = c.Member c.Data["Member"] = c.Member
}else{ }else{

View File

@ -392,9 +392,8 @@ func (c *DocumentController) Create() {
document.MemberId = c.Member.MemberId document.MemberId = c.Member.MemberId
document.BookId = book_id document.BookId = book_id
if doc_identify != "" {
document.Identify = doc_identify document.Identify = doc_identify
}
document.Version = time.Now().Unix() document.Version = time.Now().Unix()
document.DocumentName = doc_name document.DocumentName = doc_name
@ -435,15 +434,27 @@ func (c *DocumentController) Upload() {
defer file.Close() 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) ext := filepath.Ext(moreFile.Filename)
if ext == "" { if ext == "" {
c.JsonResult(6003, "无法解析文件的格式") c.JsonResult(6003, "无法解析文件的格式")
} }
//如果文件类型设置为 * 标识不限制文件类型
if beego.AppConfig.DefaultString("upload_file_ext", "") != "*" {
if !conf.IsAllowUploadFileExt(ext) { if !conf.IsAllowUploadFileExt(ext) {
c.JsonResult(6004, "不允许的文件类型") c.JsonResult(6004, "不允许的文件类型")
} }
}
book_id := 0 book_id := 0
@ -806,6 +817,14 @@ func (c *DocumentController) Content() {
beego.Error("DocumentHistory InsertOrUpdate => ", err) 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) c.JsonResult(0, "ok", doc)
} }

1
logs/.gitignore vendored
View File

@ -1 +0,0 @@
# Created by .ignore support plugin (hsz.mobi)

View File

@ -51,7 +51,7 @@
"<label>" + imageLang.url + "</label>" + "<label>" + imageLang.url + "</label>" +
"<input type=\"text\" data-url />" + (function(){ "<input type=\"text\" data-url />" + (function(){
return (settings.imageUpload) ? "<div class=\"" + classPrefix + "file-input\">" + return (settings.imageUpload) ? "<div class=\"" + classPrefix + "file-input\">" +
"<input type=\"file\" name=\"" + classPrefix + "image-file\" accept=\"image/*\" />" + "<input type=\"file\" name=\"" + classPrefix + "image-file\" accept=\"image/jpeg,image/png,image/gif,image/jpg\" />" +
"<input type=\"submit\" value=\"" + imageLang.uploadButton + "\" />" + "<input type=\"submit\" value=\"" + imageLang.uploadButton + "\" />" +
"</div>" : ""; "</div>" : "";
})() + })() +

View File

@ -144,11 +144,16 @@ $(function () {
resetEditor(); resetEditor();
if (res.errcode === 0) { if (res.errcode === 0) {
window.isLoad = true; window.isLoad = true;
try {
window.editor.clear(); window.editor.clear();
window.editor.insertValue(res.data.markdown); window.editor.insertValue(res.data.markdown);
window.editor.setCursor({ line : 0, ch : 0 }); 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 }; 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); pushDocumentCategory(node);
console.log(node);
window.selectNode = node; window.selectNode = node;
pushVueLists(res.data.attach); pushVueLists(res.data.attach);
} else { } else {
@ -351,6 +356,7 @@ $(function () {
}).on('loaded.jstree', function () { }).on('loaded.jstree', function () {
window.treeCatalog = $(this).jstree(); window.treeCatalog = $(this).jstree();
}).on('select_node.jstree', function (node, selected, event) { }).on('select_node.jstree', function (node, selected, event) {
if ($("#markdown-save").hasClass('change')) { if ($("#markdown-save").hasClass('change')) {
if (confirm("编辑内容未保存,需要保存吗?")) { if (confirm("编辑内容未保存,需要保存吗?")) {
saveDocument(false, function () { saveDocument(false, function () {
@ -362,7 +368,9 @@ $(function () {
loadDocument(selected); loadDocument(selected);
}).on("move_node.jstree", jstree_save); }).on("move_node.jstree", jstree_save);
/**
*
*/
$("#documentTemplateModal").on("click", ".section>a[data-type]", function () { $("#documentTemplateModal").on("click", ".section>a[data-type]", function () {
var $this = $(this).attr("data-type"); var $this = $(this).attr("data-type");
var body = $("#template-" + $this).html(); var body = $("#template-" + $this).html();

View File

@ -166,7 +166,7 @@ func DealUri(po *PageOptions, requestURI string) {
func fun4(po *PageOptions, totalPages int) string { func fun4(po *PageOptions, totalPages int) string {
rs := "" rs := ""
rs += getHeader(po, totalPages) rs += getHeader(po, totalPages)
rs += "<li><a href='" + po.Href + "&" + po.ParamName + "=" + con.Itoa(1) + "'>" + con.Itoa(1) + "</a><li>" rs += "<li><a href='" + po.Href + "&" + po.ParamName + "=" + con.Itoa(1) + "'>" + con.Itoa(1) + "</a></li>"
rs += "<li><a href=''>...</a></li>" rs += "<li><a href=''>...</a></li>"
for i := totalPages - po.LinkItemCount; i <= totalPages; i++ { for i := totalPages - po.LinkItemCount; i <= totalPages; i++ {
if po.CurrentPage != i { if po.CurrentPage != i {

View File

@ -92,7 +92,7 @@
<script src="{{cdnjs "/static/layer/layer.js"}}" type="text/javascript"></script> <script src="{{cdnjs "/static/layer/layer.js"}}" type="text/javascript"></script>
<script type="text/javascript"> <script type="text/javascript">
$(function () { $(function () {
$("#account,#passwd,#code").on('focus', function () { $("#account,#password,#code").on('focus', function () {
$(this).tooltip('destroy').parents('.form-group').removeClass('has-error'); $(this).tooltip('destroy').parents('.form-group').removeClass('has-error');
}); });
@ -104,6 +104,7 @@
}); });
$("#btn-login").on('click', function () { $("#btn-login").on('click', function () {
$(this).tooltip('destroy').parents('.form-group').removeClass('has-error');
var $btn = $(this).button('loading'); var $btn = $(this).button('loading');
var account = $.trim($("#account").val()); var account = $.trim($("#account").val());

View File

@ -28,9 +28,9 @@
<link href="{{cdncss "/static/css/jstree.css"}}" rel="stylesheet"> <link href="{{cdncss "/static/css/jstree.css"}}" rel="stylesheet">
<link href="{{cdncss "/static/highlight/styles/zenburn.css"}}" rel="stylesheet"> <link href="{{cdncss "/static/highlight/styles/zenburn.css"}}" rel="stylesheet">
<link href="{{cdncss "/static/webuploader/webuploader.css"}}" rel="stylesheet"> <link href="{{cdncss "/static/webuploader/webuploader.css"}}" rel="stylesheet">
<link href="/static/css/markdown.css" rel="stylesheet"> <link href="{{cdncss "/static/css/markdown.css"}}" rel="stylesheet">
<link href="{{cdncss "/static/prettify/themes/atelier-estuary-dark.min.css"}}" rel="stylesheet"> <link href="{{cdncss "/static/prettify/themes/atelier-estuary-dark.min.css"}}" rel="stylesheet">
<link href="/static/css/markdown.preview.css" rel="stylesheet"> <link href="{{cdncss "/static/css/markdown.preview.css"}}" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]> <!--[if lt IE 9]>
@ -310,6 +310,7 @@
compress : false compress : false
}).on("beforeFileQueued",function (file) { }).on("beforeFileQueued",function (file) {
uploader.reset(); uploader.reset();
this.options.formData.doc_id = window.selectNode.id;
}).on( 'fileQueued', function( file ) { }).on( 'fileQueued', function( file ) {
var item = { var item = {
state : "wait", state : "wait",

View File

@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>网站首页 - Powered by MinDoc</title> <title>{{.SITE_NAME}} - Powered by MinDoc</title>
<meta name="author" content="Minho" /> <meta name="author" content="Minho" />
<meta name="site" content="https://www.iminho.me" /> <meta name="site" content="https://www.iminho.me" />
<!-- Bootstrap --> <!-- Bootstrap -->
@ -44,7 +44,7 @@
<dl class="manual-item-standard"> <dl class="manual-item-standard">
<dt> <dt>
<a href="{{urlfor "DocumentController.Index" ":key" $item.Identify}}" title="{{$item.BookName}}-{{$item.CreateName}}" target="_blank"> <a href="{{urlfor "DocumentController.Index" ":key" $item.Identify}}" title="{{$item.BookName}}-{{$item.CreateName}}" target="_blank">
<img src="{{$item.Cover}}" class="cover" alt="{{$item.BookName}}-{{$item.CreateName}}"> <img src="{{$item.Cover}}" class="cover" alt="{{$item.BookName}}-{{$item.CreateName}}" onerror="this.src='{{cdnimg "static/images/book.jpg"}}';">
</a> </a>
</dt> </dt>
<dd> <dd>

View File

@ -1,6 +1,6 @@
<header class="navbar navbar-static-top navbar-fixed-top manual-header" role="banner"> <header class="navbar navbar-static-top navbar-fixed-top manual-header" role="banner">
<div class="container"> <div class="container">
<div class="navbar-header col-sm-12 col-md-7 col-lg-6"> <div class="navbar-header col-sm-12 col-md-10 col-lg-8">
<a href="/" class="navbar-brand" title="{{.SITE_NAME}}"> <a href="/" class="navbar-brand" title="{{.SITE_NAME}}">
{{if .SITE_TITLE}} {{if .SITE_TITLE}}
{{.SITE_TITLE}} {{.SITE_TITLE}}