mirror of
https://github.com/gmemstr/sliproad.git
synced 2024-09-20 00:21:15 +01:00
Support for special characters in filename.
Previously, spaces or other special characters in filenames were borked because of how the filenames were passed through to the ViewFile function - with escaped strings (%020 instead of " "). Added a QueryUnescape call, and slightly tweaked the router to use a filename rather than accessing var everytime.
This commit is contained in:
parent
0902f8a429
commit
59c79fc4fe
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/gmemstr/nas/files"
|
"github.com/gmemstr/nas/files"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -20,18 +21,25 @@ func HandleProvider() Handler {
|
||||||
if r.Method == "GET" {
|
if r.Method == "GET" {
|
||||||
fileList := provider.GetDirectory("")
|
fileList := provider.GetDirectory("")
|
||||||
if vars["file"] != "" {
|
if vars["file"] != "" {
|
||||||
fileType := provider.DetermineType(vars["file"])
|
filename, err := url.QueryUnescape(vars["file"])
|
||||||
|
if err != nil {
|
||||||
|
return &HTTPError{
|
||||||
|
Message: fmt.Sprintf("error determining filetype for %s\n", filename),
|
||||||
|
StatusCode: http.StatusInternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fileType := provider.DetermineType(filename)
|
||||||
if fileType == "" {
|
if fileType == "" {
|
||||||
return &HTTPError{
|
return &HTTPError{
|
||||||
Message: fmt.Sprintf("error determining filetype for %s\n", vars["file"]),
|
Message: fmt.Sprintf("error determining filetype for %s\n", filename),
|
||||||
StatusCode: http.StatusInternalServerError,
|
StatusCode: http.StatusInternalServerError,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if fileType == "file" {
|
if fileType == "file" {
|
||||||
provider.ViewFile(vars["file"], w)
|
provider.ViewFile(filename, w)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
fileList = provider.GetDirectory(vars["file"])
|
fileList = provider.GetDirectory(filename)
|
||||||
}
|
}
|
||||||
data, err := json.Marshal(fileList)
|
data, err := json.Marshal(fileList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue