fix:1、修复附件无法同时上传多个的BUG

2、新增客户端校验附件大小
pull/358/head
lifei6671 2018-09-11 15:57:03 +08:00
parent 929f54840b
commit 90efeac326
8 changed files with 59 additions and 57 deletions

View File

@ -186,6 +186,9 @@ func IsAllowUploadFileExt(ext string) bool {
exts := GetUploadFileExt()
for _, item := range exts {
if item == "*" {
return true
}
if strings.EqualFold(item, ext) {
return true
}

View File

@ -12,6 +12,8 @@ import (
"github.com/lifei6671/mindoc/conf"
"github.com/lifei6671/mindoc/models"
"github.com/lifei6671/mindoc/utils"
"github.com/lifei6671/mindoc/utils/filetil"
"path/filepath"
)
type BaseController struct {
@ -56,9 +58,6 @@ func (c *BaseController) Prepare() {
}
}
}
//c.Member = models.NewMember()
//c.Member.Find(1)
//c.Data["Member"] = *c.Member
}
conf.BaseUrl = c.BaseUrl()
c.Data["BaseUrl"] = c.BaseUrl()
@ -78,6 +77,10 @@ func (c *BaseController) Prepare() {
}
}
c.Data["HighlightStyle"] = beego.AppConfig.DefaultString("highlight_style","github")
if filetil.FileExists(filepath.Join(beego.BConfig.WebConfig.ViewsPath,"widgets","scripts.tpl")) {
c.LayoutSections["Scripts"] = "widgets/scripts.tpl"
}
}
// SetMember 获取或设置当前登录用户信息,如果 MemberId 小于 0 则标识删除 Session

View File

@ -337,7 +337,6 @@ func (c *BlogController) ManageEdit() {
blog.ModifyAt = c.Member.MemberId
blog.Modified = time.Now()
if err := blog.Save("blog_content","blog_release","modify_at","modify_time","version");err != nil {
beego.Error("保存文章失败 -> ",err)
c.JsonResult(6011,"保存文章失败")
@ -374,7 +373,11 @@ func (c *BlogController) ManageEdit() {
}else{
c.Data["AttachList"] = template.JS("[]")
}
if conf.GetUploadFileSize() > 0 {
c.Data["UploadFileSize"] = conf.GetUploadFileSize()
}else{
c.Data["UploadFileSize"] = "undefined";
}
c.Data["Model"] = blog
}

View File

@ -186,7 +186,7 @@ func (c *DocumentController) Read() {
Body string `json:"body"`
Title string `json:"title"`
DocInfo string `json:"doc_info"`
Version int64 `json:"version"`
Version int64 `json:"version"`
}
data.DocTitle = doc.DocumentName
data.Body = doc.Release
@ -282,6 +282,12 @@ func (c *DocumentController) Edit() {
}
c.Data["BaiDuMapKey"] = beego.AppConfig.DefaultString("baidumapkey", "")
if conf.GetUploadFileSize() > 0 {
c.Data["UploadFileSize"] = conf.GetUploadFileSize()
}else{
c.Data["UploadFileSize"] = "undefined";
}
}
// 创建一个文档
@ -291,7 +297,7 @@ func (c *DocumentController) Create() {
docName := c.GetString("doc_name")
parentId, _ := c.GetInt("parent_id", 0)
docId, _ := c.GetInt("doc_id", 0)
isOpen,_ := c.GetInt("is_open",0)
isOpen, _ := c.GetInt("is_open", 0)
if identify == "" {
c.JsonResult(6001, "参数错误")
@ -353,7 +359,7 @@ func (c *DocumentController) Create() {
if isOpen == 1 {
document.IsOpen = 1
}else{
} else {
document.IsOpen = 0
}
@ -397,19 +403,17 @@ func (c *DocumentController) Upload() {
}
if conf.GetUploadFileSize() > 0 && moreFile.Size > conf.GetUploadFileSize() {
c.JsonResult(6009, "查过文件允许的上传最大值")
c.JsonResult(6009, "文件大小超过了限定的最大值")
}
ext := filepath.Ext(moreFile.Filename)
//文件必须带有后缀名
if ext == "" {
c.JsonResult(6003, "无法解析文件的格式")
}
//如果文件类型设置为 * 标识不限制文件类型
if beego.AppConfig.DefaultString("upload_file_ext", "") != "*" {
if !conf.IsAllowUploadFileExt(ext) {
c.JsonResult(6004, "不允许的文件类型")
}
if conf.IsAllowUploadFileExt(ext) == false {
c.JsonResult(6004, "不允许的文件类型")
}
bookId := 0
@ -504,7 +508,7 @@ func (c *DocumentController) Upload() {
if err != nil {
os.Remove(filePath)
beego.Error("Attachment Insert => ", err)
beego.Error("文件保存失败 ->", err)
c.JsonResult(6006, "文件保存失败")
}
@ -512,7 +516,7 @@ func (c *DocumentController) Upload() {
attachment.HttpPath = conf.URLFor("DocumentController.DownloadAttachment", ":key", identify, ":attach_id", attachment.AttachmentId)
if err := attachment.Update(); err != nil {
beego.Error("SaveToFile => ", err)
beego.Error("保存文件失败 ->", err)
c.JsonResult(6005, "保存文件失败")
}
}

View File

@ -237,10 +237,8 @@
formData : { "blogId" : {{.Model.BlogId}}},
pick: "#filePicker",
fileVal : "editormd-file-file",
fileNumLimit : 1,
fileSingleSizeLimit: {{.UploadFileSize}},
compress : false
}).on("beforeFileQueued",function (file) {
uploader.reset();
}).on( 'fileQueued', function( file ) {
var item = {
state : "wait",
@ -249,15 +247,14 @@
file_name : file.name,
message : "正在上传"
};
window.vueApp.lists.splice(0,0,item);
window.vueApp.lists.push(item);
}).on("uploadError",function (file,reason) {
for(var i in window.vueApp.lists){
var item = window.vueApp.lists[i];
if(item.attachment_id == file.id){
item.state = "error";
item.message = "上传失败";
break;
item.message = "上传失败:" + reason;
}
}
@ -267,25 +264,23 @@
var item = window.vueApp.lists[index];
if(item.attachment_id === file.id){
if(res.errcode === 0) {
window.vueApp.lists.splice(index, 1, res.attach);
window.vueApp.lists.splice(index, 1, res.attach?res.attach:res.data);
}else{
item.message = res.message;
item.state = "error";
}
break;
}
}
}).on("beforeFileQueued",function (file) {
}).on("uploadComplete",function () {
}).on("uploadProgress",function (file, percentage) {
var $li = $( '#'+file.id ),
$percent = $li.find('.progress .progress-bar');
$percent.css( 'width', percentage * 100 + '%' );
}).on("error", function (type) {
if(type === "F_EXCEED_SIZE"){
layer.msg("文件超过了限定大小");
}
console.log(type);
});
}catch(e){
console.log(e);

View File

@ -278,7 +278,6 @@
<script src="{{cdnjs "/static/js/kancloud.js" "version"}}" type="text/javascript"></script>
<script src="{{cdnjs "/static/js/splitbar.js" "version"}}" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#searchList").on("click","a",function () {
var id = $(this).attr("data-id");
@ -290,7 +289,7 @@ $(function () {
});
});
});
</script>
{{.Scripts}}
</body>
</html>

