op

package
v4.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: AGPL-3.0 Imports: 32 Imported by: 0

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

View Source
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

View Source
const (
	STATUS_WORK     = "工作中"
	STATUS_DISABLED = "已禁用"
)

存储状态常量

Variables

View Source
var (
	ErrStorageNotFound    = errors.New("存储不存在")
	ErrStorageInitFailed  = errors.New("存储初始化失败")
	ErrStorageDisabled    = errors.New("存储已禁用")
	ErrDriverNotSupported = errors.New("不支持的驱动类型")
	ErrInvalidMountPath   = errors.New("无效的挂载路径")
	ErrDriverTypeLocked   = errors.New("驱动类型不能更改")
)

错误类型定义

View Source
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

func CallStorageHooks(typ string, storage driver.Driver)

CallStorageHooks calls all registered storage hooks

func Cancel2FAByID

func Cancel2FAByID(id uint) error

Cancel2FAByID disables two-factor authentication for a user by ID

func Cancel2FAByUser

func Cancel2FAByUser(user *model.User) error

Cancel2FAByUser disables two-factor authentication for a user

func ClearCache

func ClearCache(storage driver.Driver, path string)

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

func CreateMeta(meta *model.Meta) error

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

func CreateStorage(ctx context.Context, storage model.Storage) (uint, error)

CreateStorage 将存储配置保存到数据库并实例化驱动 返回存储ID和可能发生的错误

func CreateUser

func CreateUser(user *model.User) error

CreateUser creates a new user

func DelUserCache

func DelUserCache(username string) error

DelUserCache removes a user from cache Also clears special user instances if needed

func DeleteCache added in v4.2.7

func DeleteCache(storage driver.Driver, path string)

func DeleteMetaByID

func DeleteMetaByID(id uint) error

DeleteMetaByID deletes metadata by its ID and removes it from cache

func DeleteSSHPublicKeyByID

func DeleteSSHPublicKeyByID(keyID uint) error

DeleteSSHPublicKeyByID deletes an SSH public key by its ID

func DeleteSettingItemByKey

func DeleteSettingItemByKey(key string) error

DeleteSettingItemByKey deletes a setting item by its key Only deprecated items can be deleted

func DeleteStorageByID

func DeleteStorageByID(ctx context.Context, id uint) error

DeleteStorageByID 完全删除存储

func DeleteUserByID

func DeleteUserByID(id uint) error

DeleteUserByID deletes a user by ID Admin and guest users cannot be deleted

func DisableStorage

func DisableStorage(ctx context.Context, id uint) error

DisableStorage 禁用活动存储

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 EnableStorage

func EnableStorage(ctx context.Context, id uint) error

EnableStorage 启用之前禁用的存储

func Get

func Get(ctx context.Context, storage driver.Driver, path string) (model.Obj, error)

Get object from list of files

func GetAdmin

func GetAdmin() (*model.User, error)

GetAdmin returns the admin user, loading it from database if necessary

func GetAllStorages

func GetAllStorages() []driver.Driver

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

func GetBalancedStorage(path string) driver.Driver

GetBalancedStorage 返回路径的存储,如果存在多个则使用轮询

func GetDriverInfoMap

func GetDriverInfoMap() map[string]driver.Info

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 GetGuest

func GetGuest() (*model.User, error)

GetGuest returns the guest user, loading it from database if necessary

func GetMetaByID

func GetMetaByID(id uint) (*model.Meta, error)

GetMetaByID retrieves metadata by its ID directly from the database

func GetMetaByPath

func GetMetaByPath(path string) (*model.Meta, error)

GetMetaByPath returns metadata for the exact path specified It will clean the path before searching

func GetMetas

func GetMetas(pageIndex, pageSize int) (metas []model.Meta, count int64, err error)

GetMetas retrieves a paginated list of all metadata

func GetNearestMeta

func GetNearestMeta(path string) (*model.Meta, error)

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

func GetPublicSettingsMap() map[string]string

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

func GetSettingsMap() map[string]string

