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

Method Download

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

Source from the content-addressed store, hash-verified

1022}
1023
1024func (this *CommonController) Download() {
1025 identify := this.GetString("identify")
1026 if identify == "" {
1027 this.Response(http.StatusBadRequest, messageBadRequest)
1028 }
1029
1030 id, _ := strconv.Atoi(identify)
1031
1032 book := models.NewBook()
1033 q := orm.NewOrm().QueryTable(book)
1034 if id > 0 {
1035 q.Filter("book_id", id).One(book)
1036 } else {
1037 q.Filter("identify", identify).One(book)
1038 }
1039
1040 if book.BookId == 0 || book.GenerateTime.Unix() < book.ReleaseTime.Unix() {
1041 this.Response(http.StatusNotFound, messageNotFound)
1042 }
1043
1044 if book.PrivatelyOwned == 1 && this.isLogin() != book.MemberId {
1045 this.Response(http.StatusNotFound, messageNotFound)
1046 }
1047
1048 format := fmt.Sprintf("projects/%v/books/%v", book.Identify, book.GenerateTime.Unix())
1049
1050 data := map[string]string{
1051 "pdf": this.completeLink(format + ".pdf"),
1052 "mobi": this.completeLink(format + ".mobi"),
1053 "epub": this.completeLink(format + ".epub"),
1054 }
1055
1056 this.Response(http.StatusOK, messageSuccess, map[string]interface{}{"files": data})
1057}
1058
1059func (this *CommonController) Bookshelf() {
1060 uid, _ := this.GetInt("uid")

Callers 3

DownloadAttachmentMethod · 0.80
Export2MarkdownMethod · 0.80
UploadsMethod · 0.80

Calls 4

NewBookFunction · 0.92
ResponseMethod · 0.80
isLoginMethod · 0.80
completeLinkMethod · 0.80

Tested by

no test coverage detected