mirror of
https://github.com/mindoc-org/mindoc.git
synced 2026-02-27 17:03:57 +08:00
refactor, replace beego.Error with logs.Error
This commit is contained in:
@@ -3,6 +3,7 @@ package controllers
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -49,7 +50,7 @@ func (c *BlogController) Index() {
|
||||
}
|
||||
|
||||
if c.Ctx.Input.IsPost() {
|
||||
password := c.GetString("password");
|
||||
password := c.GetString("password")
|
||||
if blog.BlogStatus == "password" && password != blog.Password {
|
||||
c.JsonResult(6001, "文章密码不正确")
|
||||
} else if blog.BlogStatus == "password" && password == blog.Password {
|
||||
@@ -250,7 +251,7 @@ func (c *BlogController) ManageSetting() {
|
||||
blog.Password = blogPassword
|
||||
|
||||
if err := blog.Save(); err != nil {
|
||||
beego.Error("保存文章失败 -> ", err)
|
||||
logs.Error("保存文章失败 -> ", err)
|
||||
c.JsonResult(6011, "保存文章失败")
|
||||
} else {
|
||||
c.JsonResult(0, "ok", blog)
|
||||
@@ -263,7 +264,7 @@ func (c *BlogController) ManageSetting() {
|
||||
}
|
||||
blogId, err := strconv.Atoi(c.Ctx.Input.Param(":id"))
|
||||
|
||||
c.Data["DocumentIdentify"] = "";
|
||||
c.Data["DocumentIdentify"] = ""
|
||||
if err == nil {
|
||||
blog, err := models.NewBlog().FindByIdAndMemberId(blogId, c.Member.MemberId)
|
||||
if err != nil {
|
||||
@@ -301,7 +302,7 @@ func (c *BlogController) ManageEdit() {
|
||||
blog, err = models.NewBlog().FindByIdAndMemberId(blogId, c.Member.MemberId)
|
||||
}
|
||||
if err != nil {
|
||||
beego.Error("查询文章失败 ->", err)
|
||||
logs.Error("查询文章失败 ->", err)
|
||||
c.JsonResult(6002, "查询文章失败")
|
||||
}
|
||||
if version > 0 && blog.Version != version && cover != "yes" {
|
||||
@@ -311,7 +312,7 @@ func (c *BlogController) ManageEdit() {
|
||||
if blog.BlogType == 1 {
|
||||
doc, err := models.NewDocument().Find(blog.DocumentId)
|
||||
if err != nil {
|
||||
beego.Error("查询关联项目文档时出错 ->", err)
|
||||
logs.Error("查询关联项目文档时出错 ->", err)
|
||||
c.JsonResult(6003, "查询关联项目文档时出错")
|
||||
}
|
||||
book, err := models.NewBook().Find(doc.BookId)
|
||||
@@ -324,7 +325,7 @@ func (c *BlogController) ManageEdit() {
|
||||
bookResult, err := models.NewBookResult().FindByIdentify(book.Identify, c.Member.MemberId)
|
||||
|
||||
if err != nil || bookResult.RoleId == conf.BookObserver {
|
||||
beego.Error("FindByIdentify => ", err)
|
||||
logs.Error("FindByIdentify => ", err)
|
||||
c.JsonResult(6002, "关联文档不存在或权限不足")
|
||||
}
|
||||
}
|
||||
@@ -335,7 +336,7 @@ func (c *BlogController) ManageEdit() {
|
||||
doc.ModifyTime = time.Now()
|
||||
doc.ModifyAt = c.Member.MemberId
|
||||
if err := doc.InsertOrUpdate("markdown", "release", "content", "modify_time", "modify_at"); err != nil {
|
||||
beego.Error("保存关联文档时出错 ->", err)
|
||||
logs.Error("保存关联文档时出错 ->", err)
|
||||
c.JsonResult(6004, "保存关联文档时出错")
|
||||
}
|
||||
}
|
||||
@@ -346,7 +347,7 @@ func (c *BlogController) ManageEdit() {
|
||||
blog.Modified = time.Now()
|
||||
|
||||
if err := blog.Save("blog_content", "blog_release", "modify_at", "modify_time", "version"); err != nil {
|
||||
beego.Error("保存文章失败 -> ", err)
|
||||
logs.Error("保存文章失败 -> ", err)
|
||||
c.JsonResult(6011, "保存文章失败")
|
||||
} else {
|
||||
c.JsonResult(0, "ok", blog)
|
||||
@@ -374,7 +375,7 @@ func (c *BlogController) ManageEdit() {
|
||||
if len(blog.AttachList) > 0 {
|
||||
returnJSON, err := json.Marshal(blog.AttachList)
|
||||
if err != nil {
|
||||
beego.Error("序列化文章附件时出错 ->", err)
|
||||
logs.Error("序列化文章附件时出错 ->", err)
|
||||
} else {
|
||||
c.Data["AttachList"] = template.JS(string(returnJSON))
|
||||
}
|
||||
@@ -384,7 +385,7 @@ func (c *BlogController) ManageEdit() {
|
||||
if conf.GetUploadFileSize() > 0 {
|
||||
c.Data["UploadFileSize"] = conf.GetUploadFileSize()
|
||||
} else {
|
||||
c.Data["UploadFileSize"] = "undefined";
|
||||
c.Data["UploadFileSize"] = "undefined"
|
||||
}
|
||||
c.Data["Model"] = blog
|
||||
}
|
||||
@@ -484,7 +485,7 @@ func (c *BlogController) Upload() {
|
||||
_, err := models.NewBlog().FindByIdAndMemberId(blogId, c.Member.MemberId)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("查询文章时出错 -> ", err)
|
||||
logs.Error("查询文章时出错 -> ", err)
|
||||
if err == orm.ErrNoRows {
|
||||
c.JsonResult(6006, "权限不足")
|
||||
}
|
||||
@@ -504,7 +505,7 @@ func (c *BlogController) Upload() {
|
||||
err = c.SaveToFile(name, filePath)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("SaveToFile => ", err)
|
||||
logs.Error("SaveToFile => ", err)
|
||||
c.JsonResult(6005, "保存文件失败")
|
||||
}
|
||||
|
||||
@@ -537,14 +538,14 @@ func (c *BlogController) Upload() {
|
||||
|
||||
if err := attachment.Insert(); err != nil {
|
||||
os.Remove(filePath)
|
||||
beego.Error("保存文件附件失败 -> ", err)
|
||||
logs.Error("保存文件附件失败 -> ", err)
|
||||
c.JsonResult(6006, "文件保存失败")
|
||||
}
|
||||
if attachment.HttpPath == "" {
|
||||
attachment.HttpPath = conf.URLForNotHost("BlogController.Download", ":id", blogId, ":attach_id", attachment.AttachmentId)
|
||||
|
||||
if err := attachment.Update(); err != nil {
|
||||
beego.Error("保存文件失败 -> ",attachment.FilePath, err)
|
||||
logs.Error("保存文件失败 -> ", attachment.FilePath, err)
|
||||
c.JsonResult(6005, "保存文件失败")
|
||||
}
|
||||
}
|
||||
@@ -581,7 +582,7 @@ func (c *BlogController) RemoveAttachment() {
|
||||
attach, err := models.NewAttachment().Find(attachId)
|
||||
|
||||
if err != nil {
|
||||
beego.Error(err)
|
||||
logs.Error(err)
|
||||
c.JsonResult(6002, "附件不存在")
|
||||
}
|
||||
|
||||
@@ -589,7 +590,7 @@ func (c *BlogController) RemoveAttachment() {
|
||||
_, err := models.NewBlog().FindByIdAndMemberId(attach.DocumentId, c.Member.MemberId)
|
||||
|
||||
if err != nil {
|
||||
beego.Error(err)
|
||||
logs.Error(err)
|
||||
c.JsonResult(6003, "文档不存在")
|
||||
}
|
||||
}
|
||||
@@ -601,7 +602,7 @@ func (c *BlogController) RemoveAttachment() {
|
||||
}
|
||||
|
||||
if err := attach.Delete(); err != nil {
|
||||
beego.Error(err)
|
||||
logs.Error(err)
|
||||
c.JsonResult(6005, "删除失败")
|
||||
}
|
||||
|
||||
@@ -639,7 +640,7 @@ func (c *BlogController) Download() {
|
||||
if err == orm.ErrNoRows {
|
||||
c.ShowErrorPage(404, "附件不存在")
|
||||
} else {
|
||||
beego.Error("查询附件时出现异常 -> ", err)
|
||||
logs.Error("查询附件时出现异常 -> ", err)
|
||||
c.ShowErrorPage(500, "查询附件时出现异常")
|
||||
}
|
||||
}
|
||||
@@ -647,7 +648,7 @@ func (c *BlogController) Download() {
|
||||
//如果是链接的文章,需要校验文档ID是否一致,如果不是,需要保证附件的项目ID为0且文档的ID等于博文ID
|
||||
if blog.BlogType == 1 && attachment.DocumentId != blog.DocumentId {
|
||||
c.ShowErrorPage(404, "附件不存在")
|
||||
} else if blog.BlogType != 1 && (attachment.BookId != 0 || attachment.DocumentId != blogId ) {
|
||||
} else if blog.BlogType != 1 && (attachment.BookId != 0 || attachment.DocumentId != blogId) {
|
||||
c.ShowErrorPage(404, "附件不存在")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user