()
| 1101 | } |
| 1102 | |
| 1103 | func (this *ManagerController) UploadBanner() { |
| 1104 | f, h, err := this.GetFile("image") |
| 1105 | if err != nil { |
| 1106 | this.JsonResult(1, err.Error()) |
| 1107 | } |
| 1108 | ext := strings.ToLower(filepath.Ext(strings.ToLower(h.Filename))) |
| 1109 | tmpFile := fmt.Sprintf("uploads/tmp/banner-%v-%v%v", this.Member.MemberId, time.Now().Unix(), ext) |
| 1110 | destFile := fmt.Sprintf("uploads/banners/%v.%v%v", this.Member.MemberId, time.Now().Unix(), ext) |
| 1111 | defer func() { |
| 1112 | f.Close() |
| 1113 | os.Remove(tmpFile) |
| 1114 | if err != nil { |
| 1115 | utils.DeleteFile(destFile) |
| 1116 | } |
| 1117 | }() |
| 1118 | |
| 1119 | os.MkdirAll(filepath.Dir(tmpFile), os.ModePerm) |
| 1120 | err = this.SaveToFile("image", tmpFile) |
| 1121 | if err != nil { |
| 1122 | this.JsonResult(1, err.Error()) |
| 1123 | } |
| 1124 | err = utils.UploadFile(tmpFile, destFile) |
| 1125 | if err != nil { |
| 1126 | this.JsonResult(1, err.Error()) |
| 1127 | } |
| 1128 | banner := &models.Banner{ |
| 1129 | Image: "/" + destFile, |
| 1130 | Type: this.GetString("type"), |
| 1131 | Title: this.GetString("title"), |
| 1132 | Link: this.GetString("link"), |
| 1133 | Status: true, |
| 1134 | CreatedAt: time.Now(), |
| 1135 | } |
| 1136 | banner.Sort, _ = this.GetInt("sort") |
| 1137 | _, err = orm.NewOrm().Insert(banner) |
| 1138 | if err != nil { |
| 1139 | this.JsonResult(1, err.Error()) |
| 1140 | } |
| 1141 | this.JsonResult(0, "横幅上传成功") |
| 1142 | } |
| 1143 | |
| 1144 | func (this *ManagerController) SubmitBook() { |
| 1145 | this.TplName = "manager/submit_book.html" |
nothing calls this directly
no test coverage detected