unexport and rework some more things
parent
fffbcc7098
commit
e1bee6d07e
|
@ -24,7 +24,7 @@ type editor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// getEditor gets the editor based on a Info 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
|
var err error
|
||||||
|
|
||||||
// Create a new editor variable and set the mode
|
// Create a new editor variable and set the mode
|
||||||
|
|
|
@ -34,9 +34,6 @@ type fileInfo struct {
|
||||||
|
|
||||||
// Indicates the file content type: video, text, image, music or blob.
|
// Indicates the file content type: video, text, image, music or blob.
|
||||||
Type string
|
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
|
// getInfo gets the file information and, in case of error, returns the
|
|
@ -14,7 +14,7 @@ func serveListing(w http.ResponseWriter, r *http.Request, c *FileManager, u *use
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Loads the content of the directory
|
// 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 {
|
if err != nil {
|
||||||
return errorToHTTP(err, true), err
|
return errorToHTTP(err, true), err
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ func serveSingle(w http.ResponseWriter, r *http.Request, c *FileManager, u *user
|
||||||
}
|
}
|
||||||
|
|
||||||
if i.CanBeEdited() && u.AllowEdit {
|
if i.CanBeEdited() && u.AllowEdit {
|
||||||
p.Data, err = GetEditor(r, i)
|
p.Data, err = getEditor(r, i)
|
||||||
p.Editor = true
|
p.Editor = true
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
|
|
49
listing.go
49
listing.go
|
@ -11,29 +11,29 @@ import (
|
||||||
"github.com/mholt/caddy/caddyhttp/httpserver"
|
"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.
|
||||||
type Listing struct {
|
type listing struct {
|
||||||
// The name of the directory (the last element of the path)
|
// The name of the directory (the last element of the path).
|
||||||
Name string
|
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
|
Path string
|
||||||
// The items (files and folders) in the path
|
// The items (files and folders) in the path.
|
||||||
Items []fileInfo
|
Items []fileInfo
|
||||||
// The number of directories in the listing
|
// The number of directories in the listing.
|
||||||
NumDirs int
|
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
|
NumFiles int
|
||||||
// Which sorting order is used
|
// Which sorting order is used.
|
||||||
Sort string
|
Sort string
|
||||||
// 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:"-"`
|
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.
|
||||||
func GetListing(u *user, filePath string, baseURL string) (*Listing, error) {
|
func getListing(u *user, filePath string, baseURL string) (*listing, error) {
|
||||||
// Gets the directory information using the Virtual File System of
|
// Gets the directory information using the Virtual File System of
|
||||||
// the user configuration.
|
// the user configuration.
|
||||||
file, err := u.fileSystem.OpenFile(context.TODO(), filePath, os.O_RDONLY, 0)
|
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}
|
url := url.URL{Path: baseURL + name}
|
||||||
|
|
||||||
i := fileInfo{
|
i := fileInfo{
|
||||||
Name: f.Name(),
|
Name: f.Name(),
|
||||||
Size: f.Size(),
|
Size: f.Size(),
|
||||||
ModTime: f.ModTime(),
|
ModTime: f.ModTime(),
|
||||||
Mode: f.Mode(),
|
Mode: f.Mode(),
|
||||||
IsDir: f.IsDir(),
|
IsDir: f.IsDir(),
|
||||||
URL: url.String(),
|
URL: url.String(),
|
||||||
UserAllowed: allowed,
|
|
||||||
}
|
}
|
||||||
i.RetrieveFileType()
|
i.RetrieveFileType()
|
||||||
|
|
||||||
fileinfos = append(fileinfos, i)
|
fileinfos = append(fileinfos, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Listing{
|
return &listing{
|
||||||
Name: path.Base(filePath),
|
Name: path.Base(filePath),
|
||||||
Path: filePath,
|
Path: filePath,
|
||||||
Items: fileinfos,
|
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
|
// ApplySort applies the sort order using .Order and .Sort
|
||||||
func (l Listing) ApplySort() {
|
func (l listing) ApplySort() {
|
||||||
// Check '.Order' to know how to sort
|
// Check '.Order' to know how to sort
|
||||||
if l.Order == "desc" {
|
if l.Order == "desc" {
|
||||||
switch l.Sort {
|
switch l.Sort {
|
||||||
|
@ -124,10 +123,10 @@ func (l Listing) ApplySort() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement sorting for Listing
|
// Implement sorting for listing
|
||||||
type byName Listing
|
type byName listing
|
||||||
type bySize Listing
|
type bySize listing
|
||||||
type byTime Listing
|
type byTime listing
|
||||||
|
|
||||||
// By Name
|
// By Name
|
||||||
func (l byName) Len() int {
|
func (l byName) Len() int {
|
||||||
|
|
Loading…
Reference in New Issue