上传书籍
()
| 1006 | |
| 1007 | // 上传书籍 |
| 1008 | func (this *BookController) UploadProject() { |
| 1009 | //处理步骤 |
| 1010 | //1、接受上传上来的zip文件,并存放到store/temp目录下 |
| 1011 | //2、解压zip到当前目录,然后移除非图片文件 |
| 1012 | //3、将文件夹移动到uploads目录下 |
| 1013 | |
| 1014 | identify := this.GetString("identify") |
| 1015 | |
| 1016 | if !models.NewBook().HasProjectAccess(identify, this.Member.MemberId, conf.BookEditor) { |
| 1017 | this.JsonResult(1, "无操作权限") |
| 1018 | } |
| 1019 | |
| 1020 | book, _ := models.NewBookResult().FindByIdentify(identify, this.Member.MemberId) |
| 1021 | if book.BookId == 0 { |
| 1022 | this.JsonResult(1, "书籍不存在") |
| 1023 | } |
| 1024 | |
| 1025 | f, h, err := this.GetFile("zipfile") |
| 1026 | if err != nil { |
| 1027 | this.JsonResult(1, err.Error()) |
| 1028 | } |
| 1029 | defer f.Close() |
| 1030 | if strings.ToLower(filepath.Ext(h.Filename)) != ".zip" && strings.ToLower(filepath.Ext(h.Filename)) != ".epub" { |
| 1031 | this.JsonResult(1, "请上传指定格式文件") |
| 1032 | } |
| 1033 | tmpFile := "store/" + identify + ".zip" //保存的文件名 |
| 1034 | if err := this.SaveToFile("zipfile", tmpFile); err == nil { |
| 1035 | go this.unzipToData(book.BookId, identify, tmpFile, h.Filename) |
| 1036 | } else { |
| 1037 | beego.Error(err.Error()) |
| 1038 | } |
| 1039 | this.JsonResult(0, "上传成功") |
| 1040 | } |
| 1041 | |
| 1042 | // 将zip压缩文件解压并录入数据库 |
| 1043 | // @param book_id 书籍id(其实有想不标识了可以不要这个的,但是这里的书籍标识只做目录) |
nothing calls this directly
no test coverage detected