vfs

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 36 Imported by: 0

README

VFS Service

Examples

Hash upload

curl --upload-file image.jpg http://localhost:9999/upload/hash

How to run
createdb vfs
psql -f docs/vfs.sql vfs
mkdir testdata
make run
Upload image
wget -O image.jpg https://media.myshows.me/shows/e/22/e22c3ab75b956c6c1c1fca8182db7efb.jpg
export AUTHTOKEN=`curl http://localhost:9999/auth-token`    
curl --upload-file image.jpg  -H  "AuthorizationJWT: ${AUTHTOKEN}" http://localhost:9999/upload/hash
open http://localhost:9999/media/6/4a/64a9f060983200709061894cc5f69f83.jpg

Documentation

Index

Examples

Constants

View Source
const (
	DefaultHashExtension = "jpg"
	NamespacePublic      = ""
)
View Source
const AtomTime = "02.01.2006 15:04"
View Source
const (
	DefaultNamespace = "default"
)

Variables

View Source
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")
)
View Source
var (
	ErrInvalidNamespace = errors.New("invalid namespace")
	ErrInvalidExtension = errors.New("invalid extension")
)
View Source
var RPC = struct {
	Service struct{ GetFolder, GetFolderBranch, GetFiles, CountFiles, MoveFiles, DeleteFiles, SetFilePhysicalName, SearchFolderByFileId, SearchFolderByFile, GetFavorites, ManageFavorites, CreateFolder, DeleteFolder, MoveFolder, RenameFolder, HelpUpload, UrlByHash, UrlByHashList string }
}{
	Service: struct{ GetFolder, GetFolderBranch, GetFiles, CountFiles, MoveFiles, DeleteFiles, SetFilePhysicalName, SearchFolderByFileId, SearchFolderByFile, GetFavorites, ManageFavorites, CreateFolder, DeleteFolder, MoveFolder, RenameFolder, HelpUpload, UrlByHash, UrlByHashList 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",
	},
}

Functions

func InternalError

func InternalError(err error) *zenrpc.Error

Types

type Config

type Config struct {
	MaxFileSize      int64
	Path             string
	WebPath          string
	PreviewPath      string
	Database         *pg.Options
	Namespaces       []string
	Extensions       []string
	UploadFormName   string
	SaltedFilenames  bool
	SkipFolderVerify bool
}

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"`
}

func NewFile

func NewFile(in *db.VfsFile, webpath, previewpath string) *File

type FileHash

type FileHash struct {
	Hash string
	Ext  string
}
Example
package main

import (
	"fmt"

	"github.com/vmkteam/vfs"
)

func main() {
	fh := vfs.NewFileHash("6698364ea6730f327a26bb8a6d3da3be", "")
	fmt.Println(fh.Dir())
	fmt.Println(fh.File())
}
Output:

6/69
6/69/6698364ea6730f327a26bb8a6d3da3be.jpg

func NewFileHash

func NewFileHash(hash, ext string) FileHash

func (FileHash) Dir

func (h FileHash) Dir() string

func (FileHash) File

func (h FileHash) File() string

type FileParams

type FileParams struct {
	Width  int `json:"width,omitempty"`
	Height int `json:"height,omitempty"`
}

type Folder

type Folder struct {
	ID       int      `json:"id"`
	Name     string   `json:"name"`
	ParentID *int     `json:"parentId"`
	Folders  []Folder `json:"folders,omitempty"`
}

func NewFolder

func NewFolder(in *db.VfsFolder) *Folder

func NewFullFolder

func NewFullFolder(in *db.VfsFolder, childFolders []db.VfsFolder) *Folder

type HashIndexer

type HashIndexer struct {
	// contains filtered or unexported fields
}

func NewHashIndexer

func NewHashIndexer(dbc db.DB, repo *db.VfsRepo, vfs VFS, totalWorkers int) *HashIndexer

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 HashInfo

type HashInfo struct {
	Hash      string
	Extension string
	Width     int
	Height    int
	FileSize  int64
	BlurHash  string
}

type HelpUploadItem

type HelpUploadItem struct {
	URL    string   `json:"url"`
	Params []string `json:"params"`
}

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 ScanResults struct {
	Scanned  uint64        `json:"scanned"`
	Added    uint64        `json:"added"`
	Duration time.Duration `json:"duration"`
}

type Service

type Service struct {
	zenrpc.Service
	// contains filtered or unexported fields
}

func NewService

func NewService(repo db.VfsRepo, vfs VFS, dbc *pg.DB) Service

func (Service) CountFiles

func (s Service) CountFiles(ctx context.Context, folderId int, query *string) (int, error)

Count Files

func (Service) CreateFolder

func (s Service) CreateFolder(ctx context.Context, rootFolderId int, name string) (bool, error)

Create Folder

func (Service) DeleteFiles

func (s Service) DeleteFiles(ctx context.Context, fileIds []int64) (bool, error)

Delete Files

func (Service) DeleteFolder

func (s Service) DeleteFolder(ctx context.Context, folderId int) (bool, error)

Delete Folder

func (Service) GetFavorites

func (s Service) GetFavorites(ctx context.Context) ([]Folder, error)

Get Favorites

func (Service) GetFiles

func (s Service) GetFiles(ctx context.Context, folderId int, query *string, sortField string, isDescending bool, page, pageSize int) ([]File, error)

Get Files

func (Service) GetFolder

func (s Service) GetFolder(ctx context.Context, rootFolderId int) (*Folder, error)

Get Folder with Sub Folders.

func (Service) GetFolderBranch

func (s Service) GetFolderBranch(ctx context.Context, folderId int) ([]Folder, error)

Get Folder Branch

func (Service) HelpUpload

func (s Service) HelpUpload() HelpUploadResponse

func (Service) Invoke

func (s Service) Invoke(ctx context.Context, method string, params json.RawMessage) zenrpc.Response

Invoke is as generated code from zenrpc cmd

func (Service) ManageFavorites

func (s Service) ManageFavorites(ctx context.Context, folderId int, isInFavorites bool) (bool, error)

Manage Favorite Folders

func (Service) MoveFiles

func (s Service) MoveFiles(ctx context.Context, fileIds []int64, destinationFolderId int) (bool, error)

Move Files

func (Service) MoveFolder

func (s Service) MoveFolder(ctx context.Context, folderId, destinationFolderId int) (bool, error)

Move Folder

func (Service) RenameFolder

func (s Service) RenameFolder(ctx context.Context, folderId int, name string) (bool, error)

Move Folder

func (Service) SMD

func (Service) SMD() smd.ServiceInfo

func (Service) SearchFolderByFile

func (s Service) SearchFolderByFile(ctx context.Context, filename string) (*Folder, error)

Search Folder by Filename

func (Service) SearchFolderByFileId

func (s Service) SearchFolderByFileId(ctx context.Context, fileId int) (*Folder, error)

Search Folder by File Id

func (Service) SetFilePhysicalName

func (s Service) SetFilePhysicalName(ctx context.Context, fileId int, name string) (bool, error)

Rename File on Server

func (Service) UrlByHash

func (s Service) UrlByHash(ctx context.Context, hash, namespace, mediaType string) (string, error)

Get Url by hash, namespace and media type

func (Service) UrlByHashList

func (s Service) UrlByHashList(ctx context.Context, hashList []string, namespace, mediaType string) ([]UrlByHashListResponse, error)

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 UrlByHashListResponse struct {
	Hash    string `json:"hash"`
	WebPath string `json:"webPath"`
}

type VFS

type VFS struct {
	// contains filtered or unexported fields
}

func New

func New(cfg Config) (VFS, error)

func (VFS) FullDir

func (v VFS) FullDir(ns string, h FileHash) string

func (VFS) FullFile

func (v VFS) FullFile(ns string, h FileHash) string

func (VFS) HashUpload

func (v VFS) HashUpload(r io.Reader, ns, ext string) (*FileHash, error)

func (VFS) HashUploadHandler

func (v VFS) HashUploadHandler(repo *db.VfsRepo) http.HandlerFunc

func (VFS) IsValidExtension

func (v VFS) IsValidExtension(ext string) bool

func (VFS) IsValidNamespace

func (v VFS) IsValidNamespace(ns string) bool

func (VFS) Move

func (v VFS) Move(ns, currentPath, newPath string) error

func (VFS) Path

func (v VFS) Path(ns, path string) string

func (VFS) PreviewPath

func (v VFS) PreviewPath(ns string) string

func (VFS) Upload

func (v VFS) Upload(r io.Reader, relFilename, ns string) error

func (VFS) UploadHandler

func (v VFS) UploadHandler(repo db.VfsRepo) http.HandlerFunc

func (VFS) WebHashPath

func (v VFS) WebHashPath(ns string, h FileHash) string

func (VFS) WebHashPathWithType

func (v VFS) WebHashPathWithType(ns, fType string, h FileHash) string

func (VFS) WebPath

func (v VFS) WebPath(ns string) string

Directories

Path Synopsis
cmd
vfssrv command
nolint nolint nolint
nolint nolint nolint

Jump to

Keyboard shortcuts

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