从github等拉取下载markdown书籍
()
| 938 | |
| 939 | // 从github等拉取下载markdown书籍 |
| 940 | func (this *BookController) DownloadProject() { |
| 941 | |
| 942 | //处理步骤 |
| 943 | //1、接受上传上来的zip文件,并存放到store/temp目录下 |
| 944 | //2、解压zip到当前目录,然后移除非图片文件 |
| 945 | //3、将文件夹移动到uploads目录下 |
| 946 | |
| 947 | if _, err := this.IsPermission(); err != nil { |
| 948 | this.JsonResult(1, err.Error()) |
| 949 | } |
| 950 | |
| 951 | //普通用户没有权限 |
| 952 | if this.Member.Role > 1 { |
| 953 | this.JsonResult(1, "您没有操作权限") |
| 954 | } |
| 955 | |
| 956 | identify := this.GetString("identify") |
| 957 | book, _ := models.NewBookResult().FindByIdentify(identify, this.Member.MemberId) |
| 958 | if book.BookId == 0 { |
| 959 | this.JsonResult(1, "导入失败,只有书籍创建人才有权限导入书籍") |
| 960 | } |
| 961 | //GitHub书籍链接 |
| 962 | link := this.GetString("link") |
| 963 | if strings.ToLower(filepath.Ext(link)) != ".zip" { |
| 964 | this.JsonResult(1, "只支持拉取zip压缩的markdown书籍") |
| 965 | } |
| 966 | go func() { |
| 967 | if file, err := util.CrawlFile(link, "store", 60); err != nil { |
| 968 | beego.Error(err) |
| 969 | } else { |
| 970 | this.unzipToData(book.BookId, identify, file, filepath.Base(file)) |
| 971 | } |
| 972 | }() |
| 973 | this.JsonResult(0, "提交成功。下载任务已交由后台执行") |
| 974 | } |
| 975 | |
| 976 | // 从Git仓库拉取书籍 |
| 977 | func (this *BookController) GitPull() { |
nothing calls this directly
no test coverage detected