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

Method ExportOld

controllers/DocumentController.go:1255–1316  ·  view source on GitHub ↗

导出文件

()

Source from the content-addressed store, hash-verified

1253
1254// 导出文件
1255func (this *DocumentController) ExportOld() {
1256 wecode := strings.TrimSpace(this.GetString("wecode"))
1257 if wecode == "" && (this.Member == nil || this.Member.MemberId == 0) {
1258 if tips, ok := this.Option["DOWNLOAD_LIMIT"]; ok {
1259 tips = strings.TrimSpace(tips)
1260 if len(tips) > 0 {
1261 this.JsonResult(1, tips)
1262 }
1263 }
1264 }
1265
1266 identify := this.Ctx.Input.Param(":key")
1267 ext := strings.ToLower(this.GetString("output"))
1268 switch ext {
1269 case "pdf", "epub", "mobi":
1270 ext = "." + ext
1271 default:
1272 ext = ".pdf"
1273 }
1274 if identify == "" {
1275 this.JsonResult(1, "下载失败,无法识别您要下载的文档")
1276 }
1277 book, err := new(models.Book).FindByIdentify(identify)
1278 if err != nil {
1279 beego.Error(err.Error())
1280 this.JsonResult(1, "下载失败,您要下载的书籍当前并未生成可下载的电子书。")
1281 }
1282 if book.PrivatelyOwned == 1 && this.Member.MemberId != book.MemberId {
1283 this.JsonResult(1, "私有文档,只有文档创建人可导出")
1284 }
1285 //查询文档是否存在
1286 obj := fmt.Sprintf("projects/%v/books/%v%v", book.Identify, book.GenerateTime.Unix(), ext)
1287 link := ""
1288 switch utils.StoreType {
1289 case utils.StoreOss:
1290 if err := store.ModelStoreOss.IsObjectExist(obj); err != nil {
1291 beego.Error(err, obj)
1292 this.JsonResult(1, "下载失败,您要下载的书籍当前并未生成可下载的电子书。")
1293 }
1294 link = this.OssDomain + "/" + obj
1295 case utils.StoreLocal:
1296 obj = "uploads/" + obj
1297 if err := store.ModelStoreLocal.IsObjectExist(obj); err != nil {
1298 beego.Error(err, obj)
1299 this.JsonResult(1, "下载失败,您要下载的书籍当前并未生成可下载的电子书。")
1300 }
1301 link = "/" + obj
1302 }
1303 if link != "" {
1304 // 查询是否可以下载
1305 counter := models.NewDownloadCounter()
1306 _, err := counter.DoesICanDownload(this.Member.MemberId, wecode)
1307 if err != nil {
1308 this.JsonResult(1, err.Error())
1309 }
1310 if wecode == "" {
1311 counter.Increase(this.Member.MemberId)
1312 }

Callers

nothing calls this directly

Calls 6

DoesICanDownloadMethod · 0.95
IncreaseMethod · 0.95
NewDownloadCounterFunction · 0.92
JsonResultMethod · 0.80
FindByIdentifyMethod · 0.45
IsObjectExistMethod · 0.45

Tested by

no test coverage detected