mirror of
https://github.com/gmemstr/sliproad.git
synced 2024-09-19 16:11:11 +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/gorilla/mux"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
@ -20,18 +21,25 @@ func HandleProvider() Handler {
|
|||
if r.Method == "GET" {
|
||||
fileList := provider.GetDirectory("")
|
||||
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 == "" {
|
||||
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,
|
||||
}
|
||||
}
|
||||
if fileType == "file" {
|
||||
provider.ViewFile(vars["file"], w)
|
||||
provider.ViewFile(filename, w)
|
||||
return nil
|
||||
}
|
||||
fileList = provider.GetDirectory(vars["file"])
|
||||
fileList = provider.GetDirectory(filename)
|
||||
}
|
||||
data, err := json.Marshal(fileList)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in a new issue