Uploads 查询上传的静态资源。 如果是音频和视频文件,需要根据后台设置而判断是否加密处理 如果使用了OSS存储,则需要将文件处理好
()
| 41 | // 如果是音频和视频文件,需要根据后台设置而判断是否加密处理 |
| 42 | // 如果使用了OSS存储,则需要将文件处理好 |
| 43 | func (this *StaticController) Uploads() { |
| 44 | file := strings.TrimLeft(this.GetString(":splat"), "./") |
| 45 | path := strings.ReplaceAll(filepath.Join("uploads", file), "\\", "/") |
| 46 | attachment := this.GetString("attachment") |
| 47 | |
| 48 | if this.isMedia(path) { // 签名验证 |
| 49 | sign := this.GetString("sign") |
| 50 | if !this.isValidSign(sign, path) { |
| 51 | // 签名验证不通过,需要再次验证书籍是否是用户的(针对编辑状态) |
| 52 | if !this.isBookOwner() { |
| 53 | this.Abort("404") |
| 54 | return |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | if attachment != "" { |
| 59 | this.Ctx.Output.Download(path, attachment) |
| 60 | return |
| 61 | } |
| 62 | http.ServeFile(this.Ctx.ResponseWriter, this.Ctx.Request, path) |
| 63 | } |
| 64 | |
| 65 | // 静态文件,这个加在路由的最后 |
| 66 | func (this *StaticController) StaticFile() { |
nothing calls this directly
no test coverage detected