MCPcopy
hub / github.com/filebrowser/filebrowser / rawDirHandler

Function rawDirHandler

http/raw.go:178–224  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request, d *data, file *files.FileInfo)

Source from the content-addressed store, hash-verified

176}
177
178func rawDirHandler(w http.ResponseWriter, r *http.Request, d *data, file *files.FileInfo) (int, error) {
179 filenames, err := parseQueryFiles(r, file, d.user)
180 if err != nil {
181 return http.StatusInternalServerError, err
182 }
183
184 extension, archiver, err := parseQueryAlgorithm(r)
185 if err != nil {
186 return http.StatusInternalServerError, err
187 }
188
189 commonDir := fileutils.CommonPrefix(filepath.Separator, filenames...)
190
191 var allFiles []archives.FileInfo
192 for _, fname := range filenames {
193 archiveFiles, err := getFiles(d, fname, commonDir)
194 if err != nil {
195 log.Printf("Failed to get files from %s: %v", fname, err)
196 continue
197 }
198 allFiles = append(allFiles, archiveFiles...)
199 }
200
201 name := filepath.Base(commonDir)
202 if name == "." || name == "" || name == string(filepath.Separator) {
203 if file.Name != "" {
204 name = file.Name
205 } else {
206 actual, statErr := file.Fs.Stat(".")
207 if statErr != nil {
208 return http.StatusInternalServerError, statErr
209 }
210 name = actual.Name()
211 }
212 }
213 if len(filenames) > 1 {
214 name = "_" + name
215 }
216 name += extension
217 w.Header().Set("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(name))
218
219 if err := archiver.Archive(r.Context(), w, allFiles); err != nil {
220 return http.StatusInternalServerError, err
221 }
222
223 return 0, nil
224}
225
226func rawFileHandler(w http.ResponseWriter, r *http.Request, file *files.FileInfo) (int, error) {
227 fd, err := file.Fs.Open(file.Path)

Callers 2

public.goFile · 0.85
raw.goFile · 0.85

Calls 6

CommonPrefixFunction · 0.92
parseQueryFilesFunction · 0.85
parseQueryAlgorithmFunction · 0.85
getFilesFunction · 0.85
NameMethod · 0.80
StatMethod · 0.45

Tested by

no test coverage detected