| 147 | } |
| 148 | |
| 149 | func 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 | |
| 174 | func InitDir() http.Handler { |
| 175 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |