()
| 1022 | } |
| 1023 | |
| 1024 | func (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 | |
| 1059 | func (this *CommonController) Bookshelf() { |
| 1060 | uid, _ := this.GetInt("uid") |
no test coverage detected