UploadFile upload file @Summary upload file @Description upload file @Tags Upload @Accept multipart/form-data @Security ApiKeyAuth @Param source formData string true "identify the source of the file upload" Enums(post, post_attachment, avatar, branding) @Param file formData file true "file" @Success
(ctx *gin.Context)
| 64 | // @Success 200 {object} handler.RespBody{data=string} |
| 65 | // @Router /answer/api/v1/file [post] |
| 66 | func (uc *UploadController) UploadFile(ctx *gin.Context) { |
| 67 | var ( |
| 68 | url string |
| 69 | err error |
| 70 | ) |
| 71 | |
| 72 | source := ctx.PostForm("source") |
| 73 | userID := middleware.GetLoginUserIDFromContext(ctx) |
| 74 | switch source { |
| 75 | case fileFromAvatar: |
| 76 | url, err = uc.uploaderService.UploadAvatarFile(ctx, userID) |
| 77 | case fileFromPost: |
| 78 | url, err = uc.uploaderService.UploadPostFile(ctx, userID) |
| 79 | case fileFromBranding: |
| 80 | if !middleware.GetIsAdminFromContext(ctx) { |
| 81 | handler.HandleResponse(ctx, errors.Forbidden(reason.ForbiddenError), nil) |
| 82 | return |
| 83 | } |
| 84 | url, err = uc.uploaderService.UploadBrandingFile(ctx, userID) |
| 85 | case fileFromPostAttachment: |
| 86 | url, err = uc.uploaderService.UploadPostAttachment(ctx, userID) |
| 87 | default: |
| 88 | handler.HandleResponse(ctx, errors.BadRequest(reason.UploadFileSourceUnsupported), nil) |
| 89 | return |
| 90 | } |
| 91 | if err != nil { |
| 92 | handler.HandleResponse(ctx, err, nil) |
| 93 | return |
| 94 | } |
| 95 | handler.HandleResponse(ctx, err, url) |
| 96 | } |
| 97 | |
| 98 | // PostRender render post content |
| 99 | // @Summary render post content |
nothing calls this directly
no test coverage detected