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

Method ProjectsFile

controllers/StaticController.go:79–114  ·  view source on GitHub ↗

ProjectsFile 书籍静态文件

()

Source from the content-addressed store, hash-verified

77
78// ProjectsFile 书籍静态文件
79func (this *StaticController) ProjectsFile() {
80 if utils.StoreType != utils.StoreOss {
81 this.Abort("404")
82 }
83
84 object := filepath.Join("projects/", strings.TrimLeft(this.GetString(":splat"), "./"))
85 object = strings.ReplaceAll(object, "\\", "/")
86
87 // 不是音频和视频,直接跳转
88 if !this.isMedia(object) {
89 this.Redirect(this.OssDomain+"/"+object, 302)
90 return
91 }
92
93 // 签名验证
94 sign := this.GetString("sign")
95 if !this.isValidSign(sign, object) {
96 // 签名验证不通过,需要再次验证书籍是否是用户的(针对编辑状态)
97 if !this.isBookOwner() {
98 this.Abort("404")
99 return
100 }
101 }
102
103 // if utils.IsSignUsed(sign) {
104 // this.Abort("404")
105 // }
106
107 if bucket, err := store.ModelStoreOss.GetBucket(); err == nil {
108 object, _ = bucket.SignURL(object, http.MethodGet, utils.MediaDuration)
109 if slice := strings.Split(object, "/"); len(slice) > 2 {
110 object = strings.Join(slice[3:], "/")
111 }
112 }
113 this.Redirect(this.OssDomain+"/"+object, 302)
114}
115
116// 是否是音视频
117func (this *StaticController) isMedia(path string) (yes bool) {

Callers

nothing calls this directly

Calls 4

isMediaMethod · 0.95
isValidSignMethod · 0.95
isBookOwnerMethod · 0.95
GetBucketMethod · 0.80

Tested by

no test coverage detected