parent
a4fe27a6d6
commit
f917b4222c
|
@ -24,7 +24,7 @@ type Editor struct {
|
|||
}
|
||||
|
||||
// GetEditor gets the editor based on a Info struct
|
||||
func GetEditor(r *http.Request, i *FileInfo) (*Editor, error) {
|
||||
func GetEditor(r *http.Request, i *fileInfo) (*Editor, error) {
|
||||
var err error
|
||||
|
||||
// Create a new editor variable and set the mode
|
||||
|
|
4
http.go
4
http.go
|
@ -18,7 +18,7 @@ func matchURL(first, second string) bool {
|
|||
// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met.
|
||||
func (c *FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
var (
|
||||
fi *FileInfo
|
||||
fi *fileInfo
|
||||
code int
|
||||
err error
|
||||
user *user
|
||||
|
@ -131,7 +131,7 @@ func (c *FileManager) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, er
|
|||
|
||||
if r.Method == http.MethodGet {
|
||||
// Gets the information of the directory/file
|
||||
fi, err = GetInfo(r.URL, c, user)
|
||||
fi, err = getInfo(r.URL, c, user)
|
||||
if err != nil {
|
||||
if r.Method == http.MethodGet {
|
||||
return htmlError(w, code, err)
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
)
|
||||
|
||||
// checksum calculates the hash of a file. Supports MD5, SHA1, SHA256 and SHA512.
|
||||
func checksum(w http.ResponseWriter, r *http.Request, i *FileInfo) (int, error) {
|
||||
func checksum(w http.ResponseWriter, r *http.Request, i *fileInfo) (int, error) {
|
||||
query := r.URL.Query().Get("checksum")
|
||||
|
||||
file, err := os.Open(i.Path)
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
|
||||
// download creates an archive in one of the supported formats (zip, tar,
|
||||
// tar.gz or tar.bz2) and sends it to be downloaded.
|
||||
func download(w http.ResponseWriter, r *http.Request, i *FileInfo) (int, error) {
|
||||
func download(w http.ResponseWriter, r *http.Request, i *fileInfo) (int, error) {
|
||||
query := r.URL.Query().Get("download")
|
||||
|
||||
if !i.IsDir {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
// serveListing presents the user with a listage of a directory folder.
|
||||
func serveListing(w http.ResponseWriter, r *http.Request, c *FileManager, u *user, i *FileInfo) (int, error) {
|
||||
func serveListing(w http.ResponseWriter, r *http.Request, c *FileManager, u *user, i *fileInfo) (int, error) {
|
||||
var err error
|
||||
|
||||
// Loads the content of the directory
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
// serveSingle serves a single file in an editor (if it is editable), shows the
|
||||
// plain file, or downloads it if it can't be shown.
|
||||
func serveSingle(w http.ResponseWriter, r *http.Request, c *FileManager, u *user, i *FileInfo) (int, error) {
|
||||
func serveSingle(w http.ResponseWriter, r *http.Request, c *FileManager, u *user, i *fileInfo) (int, error) {
|
||||
var err error
|
||||
|
||||
if err = i.RetrieveFileType(); err != nil {
|
||||
|
|
22
info.go
22
info.go
|
@ -13,8 +13,8 @@ import (
|
|||
humanize "github.com/dustin/go-humanize"
|
||||
)
|
||||
|
||||
// FileInfo contains the information about a particular file or directory
|
||||
type FileInfo struct {
|
||||
// fileInfo contains the information about a particular file or directory.
|
||||
type fileInfo struct {
|
||||
Name string
|
||||
Size int64
|
||||
URL string
|
||||
|
@ -31,12 +31,12 @@ type FileInfo struct {
|
|||
content []byte
|
||||
}
|
||||
|
||||
// GetInfo gets the file information and, in case of error, returns the
|
||||
// getInfo gets the file information and, in case of error, returns the
|
||||
// respective HTTP error code
|
||||
func GetInfo(url *url.URL, c *FileManager, u *user) (*FileInfo, error) {
|
||||
func getInfo(url *url.URL, c *FileManager, u *user) (*fileInfo, error) {
|
||||
var err error
|
||||
|
||||
i := &FileInfo{URL: c.PrefixURL + url.Path}
|
||||
i := &fileInfo{URL: c.PrefixURL + url.Path}
|
||||
i.VirtualPath = strings.Replace(url.Path, c.BaseURL, "", 1)
|
||||
i.VirtualPath = strings.TrimPrefix(i.VirtualPath, "/")
|
||||
i.VirtualPath = "/" + i.VirtualPath
|
||||
|
@ -77,7 +77,7 @@ var textExtensions = [...]string{
|
|||
|
||||
// RetrieveFileType obtains the mimetype and a simplified internal Type
|
||||
// using the first 512 bytes from the file.
|
||||
func (i *FileInfo) RetrieveFileType() error {
|
||||
func (i *fileInfo) RetrieveFileType() error {
|
||||
i.Mimetype = mime.TypeByExtension(i.Extension)
|
||||
|
||||
if i.Mimetype == "" {
|
||||
|
@ -128,7 +128,7 @@ func (i *FileInfo) RetrieveFileType() error {
|
|||
}
|
||||
|
||||
// Reads the file.
|
||||
func (i *FileInfo) Read() error {
|
||||
func (i *fileInfo) Read() error {
|
||||
if len(i.content) != 0 {
|
||||
return nil
|
||||
}
|
||||
|
@ -142,22 +142,22 @@ func (i *FileInfo) Read() error {
|
|||
}
|
||||
|
||||
// StringifyContent returns the string version of Raw
|
||||
func (i FileInfo) StringifyContent() string {
|
||||
func (i fileInfo) StringifyContent() string {
|
||||
return string(i.content)
|
||||
}
|
||||
|
||||
// HumanSize returns the size of the file as a human-readable string
|
||||
// in IEC format (i.e. power of 2 or base 1024).
|
||||
func (i FileInfo) HumanSize() string {
|
||||
func (i fileInfo) HumanSize() string {
|
||||
return humanize.IBytes(uint64(i.Size))
|
||||
}
|
||||
|
||||
// HumanModTime returns the modified time of the file as a human-readable string.
|
||||
func (i FileInfo) HumanModTime(format string) string {
|
||||
func (i fileInfo) HumanModTime(format string) string {
|
||||
return i.ModTime.Format(format)
|
||||
}
|
||||
|
||||
// CanBeEdited checks if the extension of a file is supported by the editor
|
||||
func (i FileInfo) CanBeEdited() bool {
|
||||
func (i fileInfo) CanBeEdited() bool {
|
||||
return i.Type == "text"
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ type Listing struct {
|
|||
// The full path of the request relatively to a File System
|
||||
Path string
|
||||
// The items (files and folders) in the path
|
||||
Items []FileInfo
|
||||
Items []fileInfo
|
||||
// The number of directories in the listing
|
||||
NumDirs int
|
||||
// The number of files (items that aren't directories) in the listing
|
||||
|
@ -49,7 +49,7 @@ func GetListing(u *user, filePath string, baseURL string) (*Listing, error) {
|
|||
}
|
||||
|
||||
var (
|
||||
fileinfos []FileInfo
|
||||
fileinfos []fileInfo
|
||||
dirCount, fileCount int
|
||||
)
|
||||
|
||||
|
@ -71,7 +71,7 @@ func GetListing(u *user, filePath string, baseURL string) (*Listing, error) {
|
|||
// Absolute URL
|
||||
url := url.URL{Path: baseURL + name}
|
||||
|
||||
i := FileInfo{
|
||||
i := fileInfo{
|
||||
Name: f.Name(),
|
||||
Size: f.Size(),
|
||||
ModTime: f.ModTime(),
|
||||
|
|
Loading…
Reference in New Issue