unexport and rework some more things

pull/144/head
Henrique Dias 2017-06-25 14:48:34 +01:00
parent fffbcc7098
commit e1bee6d07e
No known key found for this signature in database
GPG Key ID: 936F5EB68D786730
5 changed files with 27 additions and 31 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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 {