mirror of
https://github.com/mindoc-org/mindoc.git
synced 2026-02-27 17:03:57 +08:00
fix:1、修复附件无法同时上传多个的BUG
2、新增客户端校验附件大小
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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, "保存文件失败")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user