Documentation
¶
Overview ¶
Package op provides operations for OpenList's core functionality
Package op provides operations for OpenList's core functionality ¶
Package op provides operations for OpenList's core functionality ¶
Package op provides operations for OpenList's core functionality ¶
Package op provides operations for OpenList's core functionality
Index ¶
- Constants
- Variables
- func ArchiveDecompress(ctx context.Context, storage driver.Driver, srcPath, dstDirPath string, ...) error
- func ArchiveGet(ctx context.Context, storage driver.Driver, path string, ...) (model.Obj, model.Obj, error)
- func CallStorageHooks(typ string, storage driver.Driver)
- func Cancel2FAByID(id uint) error
- func Cancel2FAByUser(user *model.User) error
- func ClearCache(storage driver.Driver, path string)
- func Copy(ctx context.Context, storage driver.Driver, srcPath, dstDirPath string, ...) error
- func CreateMeta(meta *model.Meta) error
- func CreateSSHPublicKey(key *model.SSHPublicKey) (error, bool)
- func CreateStorage(ctx context.Context, storage model.Storage) (uint, error)
- func CreateUser(user *model.User) error
- func DelUserCache(username string) error
- func DeleteCache(storage driver.Driver, path string)
- func DeleteMetaByID(id uint) error
- func DeleteSSHPublicKeyByID(keyID uint) error
- func DeleteSettingItemByKey(key string) error
- func DeleteStorageByID(ctx context.Context, id uint) error
- func DeleteUserByID(id uint) error
- func DisableStorage(ctx context.Context, id uint) error
- func DriverExtract(ctx context.Context, storage driver.Driver, path string, ...) (*model.Link, model.Obj, error)
- func EnableStorage(ctx context.Context, id uint) error
- func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, error)
- func GetAdmin() (*model.User, error)
- func GetAllStorages() []driver.Driver
- func GetArchiveMeta(ctx context.Context, storage driver.Driver, path string, ...) (*model.ArchiveMetaProvider, error)
- func GetArchiveToolAndStream(ctx context.Context, storage driver.Driver, path string, args model.LinkArgs) (model.Obj, tool2.Tool, []*stream.SeekableStream, error)
- func GetBalancedStorage(path string) driver.Driver
- func GetDriverInfoMap() map[string]driver.Info
- func GetDriverNames() []string
- func GetGuest() (*model.User, error)
- func GetMetaByID(id uint) (*model.Meta, error)
- func GetMetaByPath(path string) (*model.Meta, error)
- func GetMetas(pageIndex, pageSize int) (metas []model.Meta, count int64, err error)
- func GetNearestMeta(path string) (*model.Meta, error)
- func GetPublicSettingItems() ([]model.SettingItem, error)
- func GetPublicSettingsMap() map[string]string
- func GetSSHPublicKeyByIDAndUserID(id uint, userID uint) (*model.SSHPublicKey, error)
- func GetSSHPublicKeyByUserID(userID uint, pageIndex, pageSize int) (keys []model.SSHPublicKey, count int64, err error)
- func GetSettingItemByKey(key string) (*model.SettingItem, error)
- func GetSettingItemInKeys(keys []string) ([]model.SettingItem, error)
- func GetSettingItems() ([]model.SettingItem, error)
- func GetSettingItemsByGroup(group int) ([]model.SettingItem, error)
- func GetSettingItemsInGroups(groups []int) ([]model.SettingItem, error)
- func GetSettingsMap() map[string]string
- func GetStorageAndActualPath(rawPath string) (storage driver.Driver, actualPath string, err error)
- func GetStorageByMountPath(mountPath string) (driver.Driver, error)
- func GetStorageStats() map[string]int
- func GetStorageVirtualFilesByPath(prefix string) []model.Obj
- func GetUnwrap(ctx context.Context, storage driver.Driver, path string) (model.Obj, error)
- func GetUserByID(id uint) (*model.User, error)
- func GetUserByName(username string) (*model.User, error)
- func GetUserByRole(role int) (*model.User, error)
- func GetUsers(pageIndex, pageSize int) (users []model.User, count int64, err error)
- func HandleObjsUpdateHook(parent string, objs []model.Obj)
- func HandleSettingItemHook(item *model.SettingItem) (hasHook bool, err error)
- func HasStorage(mountPath string) bool
- func InternalExtract(ctx context.Context, storage driver.Driver, path string, ...) (io.ReadCloser, int64, error)
- func IsUseOnlineAPI(storageDriver driver.Driver) bool
- func Key(storage driver.Driver, path string) string
- func Link(ctx context.Context, storage driver.Driver, path string, args model.LinkArgs) (*model.Link, model.Obj, error)
- func List(ctx context.Context, storage driver.Driver, path string, args model.ListArgs) ([]model.Obj, error)
- func ListArchive(ctx context.Context, storage driver.Driver, path string, ...) ([]model.Obj, error)
- func LoadStorage(ctx context.Context, storage model.Storage) error
- func MakeDir(ctx context.Context, storage driver.Driver, path string, lazyCache ...bool) error
- func Move(ctx context.Context, storage driver.Driver, srcPath, dstDirPath string, ...) error
- func MustSaveDriverStorage(driver driver.Driver)
- func Other(ctx context.Context, storage driver.Driver, args model.FsOtherArgs) (any, error)
- func Put(ctx context.Context, storage driver.Driver, dstDirPath string, ...) error
- func PutURL(ctx context.Context, storage driver.Driver, dstDirPath, dstName, url string, ...) error
- func RegisterDriver(constructor DriverConstructor)
- func RegisterObjsUpdateHook(hook ObjsUpdateHook)
- func RegisterSettingChangingCallback(f func())
- func RegisterSettingItemHook(key string, hook SettingItemHook)
- func RegisterStorageHook(hook StorageHook)
- func Remove(ctx context.Context, storage driver.Driver, path string) error
- func Rename(ctx context.Context, storage driver.Driver, srcPath, dstName string, ...) error
- func ResetStorageCaches()
- func SaveSettingItem(item *model.SettingItem) error
- func SaveSettingItems(items []model.SettingItem) error
- func SettingCacheUpdate()
- func URLTreeSplitPathAndURL(path string) (dirPath string, urlPart string)
- func UpdateMeta(meta *model.Meta) error
- func UpdateSSHPublicKey(key *model.SSHPublicKey) error
- func UpdateStorage(ctx context.Context, storage model.Storage) error
- func UpdateUser(user *model.User) error
- type DriverConstructor
- type MigrationValueItem
- type ObjsUpdateHook
- type SettingItemHook
- type StorageHook
Constants ¶
const ( // WORK represents an active storage status WORK = "work" // DISABLED represents a disabled storage status DISABLED = "disabled" // RootName is the identifier for the root storage/directory RootName = "root" )
Storage status constants
const ( STATUS_WORK = "工作中" STATUS_DISABLED = "已禁用" )
存储状态常量
Variables ¶
var ( ErrStorageNotFound = errors.New("存储不存在") ErrStorageInitFailed = errors.New("存储初始化失败") ErrStorageDisabled = errors.New("存储已禁用") ErrDriverNotSupported = errors.New("不支持的驱动类型") ErrInvalidMountPath = errors.New("无效的挂载路径") ErrDriverTypeLocked = errors.New("驱动类型不能更改") )
错误类型定义
var MigrationSettingItems map[string]MigrationValueItem
Functions ¶
func ArchiveDecompress ¶
func ArchiveDecompress(ctx context.Context, storage driver.Driver, srcPath, dstDirPath string, args model.ArchiveDecompressArgs, lazyCache ...bool) error
ArchiveDecompress decompresses an archive file to a destination directory
func ArchiveGet ¶
func ArchiveGet(ctx context.Context, storage driver.Driver, path string, args model.ArchiveListArgs) (model.Obj, model.Obj, error)
ArchiveGet gets a specific file or folder from within an archive
func CallStorageHooks ¶
CallStorageHooks calls all registered storage hooks
func Cancel2FAByID ¶
Cancel2FAByID disables two-factor authentication for a user by ID
func Cancel2FAByUser ¶
Cancel2FAByUser disables two-factor authentication for a user
func ClearCache ¶
func Copy ¶
func Copy(ctx context.Context, storage driver.Driver, srcPath, dstDirPath string, lazyCache ...bool) error
Copy Just copy file[s] in a storage
func CreateMeta ¶
CreateMeta creates new metadata and invalidates the cache for its path
func CreateSSHPublicKey ¶
func CreateSSHPublicKey(key *model.SSHPublicKey) (error, bool)
CreateSSHPublicKey creates a new SSH public key for a user Returns an error and a boolean indicating if the error is due to validation (true) or system issues (false)
func CreateStorage ¶
CreateStorage 将存储配置保存到数据库并实例化驱动 返回存储ID和可能发生的错误
func DelUserCache ¶
DelUserCache removes a user from cache Also clears special user instances if needed
func DeleteCache ¶ added in v4.2.7
func DeleteMetaByID ¶
DeleteMetaByID deletes metadata by its ID and removes it from cache
func DeleteSSHPublicKeyByID ¶
DeleteSSHPublicKeyByID deletes an SSH public key by its ID
func DeleteSettingItemByKey ¶
DeleteSettingItemByKey deletes a setting item by its key Only deprecated items can be deleted
func DeleteStorageByID ¶
DeleteStorageByID 完全删除存储
func DeleteUserByID ¶
DeleteUserByID deletes a user by ID Admin and guest users cannot be deleted
func DriverExtract ¶
func DriverExtract(ctx context.Context, storage driver.Driver, path string, args model.ArchiveInnerArgs) (*model.Link, model.Obj, error)
DriverExtract extracts a file from an archive using the driver's capabilities
func GetAllStorages ¶
GetAllStorages 返回所有活动的存储驱动 返回的切片是按挂载路径排序的
func GetArchiveMeta ¶
func GetArchiveMeta(ctx context.Context, storage driver.Driver, path string, args model.ArchiveMetaArgs) (*model.ArchiveMetaProvider, error)
GetArchiveMeta retrieves archive metadata for a given file Uses cache when available unless refresh is requested
func GetArchiveToolAndStream ¶
func GetArchiveToolAndStream(ctx context.Context, storage driver.Driver, path string, args model.LinkArgs) (model.Obj, tool2.Tool, []*stream.SeekableStream, error)
GetArchiveToolAndStream retrieves the appropriate archive tool and streams for a file Returns the file object, tool, streams, and any error
func GetBalancedStorage ¶
GetBalancedStorage 返回路径的存储,如果存在多个则使用轮询
func GetDriverInfoMap ¶
GetDriverInfoMap returns the map of driver information for all registered drivers
func GetDriverNames ¶
func GetDriverNames() []string
GetDriverNames returns a list of all registered driver names
func GetMetaByID ¶
GetMetaByID retrieves metadata by its ID directly from the database
func GetMetaByPath ¶
GetMetaByPath returns metadata for the exact path specified It will clean the path before searching
func GetNearestMeta ¶
GetNearestMeta returns the nearest metadata for a given path It will traverse up the directory tree until it finds metadata or reaches the root
func GetPublicSettingItems ¶
func GetPublicSettingItems() ([]model.SettingItem, error)
GetPublicSettingItems retrieves all public setting items, using cache when available
func GetPublicSettingsMap ¶
GetPublicSettingsMap returns a map of all public settings with key-value pairs
func GetSSHPublicKeyByIDAndUserID ¶
func GetSSHPublicKeyByIDAndUserID(id uint, userID uint) (*model.SSHPublicKey, error)
GetSSHPublicKeyByIDAndUserID retrieves a specific SSH public key for a user Ensures the key belongs to the specified user
func GetSSHPublicKeyByUserID ¶
func GetSSHPublicKeyByUserID(userID uint, pageIndex, pageSize int) (keys []model.SSHPublicKey, count int64, err error)
GetSSHPublicKeyByUserID retrieves a paginated list of SSH public keys for a user
func GetSettingItemByKey ¶
func GetSettingItemByKey(key string) (*model.SettingItem, error)
GetSettingItemByKey retrieves a setting item by its key, using cache when available
func GetSettingItemInKeys ¶
func GetSettingItemInKeys(keys []string) ([]model.SettingItem, error)
GetSettingItemInKeys retrieves multiple setting items by their keys
func GetSettingItems ¶
func GetSettingItems() ([]model.SettingItem, error)
GetSettingItems retrieves all setting items, using cache when available
func GetSettingItemsByGroup ¶
func GetSettingItemsByGroup(group int) ([]model.SettingItem, error)
GetSettingItemsByGroup retrieves all setting items in a specific group
func GetSettingItemsInGroups ¶
func GetSettingItemsInGroups(groups []int) ([]model.SettingItem, error)
GetSettingItemsInGroups retrieves all setting items in multiple groups
func GetSettingsMap ¶
GetSettingsMap returns a map of all settings with key-value pairs
func GetStorageAndActualPath ¶
GetStorageAndActualPath returns the corresponding storage and actual path For path: removes the mount path prefix and joins the actual root folder if exists Returns:
- storage: the driver instance for the storage
- actualPath: the path within the storage
- err: error if any occurred
func GetStorageByMountPath ¶
GetStorageByMountPath 通过挂载路径获取存储驱动
func GetStorageStats ¶ added in v4.2.6
GetStorageStats 返回存储统计信息 包括活动存储数量、禁用存储数量和总存储数量
func GetStorageVirtualFilesByPath ¶
GetStorageVirtualFilesByPath 返回路径下存储生成的虚拟文件/文件夹 例如,给定存储位置:/a/b, /a/c, /a/d/e, /a/b.balance1, /av GetStorageVirtualFilesByPath(/a) => 虚拟文件夹 b, c, d
func GetUserByID ¶
GetUserByID retrieves a user by ID
func GetUserByName ¶
GetUserByName retrieves a user by username, using cache when available
func GetUserByRole ¶
GetUserByRole retrieves a user with a specific role
func HandleObjsUpdateHook ¶
HandleObjsUpdateHook calls all registered object update hooks
func HandleSettingItemHook ¶
func HandleSettingItemHook(item *model.SettingItem) (hasHook bool, err error)
HandleSettingItemHook processes a setting item with its registered hook Returns:
- hasHook: true if a hook was found and executed for the item
- err: any error that occurred during hook execution
func InternalExtract ¶
func InternalExtract(ctx context.Context, storage driver.Driver, path string, args model.ArchiveInnerArgs) (io.ReadCloser, int64, error)
InternalExtract extracts a file from an archive using archive tools
func IsUseOnlineAPI ¶ added in v4.3.1
func Link ¶
func Link(ctx context.Context, storage driver.Driver, path string, args model.LinkArgs) (*model.Link, model.Obj, error)
Link get link, if is an url. should have an expiry time
func List ¶
func List(ctx context.Context, storage driver.Driver, path string, args model.ListArgs) ([]model.Obj, error)
List files in storage, not contains virtual file
func ListArchive ¶
func ListArchive(ctx context.Context, storage driver.Driver, path string, args model.ArchiveListArgs) ([]model.Obj, error)
ListArchive lists the contents of an archive file Uses cache when available unless refresh is requested
func LoadStorage ¶
LoadStorage 从数据库加载现有存储到内存
func MustSaveDriverStorage ¶
MustSaveDriverStorage 保存驱动存储配置 并记录任何错误而不返回它们
func RegisterDriver ¶
func RegisterDriver(constructor DriverConstructor)
RegisterDriver registers a new storage driver with the system It extracts the driver's configuration and additional information
func RegisterObjsUpdateHook ¶
func RegisterObjsUpdateHook(hook ObjsUpdateHook)
RegisterObjsUpdateHook registers a new hook to be called when objects are updated
func RegisterSettingChangingCallback ¶
func RegisterSettingChangingCallback(f func())
RegisterSettingChangingCallback registers a function to be called when settings are updated
func RegisterSettingItemHook ¶
func RegisterSettingItemHook(key string, hook SettingItemHook)
RegisterSettingItemHook registers a hook for a specific setting key
func RegisterStorageHook ¶
func RegisterStorageHook(hook StorageHook)
RegisterStorageHook registers a new hook for storage operations
func ResetStorageCaches ¶ added in v4.2.6
func ResetStorageCaches()
ResetStorageCaches 重置所有存储相关的缓存 这在配置更改或需要强制刷新缓存时很有用
func SaveSettingItem ¶
func SaveSettingItem(item *model.SettingItem) error
SaveSettingItem saves a single setting item, handling hooks as needed
func SaveSettingItems ¶
func SaveSettingItems(items []model.SettingItem) error
SaveSettingItems saves multiple setting items, handling hooks as needed
func SettingCacheUpdate ¶
func SettingCacheUpdate()
SettingCacheUpdate clears all setting caches and executes registered change callbacks
func URLTreeSplitPathAndURL ¶
URLTreeSplitPathAndURL splits a path into directory path and URL components for URL-Tree driver Handles different URL-Tree formats: 1. /url_tree_driver/file_name[:size[:time]]:https://example.com/file 2. /url_tree_driver/https://example.com/file Returns:
- dirPath: the directory path component
- urlPart: the URL or file component
func UpdateMeta ¶
UpdateMeta updates metadata and refreshes the cache
func UpdateSSHPublicKey ¶
func UpdateSSHPublicKey(key *model.SSHPublicKey) error
UpdateSSHPublicKey updates an existing SSH public key
func UpdateStorage ¶
UpdateStorage 更新现有存储配置 包括使用新配置重新初始化驱动
Types ¶
type DriverConstructor ¶
DriverConstructor is a function type that creates a new driver instance
func GetDriver ¶
func GetDriver(name string) (DriverConstructor, error)
GetDriver returns the constructor for a driver by name Returns an error if the driver is not found
type MigrationValueItem ¶ added in v4.2.3
type MigrationValueItem struct {
MigrationValue, Value string
}
type ObjsUpdateHook ¶
ObjsUpdateHook is a function type for hooks that process objects after they are updated
type SettingItemHook ¶
type SettingItemHook func(item *model.SettingItem) error
SettingItemHook is a function type for hooks that process setting items
type StorageHook ¶
StorageHook is a function type for hooks that process storage operations