上传附件或图片.
()
| 739 | |
| 740 | // 上传附件或图片. |
| 741 | func (this *DocumentController) Upload() { |
| 742 | identify := this.GetString("identify") |
| 743 | docId, _ := this.GetInt("doc_id") |
| 744 | fileType := this.GetString("type") |
| 745 | |
| 746 | if identify == "" { |
| 747 | this.JsonResult(6001, "参数错误") |
| 748 | } |
| 749 | |
| 750 | name := "editormd-file-file" |
| 751 | if docId == 0 { |
| 752 | if fileType != "" && !strings.Contains(fileType, "/") { |
| 753 | name = "editormd-" + fileType + "-file" |
| 754 | } else { |
| 755 | fileType = strings.Split(fileType, "/")[0] |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | file, moreFile, err := this.GetFile(name) |
| 760 | if err == http.ErrMissingFile { |
| 761 | name = "editormd-image-file" |
| 762 | file, moreFile, err = this.GetFile(name) |
| 763 | if err == http.ErrMissingFile { |
| 764 | this.JsonResult(6003, "没有发现需要上传的文件") |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | if err != nil { |
| 769 | this.JsonResult(6002, err.Error()) |
| 770 | } |
| 771 | |
| 772 | defer file.Close() |
| 773 | |
| 774 | ext := filepath.Ext(moreFile.Filename) |
| 775 | if ext == "" { |
| 776 | this.JsonResult(6003, "无法解析文件的格式") |
| 777 | } |
| 778 | |
| 779 | if !conf.IsAllowUploadFileExt(ext, fileType) { |
| 780 | this.JsonResult(6004, "不允许的文件类型") |
| 781 | } |
| 782 | |
| 783 | bookId := 0 |
| 784 | bookIdentify := "" |
| 785 | //如果是超级管理员,则不判断权限 |
| 786 | if this.Member.IsAdministrator() { |
| 787 | book, err := models.NewBook().FindByFieldFirst("identify", identify) |
| 788 | if err != nil { |
| 789 | this.JsonResult(6006, "文档不存在或权限不足") |
| 790 | } |
| 791 | bookId = book.BookId |
| 792 | bookIdentify = book.Identify |
| 793 | } else { |
| 794 | book, err := models.NewBookResult().FindByIdentify(identify, this.Member.MemberId) |
| 795 | if err != nil { |
| 796 | beego.Error("DocumentController.Edit => ", err) |
| 797 | if err == orm.ErrNoRows { |
| 798 | this.JsonResult(6006, "权限不足") |
nothing calls this directly
no test coverage detected