diff --git a/editor.go b/editor.go index 57946578..3ffcf872 100644 --- a/editor.go +++ b/editor.go @@ -24,7 +24,7 @@ type editor struct { } // getEditor gets the editor based on a Info struct -func (i *fileInfo) getEditor(r *http.Request) (*editor, error) { +func getEditor(r *http.Request, i *fileInfo) (*editor, error) { var err error // Create a new editor variable and set the mode diff --git a/info.go b/file.go similarity index 97% rename from info.go rename to file.go index a99fe3f0..e5b58571 100644 --- a/info.go +++ b/file.go @@ -34,9 +34,6 @@ type fileInfo struct { // Indicates the file content type: video, text, image, music or blob. Type string - - // Indicates if the user has enough permissions to edit the file. - UserAllowed bool } // getInfo gets the file information and, in case of error, returns the diff --git a/http_listing.go b/http_listing.go index 3d430e4a..cd881f86 100644 --- a/http_listing.go +++ b/http_listing.go @@ -14,7 +14,7 @@ func serveListing(w http.ResponseWriter, r *http.Request, c *FileManager, u *use var err error // Loads the content of the directory - listing, err := GetListing(u, i.VirtualPath, c.PrefixURL+r.URL.Path) + listing, err := getListing(u, i.VirtualPath, c.PrefixURL+r.URL.Path) if err != nil { return errorToHTTP(err, true), err } diff --git a/http_single.go b/http_single.go index 853daf58..2496a2ea 100644 --- a/http_single.go +++ b/http_single.go @@ -37,7 +37,7 @@ func serveSingle(w http.ResponseWriter, r *http.Request, c *FileManager, u *user } if i.CanBeEdited() && u.AllowEdit { - p.Data, err = GetEditor(r, i) + p.Data, err = getEditor(r, i) p.Editor = true if err != nil { return http.StatusInternalServerError, err diff --git a/listing.go b/listing.go index 15930f23..1863b18a 100644 --- a/listing.go +++ b/listing.go @@ -11,29 +11,29 @@ import ( "github.com/mholt/caddy/caddyhttp/httpserver" ) -// A Listing is the context used to fill out a template. -type Listing struct { - // The name of the directory (the last element of the path) +// A listing is the context used to fill out a template. +type listing struct { + // The name of the directory (the last element of the path). Name string - // The full path of the request relatively to a File System + // The full path of the request relatively to a File System. Path string - // The items (files and folders) in the path + // The items (files and folders) in the path. Items []fileInfo - // The number of directories in the listing + // The number of directories in the listing. NumDirs int - // The number of files (items that aren't directories) in the listing + // The number of files (items that aren't directories) in the listing. NumFiles int - // Which sorting order is used + // Which sorting order is used. Sort string - // And which order + // And which order. 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 httpserver.Context `json:"-"` } -// GetListing gets the information about a specific directory and its files. -func GetListing(u *user, filePath string, baseURL string) (*Listing, error) { +// getListing gets the information about a specific directory and its files. +func getListing(u *user, filePath string, baseURL string) (*listing, error) { // Gets the directory information using the Virtual File System of // the user configuration. file, err := u.fileSystem.OpenFile(context.TODO(), filePath, os.O_RDONLY, 0) @@ -72,20 +72,19 @@ func GetListing(u *user, filePath string, baseURL string) (*Listing, error) { url := url.URL{Path: baseURL + name} i := fileInfo{ - Name: f.Name(), - Size: f.Size(), - ModTime: f.ModTime(), - Mode: f.Mode(), - IsDir: f.IsDir(), - URL: url.String(), - UserAllowed: allowed, + Name: f.Name(), + Size: f.Size(), + ModTime: f.ModTime(), + Mode: f.Mode(), + IsDir: f.IsDir(), + URL: url.String(), } i.RetrieveFileType() fileinfos = append(fileinfos, i) } - return &Listing{ + return &listing{ Name: path.Base(filePath), Path: filePath, Items: fileinfos, @@ -95,7 +94,7 @@ func GetListing(u *user, filePath string, baseURL string) (*Listing, error) { } // ApplySort applies the sort order using .Order and .Sort -func (l Listing) ApplySort() { +func (l listing) ApplySort() { // Check '.Order' to know how to sort if l.Order == "desc" { switch l.Sort { @@ -124,10 +123,10 @@ func (l Listing) ApplySort() { } } -// Implement sorting for Listing -type byName Listing -type bySize Listing -type byTime Listing +// Implement sorting for listing +type byName listing +type bySize listing +type byTime listing // By Name func (l byName) Len() int {