获取或更新文档内容.
()
| 1048 | |
| 1049 | // 获取或更新文档内容. |
| 1050 | func (this *DocumentController) Content() { |
| 1051 | identify := this.Ctx.Input.Param(":key") |
| 1052 | docId, err := this.GetInt("doc_id") |
| 1053 | errMsg := "ok" |
| 1054 | if err != nil { |
| 1055 | docId, _ = strconv.Atoi(this.Ctx.Input.Param(":id")) |
| 1056 | } |
| 1057 | bookId := 0 |
| 1058 | //如果是超级管理员,则忽略权限 |
| 1059 | if this.Member.IsAdministrator() { |
| 1060 | book, err := models.NewBook().FindByFieldFirst("identify", identify) |
| 1061 | if err != nil { |
| 1062 | this.JsonResult(6002, "书籍不存在或权限不足") |
| 1063 | } |
| 1064 | bookId = book.BookId |
| 1065 | } else { |
| 1066 | bookResult, err := models.NewBookResult().FindByIdentify(identify, this.Member.MemberId) |
| 1067 | |
| 1068 | if err != nil || bookResult.RoleId == conf.BookObserver { |
| 1069 | beego.Error("FindByIdentify => ", err) |
| 1070 | this.JsonResult(6002, "书籍不存在或权限不足") |
| 1071 | } |
| 1072 | bookId = bookResult.BookId |
| 1073 | } |
| 1074 | |
| 1075 | if docId <= 0 { |
| 1076 | this.JsonResult(6001, "参数错误") |
| 1077 | } |
| 1078 | |
| 1079 | ModelStore := new(models.DocumentStore) |
| 1080 | |
| 1081 | if !this.Ctx.Input.IsPost() { |
| 1082 | doc, err := models.NewDocument().Find(docId) |
| 1083 | |
| 1084 | if err != nil { |
| 1085 | this.JsonResult(6003, "文档不存在") |
| 1086 | } |
| 1087 | attach, err := models.NewAttachment().FindListByDocumentId(doc.DocumentId) |
| 1088 | if err == nil { |
| 1089 | doc.AttachList = attach |
| 1090 | } |
| 1091 | |
| 1092 | //为了减少数据的传输量,这里Release和Content的内容置空,前端会根据markdown文本自动渲染 |
| 1093 | //doc.Release = "" |
| 1094 | //doc.Content = "" |
| 1095 | doc.Markdown = ModelStore.GetFiledById(doc.DocumentId, "markdown") |
| 1096 | this.JsonResult(0, errMsg, doc) |
| 1097 | } |
| 1098 | |
| 1099 | //更新文档内容 |
| 1100 | markdown := strings.TrimSpace(this.GetString("markdown", "")) |
| 1101 | content := this.GetString("html") |
| 1102 | |
| 1103 | // 文档拆分 |
| 1104 | gq, err := goquery.NewDocumentFromReader(strings.NewReader(content)) |
| 1105 | if err == nil { |
| 1106 | seg := gq.Find("bookstack-split").Text() |
| 1107 | if strings.Contains(seg, "#") { |
nothing calls this directly
no test coverage detected