Documentation ¶
Index ¶
- Constants
- Variables
- func InternalError(err error) *zenrpc.Error
- type Config
- type File
- type FileHash
- type FileParams
- type Folder
- type HashIndexer
- func (hi HashIndexer) IndexFile(ns, relFilepath string) (HashInfo, error)
- func (hi HashIndexer) Preview() http.HandlerFunc
- func (hi HashIndexer) ProcessQueue(ctx context.Context) error
- func (hi HashIndexer) ScanFiles(ctx context.Context) (r ScanResults, err error)
- func (hi HashIndexer) ScanFilesHandler(w http.ResponseWriter, _ *http.Request)
- func (hi HashIndexer) Start()
- func (hi HashIndexer) Stop()
- type HashInfo
- type HelpUploadItem
- type HelpUploadResponse
- type ScanFilesResponse
- type ScanResults
- type Service
- func (s Service) CountFiles(ctx context.Context, folderId int, query *string) (int, error)
- func (s Service) CreateFolder(ctx context.Context, rootFolderId int, name string) (bool, error)
- func (s Service) DeleteFiles(ctx context.Context, fileIds []int64) (bool, error)
- func (s Service) DeleteFolder(ctx context.Context, folderId int) (bool, error)
- func (s Service) DeleteHash(ctx context.Context, namespace, hash string) (bool, error)
- func (s Service) GetFavorites(ctx context.Context) ([]Folder, error)
- func (s Service) GetFiles(ctx context.Context, folderId int, query *string, sortField string, ...) ([]File, error)
- func (s Service) GetFolder(ctx context.Context, rootFolderId int) (*Folder, error)
- func (s Service) GetFolderBranch(ctx context.Context, folderId int) ([]Folder, error)
- func (s Service) HelpUpload() HelpUploadResponse
- func (s Service) Invoke(ctx context.Context, method string, params json.RawMessage) zenrpc.Response
- func (s Service) ManageFavorites(ctx context.Context, folderId int, isInFavorites bool) (bool, error)
- func (s Service) MoveFiles(ctx context.Context, fileIds []int64, destinationFolderId int) (bool, error)
- func (s Service) MoveFolder(ctx context.Context, folderId, destinationFolderId int) (bool, error)
- func (s Service) RenameFolder(ctx context.Context, folderId int, name string) (bool, error)
- func (Service) SMD() smd.ServiceInfo
- func (s Service) SearchFolderByFile(ctx context.Context, filename string) (*Folder, error)
- func (s Service) SearchFolderByFileId(ctx context.Context, fileId int) (*Folder, error)
- func (s Service) SetFilePhysicalName(ctx context.Context, fileId int, name string) (bool, error)
- func (s Service) UrlByHash(_ context.Context, hash, namespace, mediaType string) (string, error)
- func (s Service) UrlByHashList(ctx context.Context, hashList []string, namespace, mediaType string) ([]UrlByHashListResponse, error)
- type UploadResponse
- type UrlByHashListResponse
- type VFS
- func (v VFS) FullDir(ns string, h FileHash) string
- func (v VFS) FullFile(ns string, h FileHash) string
- func (v VFS) HashUpload(r io.Reader, ns, ext string) (*FileHash, error)
- func (v VFS) HashUploadHandler(repo *db.VfsRepo) http.HandlerFunc
- func (v VFS) IsValidExtension(ext string) bool
- func (v VFS) IsValidMimeType(mType string) bool
- func (v VFS) IsValidNamespace(ns string) bool
- func (v VFS) Move(ns, currentPath, newPath string) error
- func (v VFS) Path(ns, path string) string
- func (v VFS) PreviewPath(ns string) string
- func (v VFS) Upload(r io.Reader, relFilename, ns string) error
- func (v VFS) UploadHandler(repo db.VfsRepo) http.HandlerFunc
- func (v VFS) WebHashPath(ns string, h FileHash) string
- func (v VFS) WebHashPathWithType(ns, fType string, h FileHash) string
- func (v VFS) WebPath(ns string) string
Examples ¶
Constants ¶
const ( DefaultHashExtension = "jpg" NamespacePublic = "" )
const AtomTime = "02.01.2006 15:04"
const (
DefaultNamespace = "default"
)
Variables ¶
var ( ErrInternal = httpAsRpcError(http.StatusInternalServerError) ErrNotFound = httpAsRpcError(http.StatusNotFound) ErrInvalidSort = zenrpc.NewStringError(http.StatusBadRequest, "invalid sort field") ErrInvalidInput = zenrpc.NewStringError(http.StatusBadRequest, "invalid user input") )
var ( ErrInvalidNamespace = errors.New("invalid namespace") ErrInvalidExtension = errors.New("invalid extension") ErrInvalidMimeType = errors.New("invalid mime type") )
var RPC = struct { Service struct{ GetFolder, GetFolderBranch, GetFiles, CountFiles, MoveFiles, DeleteFiles, SetFilePhysicalName, SearchFolderByFileId, SearchFolderByFile, GetFavorites, ManageFavorites, CreateFolder, DeleteFolder, MoveFolder, RenameFolder, HelpUpload, UrlByHash, UrlByHashList, DeleteHash string } }{ Service: struct{ GetFolder, GetFolderBranch, GetFiles, CountFiles, MoveFiles, DeleteFiles, SetFilePhysicalName, SearchFolderByFileId, SearchFolderByFile, GetFavorites, ManageFavorites, CreateFolder, DeleteFolder, MoveFolder, RenameFolder, HelpUpload, UrlByHash, UrlByHashList, DeleteHash string }{ GetFolder: "getfolder", GetFolderBranch: "getfolderbranch", GetFiles: "getfiles", CountFiles: "countfiles", MoveFiles: "movefiles", DeleteFiles: "deletefiles", SetFilePhysicalName: "setfilephysicalname", SearchFolderByFileId: "searchfolderbyfileid", SearchFolderByFile: "searchfolderbyfile", GetFavorites: "getfavorites", ManageFavorites: "managefavorites", CreateFolder: "createfolder", DeleteFolder: "deletefolder", MoveFolder: "movefolder", RenameFolder: "renamefolder", HelpUpload: "helpupload", UrlByHash: "urlbyhash", UrlByHashList: "urlbyhashlist", DeleteHash: "deletehash", }, }
Functions ¶
func InternalError ¶
func InternalError(err error) *zenrpc.Error
Types ¶
type File ¶
type File struct { ID int `json:"id"` Name string `json:"name"` Path string `json:"path"` PreviewPath string `json:"previewpath"` RelPath string `json:"relpath"` Size int `json:"size"` SizeH []string `json:"sizeH"` Date string `json:"date"` Type string `json:"type"` Extension string `json:"extension"` Params FileParams `json:"params"` Shortpath string `json:"shortpath"` Width *int `json:"width"` Height *int `json:"height"` }
type FileHash ¶
Example ¶
package main import ( "fmt" "github.com/vmkteam/vfs" ) func main() { fh := vfs.NewFileHash("6698364ea6730f327a26bb8a6d3da3be", "") fmt.Println(fh.Dir()) fmt.Println(fh.File()) // automatic rewrite jpeg extension to jpg fh2 := vfs.NewFileHash("6698364ea6730f327a26bb8a6d3da3be", "jpeg") fmt.Println(fh2.File()) }
Output: 6/69 6/69/6698364ea6730f327a26bb8a6d3da3be.jpg 6/69/6698364ea6730f327a26bb8a6d3da3be.jpg
func NewFileHash ¶
type FileParams ¶
type Folder ¶
type HashIndexer ¶
type HashIndexer struct {
// contains filtered or unexported fields
}
func NewHashIndexer ¶
func (HashIndexer) IndexFile ¶
func (hi HashIndexer) IndexFile(ns, relFilepath string) (HashInfo, error)
func (HashIndexer) Preview ¶
func (hi HashIndexer) Preview() http.HandlerFunc
func (HashIndexer) ProcessQueue ¶
func (hi HashIndexer) ProcessQueue(ctx context.Context) error
ProcessQueue gets not indexed data from vfsHashes, index and saves data to db.
func (HashIndexer) ScanFiles ¶
func (hi HashIndexer) ScanFiles(ctx context.Context) (r ScanResults, err error)
ScanFiles reads media folder, detects namespaces & files and loads files into vfsHashes.
func (HashIndexer) ScanFilesHandler ¶
func (hi HashIndexer) ScanFilesHandler(w http.ResponseWriter, _ *http.Request)
func (HashIndexer) Start ¶
func (hi HashIndexer) Start()
func (HashIndexer) Stop ¶
func (hi HashIndexer) Stop()
type HelpUploadItem ¶
type HelpUploadResponse ¶
type HelpUploadResponse struct { Temp HelpUploadItem `json:"temp"` Queue HelpUploadItem `json:"queue"` }
type ScanFilesResponse ¶
type ScanFilesResponse struct { ScanResults `json:",omitempty"` Error string `json:"error,omitempty"` // error message }
type ScanResults ¶
type Service ¶
type Service struct { zenrpc.Service // contains filtered or unexported fields }
func (Service) CountFiles ¶
CountFiles returns count of files.
func (Service) CreateFolder ¶
CreateFolder create virtual folder.
func (Service) DeleteFiles ¶
DeleteFiles remove files.
func (Service) DeleteFolder ¶
DeleteFolder removes Folder.
func (Service) DeleteHash ¶ added in v1.3.0
DeleteHash delete file by namespace and hash.
func (Service) GetFavorites ¶
GetFavorites return favorites list.
func (Service) GetFiles ¶
func (s Service) GetFiles(ctx context.Context, folderId int, query *string, sortField string, isDescending bool, page, pageSize int) ([]File, error)
GetFiles returns list of files.
func (Service) GetFolderBranch ¶
GetFolderBranch returns Folder branch.
func (Service) HelpUpload ¶
func (s Service) HelpUpload() HelpUploadResponse
HelpUpload returns a uploader help info.
func (Service) ManageFavorites ¶
func (s Service) ManageFavorites(ctx context.Context, folderId int, isInFavorites bool) (bool, error)
ManageFavorites manage favorite virtual folders.
func (Service) MoveFiles ¶
func (s Service) MoveFiles(ctx context.Context, fileIds []int64, destinationFolderId int) (bool, error)
MoveFiles move files to destination folder.
func (Service) MoveFolder ¶
MoveFolder move Folder to destination folder.
func (Service) RenameFolder ¶
RenameFolder change Folder name.
func (Service) SMD ¶
func (Service) SMD() smd.ServiceInfo
func (Service) SearchFolderByFile ¶
SearchFolderByFile return Folder by File name.
func (Service) SearchFolderByFileId ¶
SearchFolderByFileId return Folder by File id.
func (Service) SetFilePhysicalName ¶
SetFilePhysicalName renames File on server.
func (Service) UrlByHashList ¶
func (s Service) UrlByHashList(ctx context.Context, hashList []string, namespace, mediaType string) ([]UrlByHashListResponse, error)
UrlByHashList get Urls by hash list, with namespace and media type
type UploadResponse ¶
type UploadResponse struct { Code int `json:"-"` // http status code Error string `json:"error,omitempty"` // error message Hash string `json:"hash,omitempty"` // for hash WebPath string `json:"webPath,omitempty"` // for hash FileID int `json:"id,omitempty"` // vfs file id Extension string `json:"ext,omitempty"` // vfs file ext Name string `json:"name,omitempty"` // vfs file name Size int64 `json:"-"` }
type UrlByHashListResponse ¶
type VFS ¶
type VFS struct {
// contains filtered or unexported fields
}
func (VFS) HashUploadHandler ¶
func (v VFS) HashUploadHandler(repo *db.VfsRepo) http.HandlerFunc
func (VFS) IsValidExtension ¶
func (VFS) IsValidMimeType ¶ added in v1.2.0
func (VFS) IsValidNamespace ¶
func (VFS) PreviewPath ¶
func (VFS) UploadHandler ¶
func (v VFS) UploadHandler(repo db.VfsRepo) http.HandlerFunc