From 7fdce622d25d3c1402197e04ebc97439cb14e3de Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Tue, 27 Jun 2017 14:49:46 +0100 Subject: [PATCH] refactor and remove useless stuff Former-commit-id: 31f37b7a4487e7d0b5763f07f52b8f2b6157a4cd [formerly 8143cd383b7cd35339a21e93ec4d24ba91039708] [formerly 35ea25e79b4bea4d58edfb1745b844fcb12d91d9 [formerly 06c4e4d58bc50b245c78ca3f15d7512fcc16e92b]] Former-commit-id: e7f57997c2640adcfff36b605a99da9786aed3cb [formerly 2d63af9ef7a090b597239d5c0aeaf056e6366efc] Former-commit-id: cf7d129de97b0f289a6c35fa1ce9b070d9d6eac9 --- checksum.go | 4 ++-- filemanager.go | 4 ++-- http_listing.go | 10 +--------- listing.go | 5 +---- 4 files changed, 6 insertions(+), 17 deletions(-) diff --git a/checksum.go b/checksum.go index ba7bc865..138da3d9 100644 --- a/checksum.go +++ b/checksum.go @@ -13,8 +13,8 @@ import ( "os" ) -// checksum calculates the hash of a file. Supports MD5, SHA1, SHA256 and SHA512. -func checksum(c *requestContext, w http.ResponseWriter, r *http.Request) (int, error) { +// serveChecksum calculates the hash of a file. Supports MD5, SHA1, SHA256 and SHA512. +func serveChecksum(c *requestContext, w http.ResponseWriter, r *http.Request) (int, error) { query := r.URL.Query().Get("checksum") file, err := os.Open(c.fi.Path) diff --git a/filemanager.go b/filemanager.go index dc6894e9..ee685ea2 100644 --- a/filemanager.go +++ b/filemanager.go @@ -139,7 +139,7 @@ func (m FileManager) WebDavURL() string { // SetPrefixURL updates the prefixURL of a File // Manager object. -func (m FileManager) SetPrefixURL(url string) { +func (m *FileManager) SetPrefixURL(url string) { url = strings.TrimPrefix(url, "/") url = strings.TrimSuffix(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") != "": code, err = download(c, w, r) 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: http.ServeFile(w, r, f.Path) code, err = 0, nil diff --git a/http_listing.go b/http_listing.go index ff98eded..b306a65e 100644 --- a/http_listing.go +++ b/http_listing.go @@ -5,26 +5,18 @@ import ( "net/http" "strconv" "strings" - - "github.com/mholt/caddy/caddyhttp/httpserver" ) // serveListing presents the user with a listage of a directory folder. func serveListing(c *requestContext, w http.ResponseWriter, r *http.Request) (int, 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) if err != nil { return errorToHTTP(err, true), err } - listing.Context = httpserver.Context{ - Root: http.Dir(c.us.scope), - Req: r, - URL: r.URL, - } - cookieScope := c.fm.RootURL() if cookieScope == "" { cookieScope = "/" diff --git a/listing.go b/listing.go index b4cbbed7..0eaa62f2 100644 --- a/listing.go +++ b/listing.go @@ -7,8 +7,6 @@ import ( "path" "sort" "strings" - - "github.com/mholt/caddy/caddyhttp/httpserver" ) // A listing is the context used to fill out a template. @@ -28,8 +26,7 @@ type listing struct { // And which order. Order string // If ≠0 then Items have been limited to that many elements. - ItemsLimitedTo int - httpserver.Context `json:"-"` + ItemsLimitedTo int } // getListing gets the information about a specific directory and its files.