raw and download urls working :D
parent
42fdc14953
commit
ba64a3df0f
|
@ -29,9 +29,10 @@ func GetFileInfo(url *url.URL, c *Config) (*FileInfo, int, error) {
|
||||||
|
|
||||||
path := strings.Replace(url.Path, c.BaseURL, c.PathScope, 1)
|
path := strings.Replace(url.Path, c.BaseURL, c.PathScope, 1)
|
||||||
path = filepath.Clean(path)
|
path = filepath.Clean(path)
|
||||||
|
path = strings.Replace(path, "\\", "/", -1)
|
||||||
|
|
||||||
file := &FileInfo{Path: path}
|
file := &FileInfo{Path: path}
|
||||||
f, err := c.Root.Open(path)
|
f, err := c.Root.Open("/" + path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return file, ErrorToHTTPCode(err), err
|
return file, ErrorToHTTPCode(err), err
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,10 +64,22 @@ func (f FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, err
|
||||||
return ServeAssets(w, r, c)
|
return ServeAssets(w, r, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if file.Info.IsDir() {
|
if fi.IsDir {
|
||||||
return f.ServeListing(w, r, file.File, c)
|
//return f.ServeListing(w, r, file.File, c)
|
||||||
}
|
}
|
||||||
return f.ServeSingleFile(w, r, file, c) */
|
|
||||||
|
query := r.URL.Query()
|
||||||
|
if val, ok := query["raw"]; ok && val[0] == "true" {
|
||||||
|
// wanna raw file
|
||||||
|
return f.Next.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
if val, ok := query["download"]; ok && val[0] == "true" {
|
||||||
|
w.Header().Set("Content-Disposition", "attachment; filename="+fi.Name)
|
||||||
|
return f.Next.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
// return f.ServeSingleFile(w, r, file, c)
|
||||||
case http.MethodPost:
|
case http.MethodPost:
|
||||||
// Upload a new file
|
// Upload a new file
|
||||||
if r.Header.Get("Upload") == "true" {
|
if r.Header.Get("Upload") == "true" {
|
||||||
|
|
Loading…
Reference in New Issue