mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-09-18 09:44:26 +08:00
refactor and update i18n, to be continue
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/beego/i18n"
|
||||
"github.com/mindoc-org/mindoc/utils/sqltil"
|
||||
|
||||
"net/http"
|
||||
@@ -153,14 +154,14 @@ func (c *BookController) SaveBook() {
|
||||
itemId, _ := c.GetInt("itemId")
|
||||
|
||||
if strings.Count(description, "") > 500 {
|
||||
c.JsonResult(6004, "项目描述不能大于500字")
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.project_desc_tips"))
|
||||
}
|
||||
if commentStatus != "open" && commentStatus != "closed" && commentStatus != "group_only" && commentStatus != "registered_only" {
|
||||
commentStatus = "closed"
|
||||
}
|
||||
|
||||
if !models.NewItemsets().Exist(itemId) {
|
||||
c.JsonResult(6006, "项目空间不存在")
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.project_space_not_exist"))
|
||||
}
|
||||
if editor != "markdown" && editor != "html" {
|
||||
editor = "markdown"
|
||||
@@ -449,25 +450,25 @@ func (c *BookController) Create() {
|
||||
itemId, _ := c.GetInt("itemId")
|
||||
|
||||
if bookName == "" {
|
||||
c.JsonResult(6001, "项目名称不能为空")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.project_name_empty"))
|
||||
}
|
||||
if identify == "" {
|
||||
c.JsonResult(6002, "项目标识不能为空")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.project_id_empty"))
|
||||
}
|
||||
if ok, err := regexp.MatchString(`^[a-z]+[a-zA-Z0-9_\-]*$`, identify); !ok || err != nil {
|
||||
c.JsonResult(6003, "项目标识只能包含小写字母、数字,以及“-”和“_”符号,并且只能小写字母开头")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.project_id_tips"))
|
||||
}
|
||||
if strings.Count(identify, "") > 50 {
|
||||
c.JsonResult(6004, "文档标识不能超过50字")
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.project_id_length"))
|
||||
}
|
||||
if strings.Count(description, "") > 500 {
|
||||
c.JsonResult(6004, "项目描述不能大于500字")
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.project_desc_tips"))
|
||||
}
|
||||
if privatelyOwned != 0 && privatelyOwned != 1 {
|
||||
privatelyOwned = 1
|
||||
}
|
||||
if !models.NewItemsets().Exist(itemId) {
|
||||
c.JsonResult(6005, "项目空间不存在")
|
||||
c.JsonResult(6005, i18n.Tr(c.Lang, "message.project_space_not_exist"))
|
||||
}
|
||||
if commentStatus != "open" && commentStatus != "closed" && commentStatus != "group_only" && commentStatus != "registered_only" {
|
||||
commentStatus = "closed"
|
||||
@@ -504,7 +505,7 @@ func (c *BookController) Create() {
|
||||
}
|
||||
|
||||
if books, _ := book.FindByField("identify", identify, "book_id"); len(books) > 0 {
|
||||
c.JsonResult(6006, "项目标识已存在")
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.project_id_existed"))
|
||||
}
|
||||
|
||||
book.BookName = bookName
|
||||
@@ -528,7 +529,7 @@ func (c *BookController) Create() {
|
||||
|
||||
if err := book.Insert(); err != nil {
|
||||
logs.Error("Insert => ", err)
|
||||
c.JsonResult(6005, "保存项目失败")
|
||||
c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed"))
|
||||
}
|
||||
bookResult, err := models.NewBookResult().FindByIdentify(book.Identify, c.Member.MemberId)
|
||||
|
||||
@@ -585,22 +586,22 @@ func (c *BookController) Import() {
|
||||
itemId, _ := c.GetInt("itemId")
|
||||
|
||||
if bookName == "" {
|
||||
c.JsonResult(6001, "项目名称不能为空")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.project_name_empty"))
|
||||
}
|
||||
if len([]rune(bookName)) > 500 {
|
||||
c.JsonResult(6002, "项目名称不能大于500字")
|
||||
}
|
||||
if identify == "" {
|
||||
c.JsonResult(6002, "项目标识不能为空")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.project_id_empty"))
|
||||
}
|
||||
if ok, err := regexp.MatchString(`^[a-z]+[a-zA-Z0-9_\-]*$`, identify); !ok || err != nil {
|
||||
c.JsonResult(6003, "项目标识只能包含小写字母、数字,以及“-”和“_”符号,并且只能小写字母开头")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.project_id_tips"))
|
||||
}
|
||||
if !models.NewItemsets().Exist(itemId) {
|
||||
c.JsonResult(6007, "项目空间不存在")
|
||||
c.JsonResult(6007, i18n.Tr(c.Lang, "message.project_space_not_exist"))
|
||||
}
|
||||
if strings.Count(identify, "") > 50 {
|
||||
c.JsonResult(6004, "文档标识不能超过50字")
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.project_id_length"))
|
||||
}
|
||||
|
||||
ext := filepath.Ext(moreFile.Filename)
|
||||
@@ -610,7 +611,7 @@ func (c *BookController) Import() {
|
||||
}
|
||||
|
||||
if books, _ := models.NewBook().FindByField("identify", identify, "book_id"); len(books) > 0 {
|
||||
c.JsonResult(6006, "项目标识已存在")
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.project_id_existed"))
|
||||
}
|
||||
|
||||
tempPath := filepath.Join(os.TempDir(), c.CruSession.SessionID())
|
||||
|
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/beego/i18n"
|
||||
"github.com/boombuler/barcode"
|
||||
"github.com/boombuler/barcode/qr"
|
||||
"github.com/mindoc-org/mindoc/conf"
|
||||
@@ -42,7 +43,7 @@ func (c *DocumentController) Index() {
|
||||
token := c.GetString("token")
|
||||
|
||||
if identify == "" {
|
||||
c.ShowErrorPage(404, "项目不存在或已删除")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
}
|
||||
|
||||
// 如果没有开启匿名访问则跳转到登录
|
||||
@@ -67,7 +68,7 @@ func (c *DocumentController) Index() {
|
||||
c.Data["Description"] = utils.AutoSummary(doc.Release, 120)
|
||||
}
|
||||
} else {
|
||||
c.Data["Title"] = "概要"
|
||||
c.Data["Title"] = i18n.Tr(c.Lang, "blog.summary")
|
||||
c.Data["Content"] = template.HTML(blackfriday.Run([]byte(bookResult.Description)))
|
||||
}
|
||||
|
||||
@@ -75,10 +76,10 @@ func (c *DocumentController) Index() {
|
||||
|
||||
if err != nil {
|
||||
if err == orm.ErrNoRows {
|
||||
c.ShowErrorPage(404, "当前项目没有文档")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.no_doc_in_cur_proj"))
|
||||
} else {
|
||||
logs.Error("生成项目文档树时出错 -> ", err)
|
||||
c.ShowErrorPage(500, "生成项目文档树时出错")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.build_doc_tree_error"))
|
||||
}
|
||||
}
|
||||
c.Data["Model"] = bookResult
|
||||
@@ -97,7 +98,7 @@ func (c *DocumentController) Read() {
|
||||
c.Data["DocumentId"] = id
|
||||
|
||||
if identify == "" || id == "" {
|
||||
c.ShowErrorPage(404, "项目不存或已删除")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
}
|
||||
|
||||
// 如果没有开启匿名访问则跳转到登录
|
||||
@@ -116,24 +117,24 @@ func (c *DocumentController) Read() {
|
||||
doc, err = doc.FromCacheById(docId)
|
||||
if err != nil || doc == nil {
|
||||
logs.Error("从缓存中读取文档时失败 ->", err)
|
||||
c.ShowErrorPage(404, "文档不存在或已删除")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.doc_not_exist"))
|
||||
return
|
||||
}
|
||||
} else {
|
||||
doc, err = doc.FromCacheByIdentify(id, bookResult.BookId)
|
||||
if err != nil || doc == nil {
|
||||
if err == orm.ErrNoRows {
|
||||
c.ShowErrorPage(404, "文档不存在或已删除")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.doc_not_exist"))
|
||||
} else {
|
||||
logs.Error("从缓存查询文档时出错 ->", err)
|
||||
c.ShowErrorPage(500, "未知异常")
|
||||
logs.Error("从数据库查询文档时出错 ->", err)
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.unknown_exception"))
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if doc.BookId != bookResult.BookId {
|
||||
c.ShowErrorPage(404, "文档不存在或已删除")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.doc_not_exist"))
|
||||
}
|
||||
|
||||
doc.Processor()
|
||||
@@ -163,7 +164,7 @@ func (c *DocumentController) Read() {
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
logs.Error("生成项目文档树时出错 ->", err)
|
||||
|
||||
c.ShowErrorPage(500, "生成项目文档树时出错")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.build_doc_tree_error"))
|
||||
}
|
||||
|
||||
c.Data["Description"] = utils.AutoSummary(doc.Release, 120)
|
||||
@@ -180,7 +181,7 @@ func (c *DocumentController) Edit() {
|
||||
|
||||
identify := c.Ctx.Input.Param(":key")
|
||||
if identify == "" {
|
||||
c.ShowErrorPage(404, "无法解析项目标识")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.project_id_error"))
|
||||
}
|
||||
|
||||
bookResult := models.NewBookResult()
|
||||
@@ -190,7 +191,7 @@ func (c *DocumentController) Edit() {
|
||||
if c.Member.IsAdministrator() {
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
if err != nil {
|
||||
c.JsonResult(6002, "项目不存在或权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit"))
|
||||
}
|
||||
|
||||
bookResult = models.NewBookResult().ToBookResult(*book)
|
||||
@@ -199,15 +200,15 @@ func (c *DocumentController) Edit() {
|
||||
|
||||
if err != nil {
|
||||
if err == orm.ErrNoRows || err == models.ErrPermissionDenied {
|
||||
c.ShowErrorPage(403, "项目不存在或没有权限")
|
||||
c.ShowErrorPage(403, i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit"))
|
||||
} else {
|
||||
logs.Error("查询项目时出错 -> ", err)
|
||||
c.ShowErrorPage(500, "查询项目时出错")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.system_error"))
|
||||
}
|
||||
return
|
||||
}
|
||||
if bookResult.RoleId == conf.BookObserver {
|
||||
c.JsonResult(6002, "项目不存在或权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,11 +262,11 @@ func (c *DocumentController) Create() {
|
||||
isOpen, _ := c.GetInt("is_open", 0)
|
||||
|
||||
if identify == "" {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
if docName == "" {
|
||||
c.JsonResult(6004, "文档名称不能为空")
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.doc_name_empty"))
|
||||
}
|
||||
|
||||
bookId := 0
|
||||
@@ -275,7 +276,7 @@ func (c *DocumentController) Create() {
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
c.JsonResult(6002, "项目不存在或权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_existed_or_no_permit"))
|
||||
}
|
||||
|
||||
bookId = book.BookId
|
||||
@@ -284,7 +285,7 @@ func (c *DocumentController) Create() {
|
||||
|
||||
if err != nil || bookResult.RoleId == conf.BookObserver {
|
||||
logs.Error("FindByIdentify => ", err)
|
||||
c.JsonResult(6002, "项目不存在或权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_existed_or_no_permit"))
|
||||
}
|
||||
|
||||
bookId = bookResult.BookId
|
||||
@@ -292,18 +293,18 @@ func (c *DocumentController) Create() {
|
||||
|
||||
if docIdentify != "" {
|
||||
if ok, err := regexp.MatchString(`[a-z]+[a-zA-Z0-9_.\-]*$`, docIdentify); !ok || err != nil {
|
||||
c.JsonResult(6003, "文档标识只能包含小写字母、数字,以及“-”、“.”和“_”符号")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.project_id_tips"))
|
||||
}
|
||||
|
||||
d, _ := models.NewDocument().FindByIdentityFirst(docIdentify, bookId)
|
||||
if d.DocumentId > 0 && d.DocumentId != docId {
|
||||
c.JsonResult(6006, "文档标识已被使用")
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.project_id_existed"))
|
||||
}
|
||||
}
|
||||
if parentId > 0 {
|
||||
doc, err := models.NewDocument().Find(parentId)
|
||||
if err != nil || doc.BookId != bookId {
|
||||
c.JsonResult(6003, "父分类不存在")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.parent_id_not_existed"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,7 +329,7 @@ func (c *DocumentController) Create() {
|
||||
|
||||
if err := document.InsertOrUpdate(); err != nil {
|
||||
logs.Error("添加或更新文档时出错 -> ", err)
|
||||
c.JsonResult(6005, "保存失败")
|
||||
c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed"))
|
||||
} else {
|
||||
c.JsonResult(0, "ok", document)
|
||||
}
|
||||
@@ -341,7 +342,7 @@ func (c *DocumentController) Upload() {
|
||||
isAttach := true
|
||||
|
||||
if identify == "" {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
name := "editormd-file-file"
|
||||
@@ -351,7 +352,7 @@ func (c *DocumentController) Upload() {
|
||||
name = "editormd-image-file"
|
||||
file, moreFile, err = c.GetFile(name)
|
||||
if err == http.ErrMissingFile || moreFile == nil {
|
||||
c.JsonResult(6003, "没有发现需要上传的文件")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.upload_file_empty"))
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -367,17 +368,17 @@ func (c *DocumentController) Upload() {
|
||||
}
|
||||
|
||||
if conf.GetUploadFileSize() > 0 && moreFile.Size > conf.GetUploadFileSize() {
|
||||
c.JsonResult(6009, "文件大小超过了限定的最大值")
|
||||
c.JsonResult(6009, i18n.Tr(c.Lang, "message.upload_file_size_limit"))
|
||||
}
|
||||
|
||||
ext := filepath.Ext(moreFile.Filename)
|
||||
//文件必须带有后缀名
|
||||
if ext == "" {
|
||||
c.JsonResult(6003, "无法解析文件的格式")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.upload_file_type_error"))
|
||||
}
|
||||
//如果文件类型设置为 * 标识不限制文件类型
|
||||
if conf.IsAllowUploadFileExt(ext) == false {
|
||||
c.JsonResult(6004, "不允许的文件类型")
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.upload_file_type_error"))
|
||||
}
|
||||
|
||||
bookId := 0
|
||||
@@ -387,7 +388,7 @@ func (c *DocumentController) Upload() {
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
|
||||
if err != nil {
|
||||
c.JsonResult(6006, "文档不存在或权限不足")
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.doc_not_exist_or_no_permit"))
|
||||
}
|
||||
|
||||
bookId = book.BookId
|
||||
@@ -397,7 +398,7 @@ func (c *DocumentController) Upload() {
|
||||
if err != nil {
|
||||
logs.Error("DocumentController.Edit => ", err)
|
||||
if err == orm.ErrNoRows {
|
||||
c.JsonResult(6006, "权限不足")
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
|
||||
c.JsonResult(6001, err.Error())
|
||||
@@ -405,7 +406,7 @@ func (c *DocumentController) Upload() {
|
||||
|
||||
// 如果没有编辑权限
|
||||
if book.RoleId != conf.BookEditor && book.RoleId != conf.BookAdmin && book.RoleId != conf.BookFounder {
|
||||
c.JsonResult(6006, "权限不足")
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
|
||||
bookId = book.BookId
|
||||
@@ -414,11 +415,11 @@ func (c *DocumentController) Upload() {
|
||||
if docId > 0 {
|
||||
doc, err := models.NewDocument().Find(docId)
|
||||
if err != nil {
|
||||
c.JsonResult(6007, "文档不存在")
|
||||
c.JsonResult(6007, i18n.Tr(c.Lang, "message.doc_not_exist"))
|
||||
}
|
||||
|
||||
if doc.BookId != bookId {
|
||||
c.JsonResult(6008, "文档不属于指定的项目")
|
||||
c.JsonResult(6008, i18n.Tr(c.Lang, "message.doc_not_belong_project"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,7 +441,7 @@ func (c *DocumentController) Upload() {
|
||||
|
||||
if err != nil {
|
||||
logs.Error("保存文件失败 -> ", err)
|
||||
c.JsonResult(6005, "保存文件失败")
|
||||
c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed"))
|
||||
}
|
||||
|
||||
attachment := models.NewAttachment()
|
||||
@@ -473,7 +474,7 @@ func (c *DocumentController) Upload() {
|
||||
if err != nil {
|
||||
os.Remove(filePath)
|
||||
logs.Error("文件保存失败 ->", err)
|
||||
c.JsonResult(6006, "文件保存失败")
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.failed"))
|
||||
}
|
||||
|
||||
if attachment.HttpPath == "" {
|
||||
@@ -481,7 +482,7 @@ func (c *DocumentController) Upload() {
|
||||
|
||||
if err := attachment.Update(); err != nil {
|
||||
logs.Error("保存文件失败 ->", err)
|
||||
c.JsonResult(6005, "保存文件失败")
|
||||
c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -523,10 +524,10 @@ func (c *DocumentController) DownloadAttachment() {
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
if err != nil {
|
||||
if err == orm.ErrNoRows {
|
||||
c.ShowErrorPage(404, "项目不存在或已删除")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
} else {
|
||||
logs.Error("查找项目时出错 ->", err)
|
||||
c.ShowErrorPage(500, "系统错误")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.system_error"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,7 +535,7 @@ func (c *DocumentController) DownloadAttachment() {
|
||||
if c.Member == nil || c.Member.Role != conf.MemberSuperRole {
|
||||
// 如果项目是私有的,并且 token 不正确
|
||||
if (book.PrivatelyOwned == 1 && token == "") || (book.PrivatelyOwned == 1 && book.PrivateToken != token) {
|
||||
c.ShowErrorPage(403, "权限不足")
|
||||
c.ShowErrorPage(403, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -549,14 +550,14 @@ func (c *DocumentController) DownloadAttachment() {
|
||||
if err != nil {
|
||||
logs.Error("查找附件时出错 -> ", err)
|
||||
if err == orm.ErrNoRows {
|
||||
c.ShowErrorPage(404, "附件不存在或已删除")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.attachment_not_exist"))
|
||||
} else {
|
||||
c.ShowErrorPage(500, "查找附件时出错")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.system_error"))
|
||||
}
|
||||
}
|
||||
|
||||
if attachment.BookId != bookId {
|
||||
c.ShowErrorPage(404, "附件不存在或已删除")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.attachment_not_exist"))
|
||||
}
|
||||
|
||||
c.Ctx.Output.Download(filepath.Join(conf.WorkingDirectory, attachment.FilePath), attachment.FileName)
|
||||
@@ -569,39 +570,39 @@ func (c *DocumentController) RemoveAttachment() {
|
||||
attachId, _ := c.GetInt("attach_id")
|
||||
|
||||
if attachId <= 0 {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
attach, err := models.NewAttachment().Find(attachId)
|
||||
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
c.JsonResult(6002, "附件不存在")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.attachment_not_exist"))
|
||||
}
|
||||
|
||||
document, err := models.NewDocument().Find(attach.DocumentId)
|
||||
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
c.JsonResult(6003, "文档不存在")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.doc_not_exist"))
|
||||
}
|
||||
|
||||
if c.Member.Role != conf.MemberSuperRole {
|
||||
rel, err := models.NewRelationship().FindByBookIdAndMemberId(document.BookId, c.Member.MemberId)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
c.JsonResult(6004, "权限不足")
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
|
||||
if rel.RoleId == conf.BookObserver {
|
||||
c.JsonResult(6004, "权限不足")
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
}
|
||||
|
||||
err = attach.Delete()
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
c.JsonResult(6005, "删除失败")
|
||||
c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed"))
|
||||
}
|
||||
|
||||
os.Remove(filepath.Join(conf.WorkingDirectory, attach.FilePath))
|
||||
@@ -623,7 +624,7 @@ func (c *DocumentController) Delete() {
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
if err != nil {
|
||||
logs.Error("FindByIdentify => ", err)
|
||||
c.JsonResult(6002, "项目不存在或权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit"))
|
||||
}
|
||||
|
||||
bookId = book.BookId
|
||||
@@ -632,31 +633,31 @@ func (c *DocumentController) Delete() {
|
||||
|
||||
if err != nil || bookResult.RoleId == conf.BookObserver {
|
||||
logs.Error("FindByIdentify => ", err)
|
||||
c.JsonResult(6002, "项目不存在或权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit"))
|
||||
}
|
||||
|
||||
bookId = bookResult.BookId
|
||||
}
|
||||
|
||||
if docId <= 0 {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
doc, err := models.NewDocument().Find(docId)
|
||||
|
||||
if err != nil {
|
||||
logs.Error("Delete => ", err)
|
||||
c.JsonResult(6003, "删除失败")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.failed"))
|
||||
}
|
||||
// 如果文档所属项目错误
|
||||
if doc.BookId != bookId {
|
||||
c.JsonResult(6004, "参数错误")
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
// 递归删除项目下的文档以及子文档
|
||||
err = doc.RecursiveDocument(doc.DocumentId)
|
||||
if err != nil {
|
||||
c.JsonResult(6005, "删除失败")
|
||||
c.JsonResult(6005, i18n.Tr(c.Lang, "message.failed"))
|
||||
}
|
||||
|
||||
// 重置文档数量统计
|
||||
@@ -682,7 +683,7 @@ func (c *DocumentController) Content() {
|
||||
if c.Member.IsAdministrator() {
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
if err != nil || book == nil {
|
||||
c.JsonResult(6002, "项目不存在或权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -693,7 +694,7 @@ func (c *DocumentController) Content() {
|
||||
|
||||
if err != nil || bookResult.RoleId == conf.BookObserver {
|
||||
logs.Error("项目不存在或权限不足 -> ", err)
|
||||
c.JsonResult(6002, "项目不存在或权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit"))
|
||||
}
|
||||
|
||||
bookId = bookResult.BookId
|
||||
@@ -701,7 +702,7 @@ func (c *DocumentController) Content() {
|
||||
}
|
||||
|
||||
if docId <= 0 {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
if c.Ctx.Input.IsPost() {
|
||||
@@ -713,17 +714,17 @@ func (c *DocumentController) Content() {
|
||||
doc, err := models.NewDocument().Find(docId)
|
||||
|
||||
if err != nil || doc == nil {
|
||||
c.JsonResult(6003, "读取文档错误")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.read_file_error"))
|
||||
return
|
||||
}
|
||||
|
||||
if doc.BookId != bookId {
|
||||
c.JsonResult(6004, "保存的文档不属于指定项目")
|
||||
c.JsonResult(6004, i18n.Tr(c.Lang, "message.dock_not_belong_project"))
|
||||
}
|
||||
|
||||
if doc.Version != version && !strings.EqualFold(isCover, "yes") {
|
||||
logs.Info("%d|", version, doc.Version)
|
||||
c.JsonResult(6005, "文档已被修改确定要覆盖吗?")
|
||||
c.JsonResult(6005, i18n.Tr(c.Lang, "message.confirm_override_doc"))
|
||||
}
|
||||
|
||||
history := models.NewDocumentHistory()
|
||||
@@ -736,7 +737,7 @@ func (c *DocumentController) Content() {
|
||||
history.ParentId = doc.ParentId
|
||||
history.Version = time.Now().Unix()
|
||||
history.Action = "modify"
|
||||
history.ActionName = "修改文档"
|
||||
history.ActionName = i18n.Tr(c.Lang, "doc.modify_doc")
|
||||
|
||||
if markdown == "" && content != "" {
|
||||
doc.Markdown = content
|
||||
@@ -750,7 +751,7 @@ func (c *DocumentController) Content() {
|
||||
|
||||
if err := doc.InsertOrUpdate(); err != nil {
|
||||
logs.Error("InsertOrUpdate => ", err)
|
||||
c.JsonResult(6006, "保存失败")
|
||||
c.JsonResult(6006, i18n.Tr(c.Lang, "message.failed"))
|
||||
}
|
||||
|
||||
// 如果启用了文档历史,则添加历史文档
|
||||
@@ -769,7 +770,7 @@ func (c *DocumentController) Content() {
|
||||
go func() {
|
||||
err := doc.ReleaseContent()
|
||||
if err == nil {
|
||||
logs.Informational("文档自动发布成功 -> document_id=%d;document_name=%s", doc.DocumentId, doc.DocumentName)
|
||||
logs.Informational(i18n.Tr(c.Lang, "message.doc_auto_published")+"-> document_id=%d;document_name=%s", doc.DocumentId, doc.DocumentName)
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -779,7 +780,7 @@ func (c *DocumentController) Content() {
|
||||
|
||||
doc, err := models.NewDocument().Find(docId)
|
||||
if err != nil {
|
||||
c.JsonResult(6003, "文档不存在")
|
||||
c.JsonResult(6003, i18n.Tr(c.Lang, "message.doc_not_exist"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -797,7 +798,7 @@ func (c *DocumentController) Export() {
|
||||
|
||||
identify := c.Ctx.Input.Param(":key")
|
||||
if identify == "" {
|
||||
c.ShowErrorPage(500, "参数错误")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
output := c.GetString("output")
|
||||
@@ -809,7 +810,7 @@ func (c *DocumentController) Export() {
|
||||
return
|
||||
}
|
||||
if !conf.GetEnableExport() {
|
||||
c.ShowErrorPage(500, "系统没有开启导出功能")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "export_func_disable"))
|
||||
}
|
||||
|
||||
bookResult := models.NewBookResult()
|
||||
@@ -817,10 +818,10 @@ func (c *DocumentController) Export() {
|
||||
book, err := models.NewBook().FindByIdentify(identify)
|
||||
if err != nil {
|
||||
if err == orm.ErrNoRows {
|
||||
c.ShowErrorPage(404, "项目不存在")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
} else {
|
||||
logs.Error("查找项目时出错 ->", err)
|
||||
c.ShowErrorPage(500, "查找项目时出错")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.system_error"))
|
||||
}
|
||||
}
|
||||
bookResult = models.NewBookResult().ToBookResult(*book)
|
||||
@@ -828,7 +829,7 @@ func (c *DocumentController) Export() {
|
||||
bookResult = c.isReadable(identify, token)
|
||||
}
|
||||
if !bookResult.IsDownload {
|
||||
c.ShowErrorPage(200, "当前项目没有开启导出功能")
|
||||
c.ShowErrorPage(200, i18n.Tr(c.Lang, "message.cur_project_export_func_disable"))
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(bookResult.Cover, "http:://") && !strings.HasPrefix(bookResult.Cover, "https:://") {
|
||||
@@ -837,12 +838,12 @@ func (c *DocumentController) Export() {
|
||||
|
||||
if output == "markdown" {
|
||||
if bookResult.Editor != "markdown" {
|
||||
c.ShowErrorPage(500, "当前项目不支持Markdown编辑器")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.cur_project_not_support_md"))
|
||||
}
|
||||
p, err := bookResult.ExportMarkdown(c.CruSession.SessionID())
|
||||
|
||||
if err != nil {
|
||||
c.ShowErrorPage(500, "导出文档失败")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.failed"))
|
||||
}
|
||||
c.Ctx.Output.Download(p, bookResult.BookName+".zip")
|
||||
|
||||
@@ -875,15 +876,15 @@ func (c *DocumentController) Export() {
|
||||
|
||||
} else if output == "pdf" || output == "epub" || output == "docx" || output == "mobi" {
|
||||
if err := models.BackgroundConvert(c.CruSession.SessionID(), bookResult); err != nil && err != gopool.ErrHandlerIsExist {
|
||||
c.ShowErrorPage(500, "导出失败,请查看系统日志")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.export_failed"))
|
||||
}
|
||||
|
||||
c.ShowErrorPage(200, "文档正在后台转换,请稍后再下载")
|
||||
c.ShowErrorPage(200, i18n.Tr(c.Lang, "message.file_converting"))
|
||||
} else {
|
||||
c.ShowErrorPage(200, "不支持的文件格式")
|
||||
c.ShowErrorPage(200, i18n.Tr(c.Lang, "message.unsupport_file_type"))
|
||||
}
|
||||
|
||||
c.ShowErrorPage(404, "项目没有导出文件")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.no_exportable_file"))
|
||||
}
|
||||
|
||||
// 生成项目访问的二维码
|
||||
@@ -894,20 +895,20 @@ func (c *DocumentController) QrCode() {
|
||||
|
||||
book, err := models.NewBook().FindByIdentify(identify)
|
||||
if err != nil || book.BookId <= 0 {
|
||||
c.ShowErrorPage(404, "项目不存在")
|
||||
c.ShowErrorPage(404, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
}
|
||||
|
||||
uri := conf.URLFor("DocumentController.Index", ":key", identify)
|
||||
code, err := qr.Encode(uri, qr.L, qr.Unicode)
|
||||
if err != nil {
|
||||
logs.Error("生成二维码失败 ->", err)
|
||||
c.ShowErrorPage(500, "生成二维码失败")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.gen_qrcode_failed"))
|
||||
}
|
||||
|
||||
code, err = barcode.Scale(code, 150, 150)
|
||||
if err != nil {
|
||||
logs.Error("生成二维码失败 ->", err)
|
||||
c.ShowErrorPage(500, "生成二维码失败")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.gen_qrcode_failed"))
|
||||
}
|
||||
|
||||
c.Ctx.ResponseWriter.Header().Set("Content-Type", "image/png")
|
||||
@@ -917,7 +918,7 @@ func (c *DocumentController) QrCode() {
|
||||
err = png.Encode(c.Ctx.ResponseWriter, code)
|
||||
if err != nil {
|
||||
logs.Error("生成二维码失败 ->", err)
|
||||
c.ShowErrorPage(500, "生成二维码失败")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.gen_qrcode_failed"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -930,7 +931,7 @@ func (c *DocumentController) Search() {
|
||||
keyword := strings.TrimSpace(c.GetString("keyword"))
|
||||
|
||||
if identify == "" {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
if !c.EnableAnonymous && !c.isUserLoggedIn() {
|
||||
@@ -943,11 +944,11 @@ func (c *DocumentController) Search() {
|
||||
docs, err := models.NewDocumentSearchResult().SearchDocument(keyword, bookResult.BookId)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
c.JsonResult(6002, "搜索结果错误")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.search_result_error"))
|
||||
}
|
||||
|
||||
if len(docs) < 0 {
|
||||
c.JsonResult(404, "没有数据库")
|
||||
c.JsonResult(404, i18n.Tr(c.Lang, "message.no_data"))
|
||||
}
|
||||
|
||||
for _, doc := range docs {
|
||||
@@ -977,7 +978,7 @@ func (c *DocumentController) History() {
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
if err != nil {
|
||||
logs.Error("查找项目失败 ->", err)
|
||||
c.Data["ErrorMessage"] = "项目不存在或权限不足"
|
||||
c.Data["ErrorMessage"] = i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -987,7 +988,7 @@ func (c *DocumentController) History() {
|
||||
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
||||
if err != nil || bookResult.RoleId == conf.BookObserver {
|
||||
logs.Error("查找项目失败 ->", err)
|
||||
c.Data["ErrorMessage"] = "项目不存在或权限不足"
|
||||
c.Data["ErrorMessage"] = i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -996,27 +997,27 @@ func (c *DocumentController) History() {
|
||||
}
|
||||
|
||||
if docId <= 0 {
|
||||
c.Data["ErrorMessage"] = "参数错误"
|
||||
c.Data["ErrorMessage"] = i18n.Tr(c.Lang, "message.param_error")
|
||||
return
|
||||
}
|
||||
|
||||
doc, err := models.NewDocument().Find(docId)
|
||||
if err != nil {
|
||||
logs.Error("Delete => ", err)
|
||||
c.Data["ErrorMessage"] = "获取历史失败"
|
||||
c.Data["ErrorMessage"] = i18n.Tr(c.Lang, "message.get_doc_his_failed")
|
||||
return
|
||||
}
|
||||
|
||||
// 如果文档所属项目错误
|
||||
if doc.BookId != bookId {
|
||||
c.Data["ErrorMessage"] = "参数错误"
|
||||
c.Data["ErrorMessage"] = i18n.Tr(c.Lang, "message.param_error")
|
||||
return
|
||||
}
|
||||
|
||||
histories, totalCount, err := models.NewDocumentHistory().FindToPager(docId, pageIndex, conf.PageSize)
|
||||
if err != nil {
|
||||
logs.Error("分页查找文档历史失败 ->", err)
|
||||
c.Data["ErrorMessage"] = "获取历史失败"
|
||||
c.Data["ErrorMessage"] = i18n.Tr(c.Lang, "message.get_doc_his_failed")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1040,7 +1041,7 @@ func (c *DocumentController) DeleteHistory() {
|
||||
historyId, _ := c.GetInt("history_id", 0)
|
||||
|
||||
if historyId <= 0 {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
bookId := 0
|
||||
@@ -1050,7 +1051,7 @@ func (c *DocumentController) DeleteHistory() {
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
if err != nil {
|
||||
logs.Error("查找项目失败 ->", err)
|
||||
c.JsonResult(6002, "项目不存在或权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit"))
|
||||
}
|
||||
|
||||
bookId = book.BookId
|
||||
@@ -1058,31 +1059,31 @@ func (c *DocumentController) DeleteHistory() {
|
||||
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
||||
if err != nil || bookResult.RoleId == conf.BookObserver {
|
||||
logs.Error("查找项目失败 ->", err)
|
||||
c.JsonResult(6002, "项目不存在或权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit"))
|
||||
}
|
||||
|
||||
bookId = bookResult.BookId
|
||||
}
|
||||
|
||||
if docId <= 0 {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
doc, err := models.NewDocument().Find(docId)
|
||||
if err != nil {
|
||||
logs.Error("Delete => ", err)
|
||||
c.JsonResult(6001, "获取历史失败")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.get_doc_his_failed"))
|
||||
}
|
||||
|
||||
// 如果文档所属项目错误
|
||||
if doc.BookId != bookId {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
err = models.NewDocumentHistory().Delete(historyId, docId)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
c.JsonResult(6002, "删除失败")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.failed"))
|
||||
}
|
||||
|
||||
c.JsonResult(0, "ok")
|
||||
@@ -1099,7 +1100,7 @@ func (c *DocumentController) RestoreHistory() {
|
||||
historyId, _ := c.GetInt("history_id", 0)
|
||||
|
||||
if historyId <= 0 {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
bookId := 0
|
||||
@@ -1108,7 +1109,7 @@ func (c *DocumentController) RestoreHistory() {
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
if err != nil {
|
||||
logs.Error("FindByIdentify => ", err)
|
||||
c.JsonResult(6002, "项目不存在或权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit"))
|
||||
}
|
||||
|
||||
bookId = book.BookId
|
||||
@@ -1116,31 +1117,31 @@ func (c *DocumentController) RestoreHistory() {
|
||||
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
||||
if err != nil || bookResult.RoleId == conf.BookObserver {
|
||||
logs.Error("FindByIdentify => ", err)
|
||||
c.JsonResult(6002, "项目不存在或权限不足")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist_or_no_permit"))
|
||||
}
|
||||
|
||||
bookId = bookResult.BookId
|
||||
}
|
||||
|
||||
if docId <= 0 {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
doc, err := models.NewDocument().Find(docId)
|
||||
if err != nil {
|
||||
logs.Error("Delete => ", err)
|
||||
c.JsonResult(6001, "获取历史失败")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.get_doc_his_failed"))
|
||||
}
|
||||
|
||||
// 如果文档所属项目错误
|
||||
if doc.BookId != bookId {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
err = models.NewDocumentHistory().Restore(historyId, docId, c.Member.MemberId)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
c.JsonResult(6002, "删除失败")
|
||||
c.JsonResult(6002, i18n.Tr(c.Lang, "message.failed"))
|
||||
}
|
||||
|
||||
c.JsonResult(0, "ok", doc)
|
||||
@@ -1162,7 +1163,7 @@ func (c *DocumentController) Compare() {
|
||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||
if err != nil {
|
||||
logs.Error("DocumentController.Compare => ", err)
|
||||
c.ShowErrorPage(403, "权限不足")
|
||||
c.ShowErrorPage(403, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1173,7 +1174,7 @@ func (c *DocumentController) Compare() {
|
||||
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
||||
if err != nil || bookResult.RoleId == conf.BookObserver {
|
||||
logs.Error("FindByIdentify => ", err)
|
||||
c.ShowErrorPage(403, "权限不足")
|
||||
c.ShowErrorPage(403, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1183,7 +1184,7 @@ func (c *DocumentController) Compare() {
|
||||
}
|
||||
|
||||
if historyId <= 0 {
|
||||
c.ShowErrorPage(60002, "参数错误")
|
||||
c.ShowErrorPage(60002, i18n.Tr(c.Lang, "message.param_error"))
|
||||
}
|
||||
|
||||
history, err := models.NewDocumentHistory().Find(historyId)
|
||||
@@ -1194,7 +1195,7 @@ func (c *DocumentController) Compare() {
|
||||
|
||||
doc, err := models.NewDocument().Find(history.DocumentId)
|
||||
if err != nil || doc == nil || doc.BookId != bookId {
|
||||
c.ShowErrorPage(60002, "文档不存在或已删除")
|
||||
c.ShowErrorPage(60002, i18n.Tr(c.Lang, "message.doc_not_exist"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1216,7 +1217,7 @@ func (c *DocumentController) isReadable(identify, token string) *models.BookResu
|
||||
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
c.ShowErrorPage(500, "项目不存在")
|
||||
c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.item_not_exist"))
|
||||
}
|
||||
bookResult := models.NewBookResult().ToBookResult(*book)
|
||||
isOk := false
|
||||
@@ -1241,13 +1242,13 @@ func (c *DocumentController) isReadable(identify, token string) *models.BookResu
|
||||
c.SetSession(identify, token)
|
||||
} else if token, ok := c.GetSession(identify).(string); !ok || !strings.EqualFold(token, book.PrivateToken) {
|
||||
logs.Info("尝试访问文档但权限不足 ->", identify, token)
|
||||
c.ShowErrorPage(403, "权限不足")
|
||||
c.ShowErrorPage(403, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
} else if password := c.GetString("bPassword", ""); !isOk && book.BookPassword != "" && password != "" {
|
||||
|
||||
//如果设置了密码,则判断密码是否正确
|
||||
if book.BookPassword != password {
|
||||
c.JsonResult(5001, "密码错误")
|
||||
c.JsonResult(5001, i18n.Tr(c.Lang, "message.wrong_password"))
|
||||
} else {
|
||||
c.SetSession(identify, password)
|
||||
c.JsonResult(0, "OK")
|
||||
@@ -1266,7 +1267,7 @@ func (c *DocumentController) isReadable(identify, token string) *models.BookResu
|
||||
}
|
||||
} else {
|
||||
logs.Info("尝试访问文档但权限不足 ->", identify, token)
|
||||
c.ShowErrorPage(403, "权限不足")
|
||||
c.ShowErrorPage(403, i18n.Tr(c.Lang, "message.no_permission"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1280,7 +1281,7 @@ func promptUserToLogIn(c *DocumentController) {
|
||||
logs.Info(" Access will be redirected to login page(SessionId: " + c.CruSession.SessionID() + ").")
|
||||
|
||||
if c.IsAjax() {
|
||||
c.JsonResult(6000, "请重新登录。")
|
||||
c.JsonResult(6000, i18n.Tr(c.Lang, "message.need_relogin"))
|
||||
} else {
|
||||
c.Redirect(conf.URLFor("AccountController.Login")+"?url="+url.PathEscape(conf.BaseUrl+c.Ctx.Request.URL.RequestURI()), 302)
|
||||
}
|
||||
|
Reference in New Issue
Block a user