refactor and remove useless stuff

pull/144/head
Henrique Dias 2017-06-27 14:49:46 +01:00
parent 6e04c97bb9
commit 06c4e4d58b
No known key found for this signature in database
GPG Key ID: 936F5EB68D786730
4 changed files with 6 additions and 17 deletions

View File

@ -13,8 +13,8 @@ import (
"os" "os"
) )
// checksum calculates the hash of a file. Supports MD5, SHA1, SHA256 and SHA512. // serveChecksum calculates the hash of a file. Supports MD5, SHA1, SHA256 and SHA512.
func checksum(c *requestContext, w http.ResponseWriter, r *http.Request) (int, error) { func serveChecksum(c *requestContext, w http.ResponseWriter, r *http.Request) (int, error) {
query := r.URL.Query().Get("checksum") query := r.URL.Query().Get("checksum")
file, err := os.Open(c.fi.Path) file, err := os.Open(c.fi.Path)

View File

@ -139,7 +139,7 @@ func (m FileManager) WebDavURL() string {
// SetPrefixURL updates the prefixURL of a File // SetPrefixURL updates the prefixURL of a File
// Manager object. // Manager object.
func (m FileManager) SetPrefixURL(url string) { func (m *FileManager) SetPrefixURL(url string) {
url = strings.TrimPrefix(url, "/") url = strings.TrimPrefix(url, "/")
url = strings.TrimSuffix(url, "/") url = strings.TrimSuffix(url, "/")
url = "/" + url url = "/" + url
@ -322,7 +322,7 @@ func (m *FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, er
case r.URL.Query().Get("download") != "": case r.URL.Query().Get("download") != "":
code, err = download(c, w, r) code, err = download(c, w, r)
case !f.IsDir && r.URL.Query().Get("checksum") != "": case !f.IsDir && r.URL.Query().Get("checksum") != "":
code, err = checksum(c, w, r) code, err = serveChecksum(c, w, r)
case r.URL.Query().Get("raw") == "true" && !f.IsDir: case r.URL.Query().Get("raw") == "true" && !f.IsDir:
http.ServeFile(w, r, f.Path) http.ServeFile(w, r, f.Path)
code, err = 0, nil code, err = 0, nil

View File

@ -5,26 +5,18 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"github.com/mholt/caddy/caddyhttp/httpserver"
) )
// serveListing presents the user with a listage of a directory folder. // serveListing presents the user with a listage of a directory folder.
func serveListing(c *requestContext, w http.ResponseWriter, r *http.Request) (int, error) { func serveListing(c *requestContext, w http.ResponseWriter, r *http.Request) (int, error) {
var err error var err error
// Loads the content of the directory // Loads the content of the directory.
listing, err := getListing(c.us, c.fi.VirtualPath, c.fm.RootURL()+r.URL.Path) listing, err := getListing(c.us, c.fi.VirtualPath, c.fm.RootURL()+r.URL.Path)
if err != nil { if err != nil {
return errorToHTTP(err, true), err return errorToHTTP(err, true), err
} }
listing.Context = httpserver.Context{
Root: http.Dir(c.us.scope),
Req: r,
URL: r.URL,
}
cookieScope := c.fm.RootURL() cookieScope := c.fm.RootURL()
if cookieScope == "" { if cookieScope == "" {
cookieScope = "/" cookieScope = "/"

View File

@ -7,8 +7,6 @@ import (
"path" "path"
"sort" "sort"
"strings" "strings"
"github.com/mholt/caddy/caddyhttp/httpserver"
) )
// A listing is the context used to fill out a template. // A listing is the context used to fill out a template.
@ -28,8 +26,7 @@ type listing struct {
// And which order. // And which order.
Order string Order string
// If ≠0 then Items have been limited to that many elements. // If ≠0 then Items have been limited to that many elements.
ItemsLimitedTo int ItemsLimitedTo int
httpserver.Context `json:"-"`
} }
// getListing gets the information about a specific directory and its files. // getListing gets the information about a specific directory and its files.