MCPcopy Index your code
hub / github.com/TruthHun/BookStack / Read

Method Read

controllers/api/CommonController.go:763–870  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

761}
762
763func (this *CommonController) Read() {
764 identify := this.GetString("identify")
765 slice := strings.Split(identify, "/")
766 fromAPP, _ := this.GetBool("from-app") // 是否来自app
767 enhanceRichtext, _ := this.GetBool("enhance-richtext")
768 filterLinks, _ := this.GetBool("links")
769 filterImages, _ := this.GetBool("images")
770 if len(slice) != 2 {
771 this.Response(http.StatusBadRequest, messageBadRequest)
772 }
773 bookIdentify, docIdentify := slice[0], slice[1]
774 if bookIdentify == "" || docIdentify == "" {
775 this.Response(http.StatusBadRequest, messageBadRequest)
776 }
777
778 // 1. 如果书籍是私有的,则必须是作者本人才能阅读,否则无法阅读
779 book := models.NewBook()
780 bookId, _ := strconv.Atoi(bookIdentify)
781 cols := []string{"book_id", "privately_owned", "member_id", "identify"}
782 if bookId > 0 {
783 book, _ = book.Find(bookId, cols...)
784 } else {
785 book, _ = book.FindByIdentify(bookIdentify, cols...)
786 }
787
788 if book.PrivatelyOwned == 1 && this.isLogin() != book.MemberId {
789 this.Response(http.StatusNotFound, messageNotFound)
790 }
791
792 doc := models.NewDocument()
793 docId, _ := strconv.Atoi(docIdentify)
794 if docId > 0 {
795 doc, _ = doc.Find(docId)
796 } else {
797 doc, _ = doc.FindByBookIdAndDocIdentify(book.BookId, docIdentify)
798 }
799
800 if doc.DocumentId == 0 {
801 this.Response(http.StatusNotFound, messageNotFound)
802 }
803
804 var err error
805
806 // 文档阅读人次+1
807 if err = models.SetIncreAndDecre("md_documents", "vcnt",
808 fmt.Sprintf("document_id=%v", doc.DocumentId),
809 true, 1,
810 ); err != nil {
811 beego.Error(err.Error())
812 }
813
814 //书籍阅读人次+1
815 if err = models.SetIncreAndDecre("md_books", "vcnt",
816 fmt.Sprintf("book_id=%v", doc.BookId),
817 true, 1,
818 ); err != nil {
819 beego.Error(err.Error())
820 }

Callers

nothing calls this directly

Calls 15

FindMethod · 0.95
FindByIdentifyMethod · 0.95
FindMethod · 0.95
handleReleaseV3Method · 0.95
handleReleaseV2Method · 0.95
handleReleaseV1Method · 0.95
NewBookFunction · 0.92
NewDocumentFunction · 0.92
SetIncreAndDecreFunction · 0.92
NewBookmarkFunction · 0.92
CopyObjectFunction · 0.92

Tested by

no test coverage detected