View File

@ -427,10 +427,10 @@
formData : { "identify" : {{.Model.Identify}},"doc_id" : window.selectNode.id },
pick: "#filePicker",
fileVal : "editormd-file-file",
fileNumLimit : 1,
compress : false
compress : false,
fileSingleSizeLimit: {{.UploadFileSize}}
}).on("beforeFileQueued",function (file) {
uploader.reset();
// uploader.reset();
this.options.formData.doc_id = window.selectNode.id;
}).on( 'fileQueued', function( file ) {
var item = {
@ -440,14 +440,14 @@
file_name : file.name,
message : "正在上传"
};
window.vueApp.lists.splice(0,0,item);
window.vueApp.lists.push(item);
}).on("uploadError",function (file,reason) {
for(var i in window.vueApp.lists){
var item = window.vueApp.lists[i];
if(item.attachment_id == file.id){
item.state = "error";
item.message = "上传失败";
item.message = "上传失败:" + reason;
break;
}
}
@ -458,25 +458,23 @@
var item = window.vueApp.lists[index];
if(item.attachment_id === file.id){
if(res.errcode === 0) {
window.vueApp.lists.splice(index, 1, res.attach);
window.vueApp.lists.splice(index, 1, res.attach ? res.attach : res.data);
}else{
item.message = res.message;
item.state = "error";
}
break;
}
}
}).on("beforeFileQueued",function (file) {
}).on("uploadComplete",function () {
}).on("uploadProgress",function (file, percentage) {
var $li = $( '#'+file.id ),
$percent = $li.find('.progress .progress-bar');
$percent.css( 'width', percentage * 100 + '%' );
}).on("error", function (type) {
if(type === "F_EXCEED_SIZE"){
layer.msg("文件超过了限定大小");
}
console.log(type);
});
}catch(e){
console.log(e);

View File

@ -419,10 +419,9 @@
formData : { "identify" : {{.Model.Identify}},"doc_id" : window.selectNode.id },
pick: "#filePicker",
fileVal : "editormd-file-file",
fileNumLimit : 1,
compress : false
compress : false,
fileSingleSizeLimit: {{.UploadFileSize}}
}).on("beforeFileQueued",function (file) {
uploader.reset();
this.options.formData.doc_id = window.selectNode.id;
}).on( 'fileQueued', function( file ) {
var item = {
@ -432,20 +431,18 @@
file_name : file.name,
message : "正在上传"
};
window.vueApp.lists.splice(0,0,item);
window.vueApp.lists.push(item);
}).on("uploadError",function (file,reason) {
for(var i in window.vueApp.lists){
var item = window.vueApp.lists[i];
if(item.attachment_id == file.id){
item.state = "error";
item.message = "上传失败";
break;
item.message = "上传失败:" + reason;
}
}
}).on("uploadSuccess",function (file, res) {
for(var index in window.vueApp.lists){
var item = window.vueApp.lists[index];
if(item.attachment_id === file.id){
@ -456,19 +453,19 @@
item.message = res.message;
item.state = "error";
}
break;
}
}
}).on("beforeFileQueued",function (file) {
}).on("uploadComplete",function () {
}).on("uploadProgress",function (file, percentage) {
var $li = $( '#'+file.id ),
$percent = $li.find('.progress .progress-bar');
$percent.css( 'width', percentage * 100 + '%' );
}).on("error", function (type) {
if(type === "F_EXCEED_SIZE"){
layer.msg("文件超过了限定大小");
}
console.log(type);
});
}catch(e){
console.log(e);