op

package
v4.1.9 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: AGPL-3.0 Imports: 30 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

Variables

This section is empty.

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)

ClearCache recursively clears the cache for a path and all its subdirectories

func Copy

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

Copy copies a file or directory to another location

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 saves a storage configuration to the database and instantiates the driver Returns the storage ID and any error that occurred

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 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 completely removes a storage

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 disables an active storage

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 enables a previously disabled storage

func Get

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

Get retrieves an object (file or directory) from storage by path First tries to use storage's direct Get method if available, otherwise uses List

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 returns all active storage drivers

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 returns a storage for a path, using round-robin if multiple exist

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 retrieves a storage driver by its mount path

func GetStorageVirtualFilesByPath

func GetStorageVirtualFilesByPath(prefix string) []model.Obj

GetStorageVirtualFilesByPath returns virtual files/folders generated by storages under a path For example, given storages at: /a/b, /a/c, /a/d/e, /a/b.balance1, /av GetStorageVirtualFilesByPath(/a) => virtual folders b, c, d

func GetUnwrap

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

GetUnwrap retrieves an object and unwraps it to get the underlying object This removes any name wrappers that might have been added

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 checks if a storage exists at the given mount path

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 Key

func Key(storage driver.Driver, path string) string

Key generates a unique cache key for a storage and path combination The key incorporates the storage mount path to ensure uniqueness across storages

func Link(ctx context.Context, storage driver.Driver, path string, args model.LinkArgs) (*model.Link, model.Obj, error)

Link gets a download link for a file Uses cache when available to avoid repeated requests

func List

func List(ctx context.Context, storage driver.Driver, path string, args model.ListArgs) ([]model.Obj, error)

List returns a list of files and directories at the specified path Uses cache when available unless refresh is requested

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 loads an existing storage from the database into memory

func MakeDir

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

MakeDir creates a directory at the specified path If the parent directory doesn't exist, it will be created recursively

func Move

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

Move moves a file or directory from one location to another

func MustSaveDriverStorage

func MustSaveDriverStorage(driver driver.Driver)

MustSaveDriverStorage saves driver storage configuration and logs any errors without returning them

func Other

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

Other executes a driver-specific operation on an object

func Put

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

Put uploads a file to the specified directory

func PutURL

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

PutURL uploads a file from a URL to the specified directory

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

Remove deletes a file or directory

func Rename

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

Rename changes the name of a file or directory

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 updates an existing storage configuration This includes re-initializing the driver with the new configuration

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