lib

package
v0.8.9 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2020 License: Apache-2.0 Imports: 22 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 HashPassword

func HashPassword(password string) (string, error)

HashPassword generates an hash from a password using bcrypt.

Types

type Context

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

Context contains the needed information to make handlers work.

func (*Context) CutPath added in v0.8.6

func (c *Context) CutPath(path string) string

cut user home path from for non download routes

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() *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) GetUserSharexPath added in v0.8.7

func (c *Context) GetUserSharexPath() string

func (*Context) IsExternalShare added in v0.8.3

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

true if request contains rootHash param

func (*Context) MakeInfo added in v0.8.7

func (c *Context) MakeInfo() (*File, error)

MakeInfo gets the file information, and replace user in context in case share rquest

func (*Context) ResolveContextUser added in v0.8.7

func (c *Context) ResolveContextUser() (p, previewPath string, err error)

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

func (*Context) ResolvePathContext added in v0.8.7

func (c *Context) ResolvePathContext(i *File) (p string, fs FileSystem)

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 (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) (files []os.FileInfo, paths []string, err error)

recursively fetch share/file paths

func (*File) ProcessList added in v0.8.5

func (i *File) ProcessList(c *Context) error

ProcessList generate metainfo about dir/files

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
	String() string
}

FileSystem is the interface to work with the file system.

type FitFilter added in v0.8.3

type FitFilter func(name, p string) bool

used to filter out specific files by name and path

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"`
	//indicator to the frontend, to prevent request previews
	AllowGeneratePreview bool `json:"allowGeneratePreview"`
}

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

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, nformation about share metadata like list, my-meta.
	ShareType    string
	SearchString string
	/*
		external share item root dir hash,
		note: as a result, cut owner from files paths, and replaces with rootHash(hash value of specific shareItem)
	*/
	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, true if any was specified at request url, uses in FitFilter type
	Audio bool
	Image bool
	Video bool
	Pdf   bool
	//search query
	Query url.Values
	//override existing file
	Override bool
	// used in resource patch requests type
	Destination string
	Action      string
	//is share request
	IsShare bool
	//requestURL
	URL    string
	Method string
	RESP   http.ResponseWriter
	REQ    *http.Request
}

params in URL request

type ReCaptcha

type ReCaptcha struct {
	Host   string
	Key    string
	Secret string
}

ReCaptcha settings.

type UserModel

type UserModel struct {
	*config.UserConfig
	// 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:"-"`
	FileSystemSharex  FileSystem `json:"-"`
}

func ToUserModel added in v0.1.8

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

Directories

Path Synopsis
Package utils implements some useful functions to work with the file system.
Package utils 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