Documentation
¶
Overview ¶
Package file provides services for managing files, folders, and file operations in the Weblens system.
Index ¶
- Constants
- Variables
- func DeriveFileFromAction(ctx context_service.AppContext, action history.FileAction, core tower.Instance) (*file_model.WeblensFileImpl, error)
- func GetFileOwner(ctx context.Context, file *file_model.WeblensFileImpl) (*user_model.User, error)
- func IsBackupTowerRoot(path file_system.Filepath) bool
- func LoadFilesRecursively(ctx context_service.AppContext, root *file_model.WeblensFileImpl) error
- func MakeUniqueChildName(parent file_system.Filepath, childName string, childIsDir bool) (childPath file_system.Filepath, err error)
- func RemoveCacheFilesWithFilter(ctx context.Context, contentIDFilter []string) error
- func TranslateBackupPath(ctx context_service.AppContext, path file_system.Filepath, ...) (file_system.Filepath, error)
- type FolderCoverPair
- type ServiceImpl
- func (fs *ServiceImpl) AddFile(ctx context.Context, files ...*file_model.WeblensFileImpl) (err error)
- func (fs *ServiceImpl) AddTask(f *file_model.WeblensFileImpl, t *task_model.Task) error
- func (fs *ServiceImpl) CreateFile(ctx context.Context, parent *file_model.WeblensFileImpl, filename string, ...) (*file_model.WeblensFileImpl, error)
- func (fs *ServiceImpl) CreateFolder(ctx context.Context, parent *file_model.WeblensFileImpl, folderName string) (*file_model.WeblensFileImpl, error)
- func (fs *ServiceImpl) CreateUserHome(ctx context.Context, user *user_model.User) error
- func (fs *ServiceImpl) DeleteCacheFile(f *file_model.WeblensFileImpl) error
- func (fs *ServiceImpl) DeleteFiles(ctx context.Context, files ...*file_model.WeblensFileImpl) error
- func (fs *ServiceImpl) DeleteZips(ctx context.Context) error
- func (fs *ServiceImpl) GetChildren(ctx context.Context, folder *file_model.WeblensFileImpl) ([]*file_model.WeblensFileImpl, error)
- func (fs *ServiceImpl) GetFileByContentID(ctx context.Context, contentID string) (*file_model.WeblensFileImpl, error)
- func (fs *ServiceImpl) GetFileByFilepath(ctx context.Context, filepath file_system.Filepath, dontLoadNew ...bool) (*file_model.WeblensFileImpl, error)
- func (fs *ServiceImpl) GetFileByID(ctx context.Context, id string) (*file_model.WeblensFileImpl, error)
- func (fs *ServiceImpl) GetMediaCacheByFilename(_ context.Context, thumbFileName string) (*file_model.WeblensFileImpl, error)
- func (fs *ServiceImpl) GetTasks(f *file_model.WeblensFileImpl) []*task_model.Task
- func (fs *ServiceImpl) GetZip(ctx context.Context, id string) (*file_model.WeblensFileImpl, error)
- func (fs *ServiceImpl) InitBackupDirectory(ctx context.Context, tower tower_model.Instance) (*file_model.WeblensFileImpl, error)
- func (fs *ServiceImpl) MoveFiles(ctx context.Context, files []*file_model.WeblensFileImpl, ...) error
- func (fs *ServiceImpl) NewBackupRestoreFile(ctx context.Context, contentID, remoteTowerID string) (*file_model.WeblensFileImpl, error)
- func (fs *ServiceImpl) NewCacheFile(mediaID string, quality string, pageNum int) (*file_model.WeblensFileImpl, error)
- func (fs *ServiceImpl) NewZip(ctx context.Context, zipName string, owner *user_model.User) (*file_model.WeblensFileImpl, error)
- func (fs *ServiceImpl) RecursiveEnsureChildrenLoaded(ctx context.Context, folder *file_model.WeblensFileImpl) error
- func (fs *ServiceImpl) RemoveTask(f *file_model.WeblensFileImpl, t *task_model.Task) error
- func (fs *ServiceImpl) RenameFile(ctx context.Context, file *file_model.WeblensFileImpl, newName string) error
- func (fs *ServiceImpl) ResizeUp(ctx context.Context, f *file_model.WeblensFileImpl) error
- func (fs *ServiceImpl) RestoreFiles(ctx context.Context, ids []string, newParent *file_model.WeblensFileImpl, ...) error
- func (fs *ServiceImpl) RestoreHistory(ctx context.Context, actions []*history.FileAction) error
- func (fs *ServiceImpl) ReturnFilesFromTrash(_ context.Context, trashFiles []*file_model.WeblensFileImpl) error
- func (fs *ServiceImpl) Size(_ string) int64
Constants ¶
const SkipJournalKey = "skipJournal"
SkipJournalKey can be set in the context to skip journaling for file operations.
Variables ¶
var ErrChildrenAlreadyLoaded = wlerrors.Errorf("children already loaded")
ErrChildrenAlreadyLoaded indicates that a directory's children have already been loaded.
Functions ¶
func DeriveFileFromAction ¶
func DeriveFileFromAction(ctx context_service.AppContext, action history.FileAction, core tower.Instance) (*file_model.WeblensFileImpl, error)
DeriveFileFromAction creates a WeblensFileImpl from a FileAction, translating the path to the backup location. Useful for deriving the correct file object representation when restoring files from backup.
func GetFileOwner ¶
func GetFileOwner(ctx context.Context, file *file_model.WeblensFileImpl) (*user_model.User, error)
GetFileOwner retrieves the user who owns the specified file.
func IsBackupTowerRoot ¶
func IsBackupTowerRoot(path file_system.Filepath) bool
IsBackupTowerRoot checks if the given path is a backup tower root directory. Backup paths are in the form of BACKUP:<tower_id>/<path> So we check if the root name is BACKUP and the parent of the path is the root (i.e. BACKUP:)
func LoadFilesRecursively ¶
func LoadFilesRecursively(ctx context_service.AppContext, root *file_model.WeblensFileImpl) error
LoadFilesRecursively loads a directory and all its subdirectories into the file service.
func MakeUniqueChildName ¶
func MakeUniqueChildName(parent file_system.Filepath, childName string, childIsDir bool) (childPath file_system.Filepath, err error)
MakeUniqueChildName generates a unique filename within the parent directory by appending a number suffix if necessary.
func RemoveCacheFilesWithFilter ¶
RemoveCacheFilesWithFilter removes cache files that match the provided content ID filter. If the filter is empty, no files will be removed. However, if you want to remove all cache files, pass nil as the filter.
func TranslateBackupPath ¶
func TranslateBackupPath(ctx context_service.AppContext, path file_system.Filepath, core tower_model.Instance) (file_system.Filepath, error)
TranslateBackupPath translates a user path to its corresponding backup path for a given tower.
Types ¶
type FolderCoverPair ¶
FolderCoverPair represents a mapping between a folder and its cover image.
type ServiceImpl ¶
type ServiceImpl struct {
// contains filtered or unexported fields
}
ServiceImpl implements the FileService interface for managing files and directories.
func NewFileService ¶
func NewFileService( _ context.Context, ) (*ServiceImpl, error)
NewFileService creates and initializes a new FileService instance.
func (*ServiceImpl) AddFile ¶
func (fs *ServiceImpl) AddFile(ctx context.Context, files ...*file_model.WeblensFileImpl) (err error)
AddFile adds one or more files to the file service and their parent directories.
func (*ServiceImpl) AddTask ¶
func (fs *ServiceImpl) AddTask(f *file_model.WeblensFileImpl, t *task_model.Task) error
AddTask associates a task with a file for tracking purposes.
func (*ServiceImpl) CreateFile ¶
func (fs *ServiceImpl) CreateFile(ctx context.Context, parent *file_model.WeblensFileImpl, filename string, data ...[]byte) ( *file_model.WeblensFileImpl, error, )
CreateFile creates a new file in the specified parent directory with optional initial data.
func (*ServiceImpl) CreateFolder ¶
func (fs *ServiceImpl) CreateFolder(ctx context.Context, parent *file_model.WeblensFileImpl, folderName string) (*file_model.WeblensFileImpl, error)
CreateFolder creates a new folder in the specified parent directory.
func (*ServiceImpl) CreateUserHome ¶
func (fs *ServiceImpl) CreateUserHome(ctx context.Context, user *user_model.User) error
CreateUserHome initializes a home directory and trash for a new user.
func (*ServiceImpl) DeleteCacheFile ¶
func (fs *ServiceImpl) DeleteCacheFile(f *file_model.WeblensFileImpl) error
DeleteCacheFile removes a cache file from the filesystem.
func (*ServiceImpl) DeleteFiles ¶
func (fs *ServiceImpl) DeleteFiles(ctx context.Context, files ...*file_model.WeblensFileImpl) error
DeleteFiles removes files being pointed to from the tree and moves them to the restore tree.
func (*ServiceImpl) DeleteZips ¶
func (fs *ServiceImpl) DeleteZips(ctx context.Context) error
DeleteZips permanently deletes zip files from the takeout cache
func (*ServiceImpl) GetChildren ¶
func (fs *ServiceImpl) GetChildren(ctx context.Context, folder *file_model.WeblensFileImpl) ([]*file_model.WeblensFileImpl, error)
GetChildren retrieves all child files of a directory, loading them if necessary.
func (*ServiceImpl) GetFileByContentID ¶
func (fs *ServiceImpl) GetFileByContentID(ctx context.Context, contentID string) (*file_model.WeblensFileImpl, error)
GetFileByContentID retrieves a file by its content identifier.
func (*ServiceImpl) GetFileByFilepath ¶
func (fs *ServiceImpl) GetFileByFilepath(ctx context.Context, filepath file_system.Filepath, dontLoadNew ...bool) (*file_model.WeblensFileImpl, error)
GetFileByFilepath retrieves a file by its portable filepath, optionally loading directories as needed.
func (*ServiceImpl) GetFileByID ¶
func (fs *ServiceImpl) GetFileByID(ctx context.Context, id string) (*file_model.WeblensFileImpl, error)
GetFileByID retrieves a file by its unique identifier.
func (*ServiceImpl) GetMediaCacheByFilename ¶
func (fs *ServiceImpl) GetMediaCacheByFilename(_ context.Context, thumbFileName string) (*file_model.WeblensFileImpl, error)
GetMediaCacheByFilename retrieves a cached media file by its thumbnail filename.
func (*ServiceImpl) GetTasks ¶
func (fs *ServiceImpl) GetTasks(f *file_model.WeblensFileImpl) []*task_model.Task
GetTasks returns all tasks associated with a file.
func (*ServiceImpl) GetZip ¶
func (fs *ServiceImpl) GetZip(ctx context.Context, id string) (*file_model.WeblensFileImpl, error)
GetZip retrieves a zip file by its identifier.
func (*ServiceImpl) InitBackupDirectory ¶
func (fs *ServiceImpl) InitBackupDirectory(ctx context.Context, tower tower_model.Instance) (*file_model.WeblensFileImpl, error)
InitBackupDirectory initializes the backup directory for a tower instance.
func (*ServiceImpl) MoveFiles ¶
func (fs *ServiceImpl) MoveFiles(ctx context.Context, files []*file_model.WeblensFileImpl, destFolder *file_model.WeblensFileImpl) error
MoveFiles moves one or more files to a destination folder.
func (*ServiceImpl) NewBackupRestoreFile ¶
func (fs *ServiceImpl) NewBackupRestoreFile(ctx context.Context, contentID, remoteTowerID string) (*file_model.WeblensFileImpl, error)
NewBackupRestoreFile creates a new restore file in the backup restore tree for a specific content and tower.
func (*ServiceImpl) NewCacheFile ¶
func (fs *ServiceImpl) NewCacheFile(mediaID string, quality string, pageNum int) (*file_model.WeblensFileImpl, error)
NewCacheFile creates a new cache file for the specified media with the given quality and page number.
func (*ServiceImpl) NewZip ¶
func (fs *ServiceImpl) NewZip(ctx context.Context, zipName string, owner *user_model.User) (*file_model.WeblensFileImpl, error)
NewZip creates a new zip file for archiving purposes.
func (*ServiceImpl) RecursiveEnsureChildrenLoaded ¶
func (fs *ServiceImpl) RecursiveEnsureChildrenLoaded(ctx context.Context, folder *file_model.WeblensFileImpl) error
RecursiveEnsureChildrenLoaded ensures all children are loaded for a directory and all its subdirectories.
func (*ServiceImpl) RemoveTask ¶
func (fs *ServiceImpl) RemoveTask(f *file_model.WeblensFileImpl, t *task_model.Task) error
RemoveTask removes a task from the file's task list.
func (*ServiceImpl) RenameFile ¶
func (fs *ServiceImpl) RenameFile(ctx context.Context, file *file_model.WeblensFileImpl, newName string) error
RenameFile changes the name of a file and updates its path in the file service.
func (*ServiceImpl) ResizeUp ¶
func (fs *ServiceImpl) ResizeUp(ctx context.Context, f *file_model.WeblensFileImpl) error
ResizeUp updates the size of parent directories when a file changes.
func (*ServiceImpl) RestoreFiles ¶
func (fs *ServiceImpl) RestoreFiles(ctx context.Context, ids []string, newParent *file_model.WeblensFileImpl, restoreTime time.Time) error
RestoreFiles restores files to a previous state from their history at the specified time. It reconstructs past file states and hard-links content from the RESTORE tree back into the USERS tree.
func (*ServiceImpl) RestoreHistory ¶
func (fs *ServiceImpl) RestoreHistory(ctx context.Context, actions []*history.FileAction) error
RestoreHistory replays a series of file actions to restore file history.
func (*ServiceImpl) ReturnFilesFromTrash ¶
func (fs *ServiceImpl) ReturnFilesFromTrash(_ context.Context, trashFiles []*file_model.WeblensFileImpl) error
ReturnFilesFromTrash moves files from the trash back to their previous locations.
func (*ServiceImpl) Size ¶
func (fs *ServiceImpl) Size(_ string) int64
Size returns the total size of files in the specified tree.