GetSettingsMap returns a map of all settings with key-value pairs

func GetStorageAndActualPath

func GetStorageAndActualPath(rawPath string) (storage driver.Driver, actualPath string, err error)

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

func GetStorageByMountPath(mountPath string) (driver.Driver, error)

GetStorageByMountPath 通过挂载路径获取存储驱动

func GetStorageStats added in v4.2.6

func GetStorageStats() map[string]int

GetStorageStats 返回存储统计信息 包括活动存储数量、禁用存储数量和总存储数量

func GetStorageVirtualFilesByPath

func GetStorageVirtualFilesByPath(prefix string) []model.Obj

GetStorageVirtualFilesByPath 返回路径下存储生成的虚拟文件/文件夹 例如,给定存储位置:/a/b, /a/c, /a/d/e, /a/b.balance1, /av GetStorageVirtualFilesByPath(/a) => 虚拟文件夹 b, c, d

func GetUnwrap

func GetUnwrap(ctx context.Context, storage driver.Driver, path string) (model.Obj, error)

func GetUserByID

func GetUserByID(id uint) (*model.User, error)

GetUserByID retrieves a user by ID

func GetUserByName

func GetUserByName(username string) (*model.User, error)

GetUserByName retrieves a user by username, using cache when available

func GetUserByRole

func GetUserByRole(role int) (*model.User, error)

GetUserByRole retrieves a user with a specific role

func GetUsers

func GetUsers(pageIndex, pageSize int) (users []model.User, count int64, err error)

GetUsers retrieves a paginated list of users

func HandleObjsUpdateHook

func HandleObjsUpdateHook(parent string, objs []model.Obj)

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 HasStorage

func HasStorage(mountPath string) bool

HasStorage 检查给定挂载路径是否存在存储

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 IsUseOnlineAPI(storageDriver driver.Driver) bool

func Key

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)

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

func LoadStorage(ctx context.Context, storage model.Storage) error

LoadStorage 从数据库加载现有存储到内存

func MakeDir

func MakeDir(ctx context.Context, storage driver.Driver, path string, lazyCache ...bool) error

func Move

func Move(ctx context.Context, storage driver.Driver, srcPath, dstDirPath string, lazyCache ...bool) error

func MustSaveDriverStorage

func MustSaveDriverStorage(driver driver.Driver)

MustSaveDriverStorage 保存驱动存储配置 并记录任何错误而不返回它们

func Other

func Other(ctx context.Context, storage driver.Driver, args model.FsOtherArgs) (any, error)

Other api

func Put

func Put(ctx context.Context, storage driver.Driver, dstDirPath string, file model.FileStreamer, up driver.UpdateProgress, lazyCache ...bool) error

func PutURL

func PutURL(ctx context.Context, storage driver.Driver, dstDirPath, dstName, url string, lazyCache ...bool) error

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 Remove

func Remove(ctx context.Context, storage driver.Driver, path string) error

func Rename

func Rename(ctx context.Context, storage driver.Driver, srcPath, dstName string, lazyCache ...bool) error

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

func URLTreeSplitPathAndURL(path string) (dirPath string, urlPart string)

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

func UpdateMeta(meta *model.Meta) error

UpdateMeta updates metadata and refreshes the cache

func UpdateSSHPublicKey

func UpdateSSHPublicKey(key *model.SSHPublicKey) error

UpdateSSHPublicKey updates an existing SSH public key

func UpdateStorage

func UpdateStorage(ctx context.Context, storage model.Storage) error

UpdateStorage 更新现有存储配置 包括使用新配置重新初始化驱动

func UpdateUser

func UpdateUser(user *model.User) error

UpdateUser updates a user's information

Types

type DriverConstructor

type DriverConstructor func() driver.Driver

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

type ObjsUpdateHook = func(parent string, objs []model.Obj)

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

type StorageHook func(typ string, storage driver.Driver)

StorageHook is a function type for hooks that process storage operations

Jump to

Keyboard shortcuts

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