Documentation
¶
Index ¶
- Constants
- Variables
- func CronCollectTrashBin(ctx context.Context)
- func NewEntityRecycleRoutineTask(ctx context.Context) (queue.Task, error)
- func NewEntityRecycleRoutineTaskFromModel(task *ent.Task) queue.Task
- func NewExplicitEntityRecycleTaskFromModel(task *ent.Task) queue.Task
- func NewFullTextChangeOwnerTaskFromModel(t *ent.Task) queue.Task
- func NewFullTextCopyTaskFromModel(t *ent.Task) queue.Task
- func NewFullTextDeleteTaskFromModel(t *ent.Task) queue.Task
- func NewFullTextIndexTaskFromModel(t *ent.Task) queue.Task
- func NewMediaMetaTaskFromModel(task *ent.Task) queue.Task
- func NewUploadSentinelCheckTaskFromModel(task *ent.Task) queue.Task
- func ShouldExtractText(extractor searcher.TextExtractor, fileName string, size int64) bool
- func ViewerFromContext(ctx context.Context) *types.Viewer
- type ArchivedFile
- type Archiver
- type CreateShareArgs
- type DirectLink
- type EntityManagement
- type EntityRecycleRoutineTask
- type EntityRecycleRoutineTaskState
- type EntityUrl
- type EntityUrlCache
- type ExplicitEntityRecycleTask
- type ExplicitEntityRecycleTaskState
- type FileManager
- type FileOperation
- type FsManagement
- type FullTextChangeOwnerTask
- type FullTextChangeOwnerTaskState
- type FullTextCopyTask
- type FullTextCopyTaskState
- type FullTextDeleteTask
- type FullTextDeleteTaskState
- type FullTextIndexTask
- type FullTextIndexTaskState
- type FullTextSearchResult
- type FullTextSearchResults
- type GenerateThumbTask
- type GetEntityUrlArgs
- type ListArgs
- type MediaMetaTask
- type MediaMetaTaskState
- type RecycleError
- type ShareManagement
- type UploadManagement
- type UploadSentinelCheckTask
- type UploadSentinelCheckTaskState
- type ViewerCtx
- type ViewerSession
- type ViewerSessionCache
- type ViewerSessionCacheCtx
Constants ¶
const ( UploadSessionCachePrefix = "callback_" // Ctx key for upload session UploadSessionCtx = "uploadSession" )
const ( EntityUrlCacheKeyPrefix = "entity_url_" DownloadSentinelCachePrefix = "download_sentinel_" )
const (
ArchiveListCacheTTL = 3600 // 1 hour
)
const (
MinimumTrashCollectBatch = 1000
)
const (
ViewerSessionCachePrefix = "viewer_session_"
)
Variables ¶
var (
ErrUnknownPolicyType = serializer.NewError(serializer.CodeInternalSetting, "Unknown policy type", nil)
)
var ZipEncodings = map[string]encoding.Encoding{ "ibm866": charmap.CodePage866, "iso8859_2": charmap.ISO8859_2, "iso8859_3": charmap.ISO8859_3, "iso8859_4": charmap.ISO8859_4, "iso8859_5": charmap.ISO8859_5, "iso8859_6": charmap.ISO8859_6, "iso8859_7": charmap.ISO8859_7, "iso8859_8": charmap.ISO8859_8, "iso8859_8I": charmap.ISO8859_8I, "iso8859_10": charmap.ISO8859_10, "iso8859_13": charmap.ISO8859_13, "iso8859_14": charmap.ISO8859_14, "iso8859_15": charmap.ISO8859_15, "iso8859_16": charmap.ISO8859_16, "koi8r": charmap.KOI8R, "koi8u": charmap.KOI8U, "macintosh": charmap.Macintosh, "windows874": charmap.Windows874, "windows1250": charmap.Windows1250, "windows1251": charmap.Windows1251, "windows1252": charmap.Windows1252, "windows1253": charmap.Windows1253, "windows1254": charmap.Windows1254, "windows1255": charmap.Windows1255, "windows1256": charmap.Windows1256, "windows1257": charmap.Windows1257, "windows1258": charmap.Windows1258, "macintoshcyrillic": charmap.MacintoshCyrillic, "gbk": simplifiedchinese.GBK, "gb18030": simplifiedchinese.GB18030, "big5": traditionalchinese.Big5, "eucjp": japanese.EUCJP, "iso2022jp": japanese.ISO2022JP, "shiftjis": japanese.ShiftJIS, "euckr": korean.EUCKR, "utf16be": unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM), "utf16le": unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM), }
Functions ¶
func CronCollectTrashBin ¶
CronCollectTrashBin walks through all files in trash bin and delete them if they are expired.
func ShouldExtractText ¶
func ShouldExtractText(extractor searcher.TextExtractor, fileName string, size int64) bool
ShouldExtractText checks if a file is eligible for text extraction based on the extractor's supported extensions and max file size. This is exported for use by the rebuild index workflow.
Types ¶
type ArchivedFile ¶
type Archiver ¶
type Archiver interface {
// CreateArchive creates an archive
CreateArchive(ctx context.Context, uris []*fs.URI, writer io.Writer, opts ...fs.Option) (int, error)
// ListArchiveFiles lists files in an archive
ListArchiveFiles(ctx context.Context, uri *fs.URI, entity, zipEncoding string) ([]ArchivedFile, error)
}
type DirectLink ¶
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 EntityRecycleRoutineTaskState ¶
type EntityRecycleRoutineTaskState struct {
Errors [][]RecycleError `json:"errors,omitempty"`
}
type EntityUrlCache ¶
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)
// SearchFullText searches full text for given query and offset
SearchFullText(ctx context.Context, query string, offset int) (*FullTextSearchResults, error)
}
type FsManagement ¶
type FsManagement interface {
// 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 FullTextChangeOwnerTask ¶
type FullTextCopyTask ¶
func NewFullTextCopyTask ¶
type FullTextCopyTaskState ¶
type FullTextDeleteTask ¶
func NewFullTextDeleteTask ¶
type FullTextDeleteTaskState ¶
type FullTextDeleteTaskState struct {
FileIDs []int `json:"file_ids"`
}
type FullTextIndexTask ¶
func NewFullTextIndexTask ¶
type FullTextIndexTaskState ¶
type FullTextSearchResult ¶
type FullTextSearchResults ¶
type FullTextSearchResults struct {
Hits []FullTextSearchResult
Total int64
}
type GenerateThumbTask ¶
type GenerateThumbTask struct {
*queue.InMemoryTask
// contains filtered or unexported fields
}
type GetEntityUrlArgs ¶
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 MediaMetaTaskState ¶
type RecycleError ¶
type ShareManagement ¶
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, session *fs.UploadSession) 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 ¶
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 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 ViewerSession ¶
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{}