lib

package
v0.8.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

CheckPasswordHash compares a password with an hash to check if they match.

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an fm.Error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GetMimeType added in v0.8.4

func GetMimeType(f string) string

func HashPassword

func HashPassword(password string) (string, error)

HashPassword generates an hash from a password using bcrypt.

func ResolvePaths added in v0.8.3

func ResolvePaths(c *Context, url string) (p, previewPath, urlPath string, err error)

build correct path, and replace user in context in case external share

func SplitURL added in v0.8.3

func SplitURL(path string) (int, string)

SplitURL splits the path and returns everything that stands before the first slash and everything that goes after.

Types

type Context

type Context struct {
	*FileBrowser
	User *UserModel
	File *File
	// On API handlers, Router is the APi handler we want.
	Router int
	*Params
}

Context contains the needed information to make handlers work.

func (*Context) GenPreview

func (c *Context) GenPreview(out string)

func (*Context) GenSharesPreview added in v0.8.3

func (c *Context) GenSharesPreview(out string)

func (*Context) GetAuthConfig added in v0.8.3

func (c *Context) GetAuthConfig(r *http.Request) *config.ListenConf

func (*Context) GetUserHomePath added in v0.1.8

func (c *Context) GetUserHomePath() string

func (*Context) GetUserPreviewPath added in v0.1.8

func (c *Context) GetUserPreviewPath() string

func (*Context) GetUserSharesPath added in v0.8.3

func (c *Context) GetUserSharesPath() string

func (*Context) IsExternalShare added in v0.8.3

func (c *Context) IsExternalShare() (r bool)

type FSBuilder

type FSBuilder func(scope string) FileSystem

FSBuilder is the File System Builder.

type File

type File struct {
	// Indicates the Kind of view on the front-end (Listing, editor or preview).
	Kind string `json:"kind"`
	// The name of the file.
	Name string `json:"name"`
	// The Size of the file.
	Size int64 `json:"size"`
	// The absolute URL.
	URL string `json:"url"`
	// The extension of the file.
	//Extension string `json:"extension"`
	// The last modified time.
	ModTime time.Time `json:"modified"`
	// The File Mode.
	//Mode os.FileMode `json:"mode"`
	// Indicates if this file is a directory.
	IsDir bool `json:"isDir"`
	// Absolute path.
	Path string `json:"-"`
	// Relative path to user's virtual File System.
	VirtualPath string `json:"-"`
	// Indicates the file content type: video, text, image, music or blob.
	Type string `json:"type"`
	// Stores the content of a text file.
	Content string `json:"content,omitempty"`

	Checksums map[string]string `json:"checksums,omitempty"`
	*Listing  `json:",omitempty"`

	Language string `json:"language,omitempty"`
}

File contains the information about a particular file or directory.

func MakeInfo added in v0.1.8

func MakeInfo(urlPath, urlString string, c *Context) (*File, error)

MakeInfo gets the file information and, in case of error, returns the respective HTTP error code

func (File) CanBeEdited

func (i File) CanBeEdited() bool

CanBeEdited checks if the extension of a file is supported by the editor

func (*File) Checksum

func (i *File) Checksum(algo string) error

Checksum retrieves the checksum of a file.

func (*File) GetListing

func (i *File) GetListing(c *Context, fitFilter FitFilter) error

GetListing gets the information about a specific directory and its files.

func (*File) MakeListing added in v0.8.3

func (i *File) MakeListing(c *Context, fitFilter FitFilter) (files []os.FileInfo, paths []string, err error)

func (*File) SetFileType

func (f *File) SetFileType(checkContent bool)

SetFileType obtains the mimetype and converts it to a simple type nomenclature.

type FileBrowser

type FileBrowser struct {
	// The static assets.
	Assets *rice.Box
	// ReCaptcha host, key and secret.
	ReCaptcha *ReCaptcha
	// NewFS should build a new file system for a given path.
	NewFS FSBuilder
	//generates preview
	Pgen   *preview.PreviewGen
	Config *config.GlobalConfig
}

FileBrowser is a file manager instance. It should be creating using the 'New' function and not directly.

func (*FileBrowser) Setup

func (fb *FileBrowser) Setup() (bool, error)

Setup loads the configuration from the database and configures the Assets and the Cron job. It must always be run after creating a File Browser object.

type FileSystem

type FileSystem interface {
	Mkdir(name string, perm os.FileMode, uid, gid int) error
	OpenFile(name string, flag int, perm os.FileMode, uid, gid int) (*os.File, error)
	RemoveAll(name string) error
	Rename(oldName, newName string) error
	Stat(name string) (os.FileInfo, error)
	Copy(src, dst string, uid, gid int) error
}

FileSystem is the interface to work with the file system.

type FitFilter added in v0.8.3

type FitFilter func(name, p string) bool

type Listing

type Listing struct {
	// The items (files and folders) in the path.
	Items []*File `json:"items"`
	// The number of directories in the Listing.
	NumDirs int `json:"numDirs"`
	// The number of files (items that aren't directories) in the Listing.
	NumFiles int `json:"numFiles"`
	// Which sorting order is used.
	Sort string `json:"sort"`
	// And which order.
	Order string `json:"order"`
	//indicator to the frontend, to prevent request previews
	AllowGeneratePreview bool `json:"allowGeneratePreview"`
}

A Listing is the context used to fill out a template.

func (Listing) ApplySort

func (l Listing) ApplySort()

ApplySort applies the sort order using .Order and .Sort

type Params added in v0.8.3

type Params struct {
	//indicate that requested preview
	PreviewType string
	//return files list by recursion
	IsRecursive bool
	//indicate about share request
	ShareType    string
	SearchString string
	//external share item root dir hash
	RootHash string
	//download type, zip or playlist m3u8
	Algo string
	//download multiple files
	FilePaths []string

	Auth string

	Checksum string

	Inline bool
	// playlist & search file mime types
	Audio bool
	Image bool
	Video bool
	Pdf   bool
	Query url.Values
	//override existing file
	Override bool
	// used in resource patch requests type
	Destination string
	Action      string

	Sort  string
	Order string
	//is share request
	IsShare bool
}

params in URL request

type ReCaptcha

type ReCaptcha struct {
	Host   string
	Key    string
	Secret string
}

ReCaptcha settings.

type UserModel

type UserModel struct {
	*config.UserConfig
	ID string `json:"ID"`
	// FileSystem is the virtual file system the user has access.
	FileSystem FileSystem `json:"-"`
	// FileSystem is the virtual file system the user has access, uses to store previews.
	FileSystemPreview FileSystem `json:"-"`
	FileSystemShares  FileSystem `json:"-"`
}

func ToUserModel added in v0.1.8

func ToUserModel(u *config.UserConfig, cfg *config.GlobalConfig) *UserModel

Directories

Path Synopsis
Package fileutils implements some useful functions to work with the file system.
Package fileutils implements some useful functions to work with the file system.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL