manager

package
v4.0.0-...-a1ce16b Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: GPL-3.0 Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UploadSessionCachePrefix = "callback_"
	// Ctx key for upload session
	UploadSessionCtx = "uploadSession"
)
View Source
const (
	EntityUrlCacheKeyPrefix     = "entity_url_"
	DownloadSentinelCachePrefix = "download_sentinel_"
)
View Source
const (
	MinimumTrashCollectBatch = 1000
)
View Source
const (
	ViewerSessionCachePrefix = "viewer_session_"
)

Variables

View Source
var (
	ErrUnknownPolicyType = serializer.NewError(serializer.CodeInternalSetting, "Unknown policy type", nil)
)

Functions

func CronCollectTrashBin

func CronCollectTrashBin(ctx context.Context)

CronCollectTrashBin walks through all files in trash bin and delete them if they are expired.

func NewEntityRecycleRoutineTask

func NewEntityRecycleRoutineTask(ctx context.Context) (queue.Task, error)

func NewEntityRecycleRoutineTaskFromModel

func NewEntityRecycleRoutineTaskFromModel(task *ent.Task) queue.Task

func NewExplicitEntityRecycleTaskFromModel

func NewExplicitEntityRecycleTaskFromModel(task *ent.Task) queue.Task

func NewMediaMetaTaskFromModel

func NewMediaMetaTaskFromModel(task *ent.Task) queue.Task

func NewUploadSentinelCheckTaskFromModel

func NewUploadSentinelCheckTaskFromModel(task *ent.Task) queue.Task

func ViewerFromContext

func ViewerFromContext(ctx context.Context) *types.Viewer

Types

type Archiver

type Archiver interface {
	CreateArchive(ctx context.Context, uris []*fs.URI, writer io.Writer, opts ...fs.Option) (int, error)
}

type CreateShareArgs

type CreateShareArgs struct {
	ExistedShareID  int
	IsPrivate       bool
	Password        string
	RemainDownloads int
	Expire          *time.Time
	ShareView       bool
	ShowReadMe      bool
}

CreateShareArgs args to create share link

type DirectLink struct {
	File fs.File
	Url  string
}

type EntityManagement

type EntityManagement interface {
	// GetEntityUrls gets download urls of given entities, return URLs and the earliest expiry time
	GetEntityUrls(ctx context.Context, args []GetEntityUrlArgs, opts ...fs.Option) ([]EntityUrl, *time.Time, error)
	// GetUrlForRedirectedDirectLink gets redirected direct download link of given direct link
	GetUrlForRedirectedDirectLink(ctx context.Context, dl *ent.DirectLink, opts ...fs.Option) (string, *time.Time, error)
	// GetDirectLink gets permanent direct download link of given files
	GetDirectLink(ctx context.Context, urls ...*fs.URI) ([]DirectLink, error)
	// GetEntitySource gets source of given entity
	GetEntitySource(ctx context.Context, entityID int, opts ...fs.Option) (entitysource.EntitySource, error)
	// Thumbnail gets thumbnail entity of given file
	Thumbnail(ctx context.Context, uri *fs.URI) (entitysource.EntitySource, error)
	// SubmitAndAwaitThumbnailTask submits a thumbnail task and waits for result
	SubmitAndAwaitThumbnailTask(ctx context.Context, uri *fs.URI, ext string, entity fs.Entity) (fs.Entity, error)
	// SetCurrentVersion sets current version of given file
	SetCurrentVersion(ctx context.Context, path *fs.URI, version int) error
	// DeleteVersion deletes a version of given file
	DeleteVersion(ctx context.Context, path *fs.URI, version int) error
	// ExtractAndSaveMediaMeta extracts and saves media meta into file metadata of given file.
	ExtractAndSaveMediaMeta(ctx context.Context, uri *fs.URI, entityID int) error
	// RecycleEntities recycles a group of entities
	RecycleEntities(ctx context.Context, force bool, entityIDs ...int) error
	// ListPhysical lists physical files in a path
	ListPhysical(ctx context.Context, path string, policyID int, recursive bool, progress driver.ListProgressFunc) ([]fs.PhysicalObject, error)
	// ImportPhysical imports a physical file to a Cloudreve file
	ImportPhysical(ctx context.Context, dst *fs.URI, policyId int, src fs.PhysicalObject, completeHook bool) error
}

type EntityRecycleRoutineTask

type EntityRecycleRoutineTask struct {
	*queue.DBTask
}

func (*EntityRecycleRoutineTask) Do

type EntityRecycleRoutineTaskState

type EntityRecycleRoutineTaskState struct {
	Errors [][]RecycleError `json:"errors,omitempty"`
}

type EntityUrl

type EntityUrl struct {
	Url                        string `json:"url"`
	BrowserDownloadDisplayName string `json:"stream_saver_display_name,omitempty"`
}

type EntityUrlCache

type EntityUrlCache struct {
	Url                        string
	BrowserDownloadDisplayName string
	ExpireAt                   *time.Time
}

type ExplicitEntityRecycleTask

type ExplicitEntityRecycleTask struct {
	*queue.DBTask
}

func (*ExplicitEntityRecycleTask) Do

type ExplicitEntityRecycleTaskState

type ExplicitEntityRecycleTaskState struct {
	EntityIDs []int            `json:"entity_ids,omitempty"`
	Errors    [][]RecycleError `json:"errors,omitempty"`
}

type FileManager

type FileManager interface {
	fs.LockSystem
	FileOperation
	EntityManagement
	UploadManagement
	FsManagement
	ShareManagement
	Archiver

	// Recycle reset current FileManager object and put back to resource pool
	Recycle()
}

func NewFileManager

func NewFileManager(dep dependency.Dep, u *ent.User) FileManager

type FileOperation

type FileOperation interface {
	// Get gets file object by given path
	Get(ctx context.Context, path *fs.URI, opts ...fs.Option) (fs.File, error)
	// List lists files under given path
	List(ctx context.Context, path *fs.URI, args *ListArgs) (fs.File, *fs.ListFileResult, error)
	// Create creates a file or directory
	Create(ctx context.Context, path *fs.URI, fileType types.FileType, opt ...fs.Option) (fs.File, error)
	// Rename renames a file or directory
	Rename(ctx context.Context, path *fs.URI, newName string) (fs.File, error)
	// Delete deletes a group of file or directory. UnlinkOnly indicates whether to delete file record in DB only.
	Delete(ctx context.Context, path []*fs.URI, opts ...fs.Option) error
	// Restore restores a group of files
	Restore(ctx context.Context, path ...*fs.URI) error
	// MoveOrCopy moves or copies a group of files
	MoveOrCopy(ctx context.Context, src []*fs.URI, dst *fs.URI, isCopy bool) error
	// Update puts file content. If given file does not exist, it will create a new one.
	Update(ctx context.Context, req *fs.UploadRequest, opts ...fs.Option) (fs.File, error)
	// Walk walks through given path
	Walk(ctx context.Context, path *fs.URI, depth int, f fs.WalkFunc, opts ...fs.Option) error
	// UpsertMedata update or insert metadata of given file
	PatchMedata(ctx context.Context, path []*fs.URI, data ...fs.MetadataPatch) error
	// CreateViewerSession creates a viewer session for given file
	CreateViewerSession(ctx context.Context, uri *fs.URI, version string, viewer *types.Viewer) (*ViewerSession, error)
	// TraverseFile traverses a file to its root file, return the file with linked root.
	TraverseFile(ctx context.Context, fileID int) (fs.File, error)
}

type FsManagement

type FsManagement interface {
	// SharedAddressTranslation translates shared symbolic address to real address. If path does not exist,
	// most recent existing parent directory will be returned.
	SharedAddressTranslation(ctx context.Context, path *fs.URI, opts ...fs.Option) (fs.File, *fs.URI, error)
	// Capacity gets capacity of current file system
	Capacity(ctx context.Context) (*fs.Capacity, error)
	// CheckIfCapacityExceeded checks if given user's capacity exceeded, and send notification email
	CheckIfCapacityExceeded(ctx context.Context) error
	// LocalDriver gets local driver for operating local files.
	LocalDriver(policy *ent.StoragePolicy) driver.Handler
	// CastStoragePolicyOnSlave check if given storage policy need to be casted to another.
	// It is used on slave node, when local policy need to cast to remote policy;
	// Remote policy with same node ID can be casted to local policy.
	CastStoragePolicyOnSlave(ctx context.Context, policy *ent.StoragePolicy) *ent.StoragePolicy
	// GetStorageDriver gets storage driver for given policy
	GetStorageDriver(ctx context.Context, policy *ent.StoragePolicy) (driver.Handler, error)
	// PatchView patches the view setting of a file
	PatchView(ctx context.Context, uri *fs.URI, view *types.ExplorerView) error
}

type GenerateThumbTask

type GenerateThumbTask struct {
	*queue.InMemoryTask
	// contains filtered or unexported fields
}

func (*GenerateThumbTask) Do

func (*GenerateThumbTask) OnError

func (m *GenerateThumbTask) OnError(err error, d time.Duration)

type GetEntityUrlArgs

type GetEntityUrlArgs struct {
	URI               *fs.URI
	PreferredEntityID string
}

GetEntityUrlArgs single args to get entity url

type ListArgs

type ListArgs struct {
	Page           int
	PageSize       int
	PageToken      string
	Order          string
	OrderDirection string
	// StreamResponseCallback is used for streamed list operation, e.g. searching files.
	// Whenever a new item is found, this callback will be called with the current item and the parent item.
	StreamResponseCallback func(fs.File, []fs.File)
}

type MediaMetaTask

type MediaMetaTask struct {
	*queue.DBTask
}

func NewMediaMetaTask

func NewMediaMetaTask(ctx context.Context, uri *fs.URI, entityID int, creator *ent.User) (*MediaMetaTask, error)

NewMediaMetaTask creates a new MediaMetaTask to

func (*MediaMetaTask) Do

func (m *MediaMetaTask) Do(ctx context.Context) (task.Status, error)

type MediaMetaTaskState

type MediaMetaTaskState struct {
	Uri      *fs.URI `json:"uri"`
	EntityID int     `json:"entity_id"`
}

type RecycleError

type RecycleError struct {
	ID    string `json:"id"`
	Error string `json:"error"`
}

type ShareManagement

type ShareManagement interface {
	// CreateShare creates a share link for given path
	CreateOrUpdateShare(ctx context.Context, path *fs.URI, args *CreateShareArgs) (*ent.Share, error)
}

type UploadManagement

type UploadManagement interface {
	// CreateUploadSession creates a upload session for given upload request
	CreateUploadSession(ctx context.Context, req *fs.UploadRequest, opts ...fs.Option) (*fs.UploadCredential, error)
	// ConfirmUploadSession confirms whether upload session is valid for upload.
	ConfirmUploadSession(ctx context.Context, session *fs.UploadSession, chunkIndex int) (fs.File, error)
	// Upload uploads file data to storage
	Upload(ctx context.Context, req *fs.UploadRequest, policy *ent.StoragePolicy) error
	// CompleteUpload completes upload session and returns file object
	CompleteUpload(ctx context.Context, session *fs.UploadSession) (fs.File, error)
	// CancelUploadSession cancels upload session
	CancelUploadSession(ctx context.Context, path *fs.URI, sessionID string) error
	// OnUploadFailed should be called when an unmanaged upload failed before complete.
	OnUploadFailed(ctx context.Context, session *fs.UploadSession)
	// Similar to CompleteUpload, but does not create actual uplaod session in storage.
	PrepareUpload(ctx context.Context, req *fs.UploadRequest, opts ...fs.Option) (*fs.UploadSession, error)
	// PreValidateUpload pre-validates an upload request.
	PreValidateUpload(ctx context.Context, dst *fs.URI, files ...fs.PreValidateFile) error
}

type UploadSentinelCheckTask

type UploadSentinelCheckTask struct {
	*queue.DBTask
}

Upload sentinel check task is used for compliant storage policy (COS, S3...), it will delete the marked entity. It is expected to be queued after upload session is created, and canceled after upload callback is completed. If this task is executed, it means the upload callback does not complete in time.

func (*UploadSentinelCheckTask) Do

type UploadSentinelCheckTaskState

type UploadSentinelCheckTaskState struct {
	Session *fs.UploadSession `json:"session"`
}

Upload sentinel check task is used for compliant storage policy (COS, S3...), it will delete the marked entity. It is expected to be queued after upload session is created, and canceled after upload callback is completed. If this task is executed, it means the upload callback does not complete in time.

type ViewerCtx

type ViewerCtx struct{}

type ViewerSession

type ViewerSession struct {
	ID          string  `json:"id"`
	AccessToken string  `json:"access_token"`
	Expires     int64   `json:"expires"`
	File        fs.File `json:"-"`
}

type ViewerSessionCache

type ViewerSessionCache struct {
	ID       string
	Uri      string
	UserID   int
	FileID   int
	ViewerID string
	Version  string
	Token    string
}

func ViewerSessionFromContext

func ViewerSessionFromContext(ctx context.Context) *ViewerSessionCache

type ViewerSessionCacheCtx

type ViewerSessionCacheCtx struct{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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