MCPcopy Index your code
hub / github.com/TruthHun/BookStack / Uploads

Method Uploads

controllers/StaticController.go:43–63  ·  view source on GitHub ↗

Uploads 查询上传的静态资源。 如果是音频和视频文件,需要根据后台设置而判断是否加密处理 如果使用了OSS存储,则需要将文件处理好

()

Source from the content-addressed store, hash-verified

41// 如果是音频和视频文件,需要根据后台设置而判断是否加密处理
42// 如果使用了OSS存储,则需要将文件处理好
43func (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// 静态文件,这个加在路由的最后
66func (this *StaticController) StaticFile() {

Callers

nothing calls this directly

Calls 4

isMediaMethod · 0.95
isValidSignMethod · 0.95
isBookOwnerMethod · 0.95
DownloadMethod · 0.80

Tested by

no test coverage detected