MCPcopy
hub / github.com/IceWhaleTech/CasaOS / InitFile

Function InitFile

route/v2.go:149–172  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

147}
148
149func InitFile() http.Handler {
150 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
151 token := r.URL.Query().Get("token")
152 if len(token) == 0 {
153 w.Header().Set("Content-Type", "application/json")
154 w.WriteHeader(http.StatusUnauthorized)
155 w.Write([]byte(`{"message": "token not found"}`))
156 return
157 }
158
159 valid, _, errs := jwt.Validate(token, func() (*ecdsa.PublicKey, error) { return external.GetPublicKey(config.CommonInfo.RuntimePath) })
160 if errs != nil || !valid {
161 w.Header().Set("Content-Type", "application/json")
162 w.WriteHeader(http.StatusUnauthorized)
163 w.Write([]byte(`{"message": "validation failure"}`))
164 return
165 }
166 filePath := r.URL.Query().Get("path")
167 fileName := path.Base(filePath)
168 w.Header().Add("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(fileName))
169 http.ServeFile(w, r, filePath)
170 // http.ServeFile(w, r, filePath)
171 })
172}
173
174func InitDir() http.Handler {
175 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Callers 1

mainFunction · 0.92

Calls 2

ValidateMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected