pass a struct with the info

Former-commit-id: 6f9843613e6abfe0b19e6e43f9299afb98645477 [formerly 805fa39b073401c946b559e0e967fdc553f16295] [formerly f9e2de337abc0cbeb5ccdb8b6962871b0bd3ee0e [formerly 1d26b8e95e73a94ba92673861c4e83dfded0d92e]]
Former-commit-id: 259a1ba8cdc71e7d32add58f9487e5827aa6685e [formerly 161a1a49bc1158f11f07fc9ff638506dafb6c918]
Former-commit-id: 67fe1fef4602baf4ddae40b28e65ac9a2a42ca9d
This commit is contained in:
Henrique Dias
2017-06-27 09:57:11 +01:00
parent a3941facd9
commit f2b492e0ce
12 changed files with 79 additions and 70 deletions

View File

@@ -14,12 +14,12 @@ import (
// download creates an archive in one of the supported formats (zip, tar,
// tar.gz or tar.bz2) and sends it to be downloaded.
func download(w http.ResponseWriter, r *http.Request, i *fileInfo) (int, error) {
func download(ctx *requestContext, w http.ResponseWriter, r *http.Request) (int, error) {
query := r.URL.Query().Get("download")
if !i.IsDir {
w.Header().Set("Content-Disposition", "attachment; filename="+i.Name)
http.ServeFile(w, r, i.Path)
if !ctx.Info.IsDir {
w.Header().Set("Content-Disposition", "attachment; filename="+ctx.Info.Name)
http.ServeFile(w, r, ctx.Info.Path)
return 0, nil
}
@@ -34,11 +34,11 @@ func download(w http.ResponseWriter, r *http.Request, i *fileInfo) (int, error)
return http.StatusInternalServerError, err
}
files = append(files, filepath.Join(i.Path, name))
files = append(files, filepath.Join(ctx.Info.Path, name))
}
} else {
files = append(files, i.Path)
files = append(files, ctx.Info.Path)
}
if query == "true" {
@@ -84,7 +84,7 @@ func download(w http.ResponseWriter, r *http.Request, i *fileInfo) (int, error)
return http.StatusInternalServerError, err
}
name := i.Name
name := ctx.Info.Name
if name == "." || name == "" {
name = "download"
}