refactor: fix golint check
This commit is contained in:
parent
7b8b91e9de
commit
223182cc0d
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
|
|
||||||
"github.com/disintegration/imaging"
|
"github.com/disintegration/imaging"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
@ -40,12 +39,7 @@ var previewHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *da
|
|||||||
return errToStatus(err), err
|
return errToStatus(err), err
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.URL.Query().Get("inline") == "true" {
|
setContentDisposition(w, r, file)
|
||||||
w.Header().Set("Content-Disposition", "inline")
|
|
||||||
} else {
|
|
||||||
// As per RFC6266 section 4.3
|
|
||||||
w.Header().Set("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(file.Name))
|
|
||||||
}
|
|
||||||
|
|
||||||
switch file.Type {
|
switch file.Type {
|
||||||
case "image":
|
case "image":
|
||||||
|
|||||||
20
http/raw.go
20
http/raw.go
@ -22,7 +22,7 @@ func parseQueryFiles(r *http.Request, f *files.FileInfo, _ *users.User) ([]strin
|
|||||||
fileSlice = append(fileSlice, f.Path)
|
fileSlice = append(fileSlice, f.Path)
|
||||||
} else {
|
} else {
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
name, err := url.QueryUnescape(strings.Replace(name, "+", "%2B", -1)) //nolint:shadow
|
name, err := url.QueryUnescape(strings.Replace(name, "+", "%2B", -1)) // nolint:shadow
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ func parseQueryFiles(r *http.Request, f *files.FileInfo, _ *users.User) ([]strin
|
|||||||
return fileSlice, nil
|
return fileSlice, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: goconst
|
// nolint: goconst
|
||||||
func parseQueryAlgorithm(r *http.Request) (string, archiver.Writer, error) {
|
func parseQueryAlgorithm(r *http.Request) (string, archiver.Writer, error) {
|
||||||
// TODO: use enum
|
// TODO: use enum
|
||||||
switch r.URL.Query().Get("algo") {
|
switch r.URL.Query().Get("algo") {
|
||||||
@ -58,6 +58,15 @@ func parseQueryAlgorithm(r *http.Request) (string, archiver.Writer, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setContentDisposition(w http.ResponseWriter, r *http.Request, file *files.FileInfo) {
|
||||||
|
if r.URL.Query().Get("inline") == "true" {
|
||||||
|
w.Header().Set("Content-Disposition", "inline")
|
||||||
|
} else {
|
||||||
|
// As per RFC6266 section 4.3
|
||||||
|
w.Header().Set("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(file.Name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var rawHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
var rawHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
||||||
if !d.user.Perm.Download {
|
if !d.user.Perm.Download {
|
||||||
return http.StatusAccepted, nil
|
return http.StatusAccepted, nil
|
||||||
@ -168,12 +177,7 @@ func rawFileHandler(w http.ResponseWriter, r *http.Request, file *files.FileInfo
|
|||||||
}
|
}
|
||||||
defer fd.Close()
|
defer fd.Close()
|
||||||
|
|
||||||
if r.URL.Query().Get("inline") == "true" {
|
setContentDisposition(w, r, file)
|
||||||
w.Header().Set("Content-Disposition", "inline")
|
|
||||||
} else {
|
|
||||||
// As per RFC6266 section 4.3
|
|
||||||
w.Header().Set("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(file.Name))
|
|
||||||
}
|
|
||||||
|
|
||||||
http.ServeContent(w, r, file.Name, file.ModTime, fd)
|
http.ServeContent(w, r, file.Name, file.ModTime, fd)
|
||||||
return 0, nil
|
return 0, nil
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user