导出文件
()
| 1317 | |
| 1318 | // 导出文件 |
| 1319 | func (this *DocumentController) Export() { |
| 1320 | wecode := strings.TrimSpace(this.GetString("wecode")) |
| 1321 | if wecode == "" && (this.Member == nil || this.Member.MemberId == 0) { |
| 1322 | if tips, ok := this.Option["DOWNLOAD_LIMIT"]; ok { |
| 1323 | tips = strings.TrimSpace(tips) |
| 1324 | if len(tips) > 0 { |
| 1325 | this.JsonResult(1, tips) |
| 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | identify := this.Ctx.Input.Param(":key") |
| 1331 | ext := strings.ToLower(this.GetString("output")) |
| 1332 | switch ext { |
| 1333 | case "pdf", "epub", "mobi": |
| 1334 | ext = "." + ext |
| 1335 | default: |
| 1336 | ext = ".pdf" |
| 1337 | } |
| 1338 | if identify == "" { |
| 1339 | this.JsonResult(1, "下载失败,无法识别您要下载的电子书") |
| 1340 | } |
| 1341 | book, err := new(models.Book).FindByIdentify(identify) |
| 1342 | if err != nil { |
| 1343 | beego.Error(err.Error()) |
| 1344 | this.JsonResult(1, "下载失败,无法识别您要下载的电子书") |
| 1345 | } |
| 1346 | if book.PrivatelyOwned == 1 && this.Member.MemberId != book.MemberId { |
| 1347 | this.JsonResult(1, "私有书籍,只有书籍创建人可导出电子书") |
| 1348 | } |
| 1349 | ebook := models.NewEbook().Get2Download(book.BookId, ext) |
| 1350 | if ebook.Id == 0 || ebook.Status != models.EBookStatusSuccess || ebook.Path == "" { |
| 1351 | this.JsonResult(1, "下载失败,您要下载的书籍当前并未生成电子书。") |
| 1352 | } |
| 1353 | |
| 1354 | //查询文档是否存在 |
| 1355 | obj := strings.TrimLeft(ebook.Path, "./") |
| 1356 | link := "" |
| 1357 | switch utils.StoreType { |
| 1358 | case utils.StoreOss: |
| 1359 | if err := store.ModelStoreOss.IsObjectExist(obj); err != nil { |
| 1360 | beego.Error(err, obj) |
| 1361 | this.JsonResult(1, "下载失败,您要下载的书籍当前并未生成电子书。") |
| 1362 | } |
| 1363 | link = this.OssDomain + "/" + obj |
| 1364 | case utils.StoreLocal: |
| 1365 | if err := store.ModelStoreLocal.IsObjectExist(obj); err != nil { |
| 1366 | beego.Error(err, obj) |
| 1367 | this.JsonResult(1, "下载失败,您要下载的书籍当前并未生成电子书。") |
| 1368 | } |
| 1369 | link = "/" + obj + fmt.Sprintf("?attachment=%s%s", url.QueryEscape(ebook.Title), ebook.Ext) |
| 1370 | } |
| 1371 | if link != "" { |
| 1372 | // 查询是否可以下载 |
| 1373 | counter := models.NewDownloadCounter() |
| 1374 | _, err := counter.DoesICanDownload(this.Member.MemberId, wecode) |
| 1375 | if err != nil { |
| 1376 | this.JsonResult(1, err.Error()) |
nothing calls this directly
no test coverage detected