You've already forked filebrowser
mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-11-26 14:25:26 +08:00
22
file.go
22
file.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 {
|
||||
// file contains the information about a particular file or directory.
|
||||
type file struct {
|
||||
Name string
|
||||
Size int64
|
||||
URL string
|
||||
@@ -30,11 +30,11 @@ type FileInfo struct {
|
||||
UserAllowed bool // Indicates if the user has enough permissions
|
||||
}
|
||||
|
||||
// GetInfo retrieves the file information and the error, if there is any.
|
||||
func GetInfo(url *url.URL, c *Config, u *User) (*FileInfo, error) {
|
||||
// getFile retrieves the file information and the error, if there is any.
|
||||
func getFile(url *url.URL, c *Config, u *User) (*file, error) {
|
||||
var err error
|
||||
|
||||
i := &FileInfo{URL: c.PrefixURL + url.Path}
|
||||
i := &file{URL: c.PrefixURL + url.Path}
|
||||
i.VirtualPath = strings.Replace(url.Path, c.BaseURL, "", 1)
|
||||
i.VirtualPath = strings.TrimPrefix(i.VirtualPath, "/")
|
||||
i.VirtualPath = "/" + i.VirtualPath
|
||||
@@ -75,7 +75,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 *file) RetrieveFileType() error {
|
||||
i.Mimetype = mime.TypeByExtension(i.Extension)
|
||||
|
||||
if i.Mimetype == "" {
|
||||
@@ -126,7 +126,7 @@ func (i *FileInfo) RetrieveFileType() error {
|
||||
}
|
||||
|
||||
// Reads the file.
|
||||
func (i *FileInfo) Read() error {
|
||||
func (i *file) Read() error {
|
||||
if len(i.Content) != 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -140,22 +140,22 @@ func (i *FileInfo) Read() error {
|
||||
}
|
||||
|
||||
// StringifyContent returns the string version of Raw
|
||||
func (i FileInfo) StringifyContent() string {
|
||||
func (i file) 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 file) 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 file) 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 file) CanBeEdited() bool {
|
||||
return i.Type == "text"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user