model

package
v4.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2025 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SINGLE = iota
	SITE
	STYLE
	PREVIEW
	GLOBAL
	OFFLINE_DOWNLOAD
	INDEX
	SSO
	LDAP
	S3
	FTP
	TRAFFIC
)
View Source
const (
	PUBLIC = iota
	PRIVATE
	READONLY
	DEPRECATED
)
View Source
const (
	GENERAL = iota
	GUEST   // only one exists
	ADMIN
)
View Source
const MaxInt = int(MaxUint >> 1)
View Source
const MaxUint = ^uint(0)
View Source
const MinInt = -MaxInt - 1
View Source
const MinUint = 0
View Source
const StaticHashSalt = "https://github.com/alist-org/alist"

Variables

View Source
var (
	DefaultLockDuration   = time.Minute * 5
	DefaultMaxAuthRetries = 5
)
View Source
var LoginCache = cache.NewMemCache[int]()

Functions

func ExtractFolder

func ExtractFolder(objs []Obj, extractFolder string)

func GetProvider added in v4.1.3

func GetProvider(obj Obj) (string, bool)

func GetThumb

func GetThumb(obj Obj) (thumb string, ok bool)

func GetUrl

func GetUrl(obj Obj) (url string, ok bool)

func HashPwd

func HashPwd(static string, salt string) string

func SortFiles

func SortFiles(objs []Obj, orderBy, orderDirection string)

func StaticHash

func StaticHash(password string) string

func TwoHashPwd

func TwoHashPwd(password string, salt string) string

func WrapObjsName

func WrapObjsName(objs []Obj)

Types

type ArchiveArgs

type ArchiveArgs struct {
	Password string
	LinkArgs
}

type ArchiveDecompressArgs

type ArchiveDecompressArgs struct {
	ArchiveInnerArgs
	CacheFull     bool
	PutIntoNewDir bool
}

type ArchiveInnerArgs

type ArchiveInnerArgs struct {
	ArchiveArgs
	InnerPath string
}

type ArchiveListArgs

type ArchiveListArgs struct {
	ArchiveInnerArgs
	Refresh bool
}

type ArchiveMeta

type ArchiveMeta interface {
	GetComment() string
	// IsEncrypted means if the content of the archive requires a password to access
	// GetArchiveMeta should return errs.WrongArchivePassword if the meta-info is also encrypted,
	// and the provided password is empty.
	IsEncrypted() bool
	// GetTree directly returns the full folder structure
	// returns nil if the folder structure should be acquired by calling driver.ArchiveReader.ListArchive
	GetTree() []ObjTree
}

type ArchiveMetaArgs

type ArchiveMetaArgs struct {
	ArchiveArgs
	Refresh bool
}

type ArchiveMetaInfo

type ArchiveMetaInfo struct {
	Comment   string
	Encrypted bool
	Tree      []ObjTree
}

func (*ArchiveMetaInfo) GetComment

func (m *ArchiveMetaInfo) GetComment() string

func (*ArchiveMetaInfo) GetTree

func (m *ArchiveMetaInfo) GetTree() []ObjTree

func (*ArchiveMetaInfo) IsEncrypted

func (m *ArchiveMetaInfo) IsEncrypted() bool

type ArchiveMetaProvider

type ArchiveMetaProvider struct {
	ArchiveMeta
	*Sort
	DriverProviding bool
	Expiration      *time.Duration
}

type DiskUsage added in v4.1.4

type DiskUsage struct {
	TotalSpace uint64 `json:"total_space"`
	FreeSpace  uint64 `json:"free_space"`
}

type File

type File interface {
	io.Reader
	io.ReaderAt
	io.Seeker
}

File is basic file level accessing interface

type FileCloser added in v4.0.9

type FileCloser struct {
	File
	io.Closer
}

func (*FileCloser) Close added in v4.0.9

func (f *FileCloser) Close() error

type FileRangeReader added in v4.0.9

type FileRangeReader struct {
	RangeReaderIF
}

type FileStreamer

type FileStreamer interface {
	io.Reader
	utils.ClosersIF
	Obj
	GetMimetype() string
	NeedStore() bool
	IsForceStreamUpload() bool
	GetExist() Obj
	SetExist(Obj)
	// for a non-seekable Stream, RangeRead supports peeking some data, and CacheFullAndWriter still works
	RangeRead(http_range.Range) (io.Reader, error)
	// for a non-seekable Stream, if Read is called, this function won't work.
	// caches the full Stream and writes it to writer (if provided, even if the stream is already cached).
	CacheFullAndWriter(up *UpdateProgress, writer io.Writer) (File, error)
	SetTmpFile(file File)
	// if the Stream is not a File and is not cached, returns nil.
	GetFile() File
}

FileStreamer ->check FileStream for more comments

type FsOtherArgs

type FsOtherArgs struct {
	Path   string      `json:"path" form:"path"`
	Method string      `json:"method" form:"method"`
	Data   interface{} `json:"data" form:"data"`
}

type IndexProgress

type IndexProgress struct {
	ObjCount     uint64     `json:"obj_count"`
	IsDone       bool       `json:"is_done"`
	LastDoneTime *time.Time `json:"last_done_time"`
	Error        string     `json:"error"`
}
type Link struct {
	URL         string        `json:"url"`    // most common way
	Header      http.Header   `json:"header"` // needed header (for url)
	RangeReader RangeReaderIF `json:"-"`      // recommended way if can't use URL

	Expiration *time.Duration // local cache expire Duration

	//for accelerating request, use multi-thread downloading
	Concurrency   int   `json:"concurrency"`
	PartSize      int   `json:"part_size"`
	ContentLength int64 `json:"-"` // 转码视频、缩略图

	utils.SyncClosers `json:"-"`
	// 如果SyncClosers中的资源被关闭后Link将不可用,则此值应为 true
	RequireReference bool `json:"-"`
}

type LinkArgs

type LinkArgs struct {
	IP       string
	Header   http.Header
	Type     string
	Redirect bool
}

type ListArgs

type ListArgs struct {
	ReqPath            string
	S3ShowPlaceholder  bool
	Refresh            bool
	WithStorageDetails bool
}

type Meta

type Meta struct {
	ID        uint   `json:"id" gorm:"primaryKey"`
	Path      string `json:"path" gorm:"unique" binding:"required"`
	Password  string `json:"password"`
	PSub      bool   `json:"p_sub"`
	Write     bool   `json:"write"`
	WSub      bool   `json:"w_sub"`
	Hide      string `json:"hide"`
	HSub      bool   `json:"h_sub"`
	Readme    string `json:"readme"`
	RSub      bool   `json:"r_sub"`
	Header    string `json:"header"`
	HeaderSub bool   `json:"header_sub"`
}

type Obj

type Obj interface {
	GetSize() int64
	GetName() string
	ModTime() time.Time
	CreateTime() time.Time
	IsDir() bool
	GetHash() utils.HashInfo

	// The internal information of the driver.
	// If you want to use it, please understand what it means
	GetID() string
	GetPath() string
}

func UnwrapObj

func UnwrapObj(obj Obj) Obj

func WrapObjName

func WrapObjName(objs Obj) Obj

type ObjMerge

type ObjMerge struct {
	// contains filtered or unexported fields
}

func NewObjMerge

func NewObjMerge() *ObjMerge

Merge

func (*ObjMerge) InitHideReg

func (om *ObjMerge) InitHideReg(hides string)

func (*ObjMerge) Merge

func (om *ObjMerge) Merge(objs []Obj, objs_ ...Obj) []Obj

func (*ObjMerge) Reset

func (om *ObjMerge) Reset()

type ObjStorageDetails added in v4.1.4

type ObjStorageDetails struct {
	Obj
	StorageDetailsWithName
}

func (ObjStorageDetails) GetStorageDetails added in v4.1.4

func (o ObjStorageDetails) GetStorageDetails() *StorageDetailsWithName

type ObjThumb

type ObjThumb struct {
	Object
	Thumbnail
}

type ObjThumbURL

type ObjThumbURL struct {
	Object
	Thumbnail
	Url
}

type ObjTree

type ObjTree interface {
	Obj
	GetChildren() []ObjTree
}

type ObjUnwrap

type ObjUnwrap interface {
	Unwrap() Obj
}

type ObjWithProvider added in v4.1.3

type ObjWithProvider interface {
	GetProvider() string
}

type ObjWithStorageDetails added in v4.1.4

type ObjWithStorageDetails interface {
	GetStorageDetails() *StorageDetailsWithName
}

type ObjWrapName

type ObjWrapName struct {
	Name string
	Obj
}

func (*ObjWrapName) GetName

func (o *ObjWrapName) GetName() string

func (*ObjWrapName) Unwrap

func (o *ObjWrapName) Unwrap() Obj

type Object

type Object struct {
	ID       string
	Path     string
	Name     string
	Size     int64
	Modified time.Time
	Ctime    time.Time // file create time
	IsFolder bool
	HashInfo utils.HashInfo
}

func GetRawObject

func GetRawObject(obj Obj) *Object

func (*Object) CreateTime

func (o *Object) CreateTime() time.Time

func (*Object) GetHash

func (o *Object) GetHash() utils.HashInfo

func (*Object) GetID

func (o *Object) GetID() string

func (*Object) GetName

func (o *Object) GetName() string

func (*Object) GetPath

func (o *Object) GetPath() string

func (*Object) GetSize

func (o *Object) GetSize() int64

func (*Object) IsDir

func (o *Object) IsDir() bool

func (*Object) ModTime

func (o *Object) ModTime() time.Time

func (*Object) SetPath

func (o *Object) SetPath(path string)

type ObjectProvider added in v4.1.3

type ObjectProvider struct {
	Object
	Provider
}

type ObjectTree

type ObjectTree struct {
	Object
	Children []ObjTree
}

func (*ObjectTree) GetChildren

func (t *ObjectTree) GetChildren() []ObjTree

type ObjectURL

type ObjectURL struct {
	Object
	Url
}

type OtherArgs

type OtherArgs struct {
	Obj    Obj
	Method string
	Data   interface{}
}

type PageReq

type PageReq struct {
	Page    int `json:"page" form:"page"`
	PerPage int `json:"per_page" form:"per_page"`
}

func (*PageReq) Validate

func (p *PageReq) Validate()

type Provider added in v4.1.3

type Provider struct {
	Provider string
}

func (Provider) GetProvider added in v4.1.3

func (p Provider) GetProvider() string

type Proxy

type Proxy struct {
	WebProxy     bool   `json:"web_proxy"`
	WebdavPolicy string `json:"webdav_policy"`
	ProxyRange   bool   `json:"proxy_range"`
	DownProxyURL string `json:"down_proxy_url"`
	// Disable sign for DownProxyURL
	DisableProxySign bool `json:"disable_proxy_sign"`
}

func (Proxy) Webdav302

func (p Proxy) Webdav302() bool

func (Proxy) WebdavProxyURL added in v4.0.9

func (p Proxy) WebdavProxyURL() bool

type RangeReadCloser

type RangeReadCloser struct {
	RangeReader RangeReaderIF
	utils.Closers
}

func (*RangeReadCloser) RangeRead

func (r *RangeReadCloser) RangeRead(ctx context.Context, httpRange http_range.Range) (io.ReadCloser, error)

type RangeReadCloserIF

type RangeReadCloserIF interface {
	RangeReaderIF
	utils.ClosersIF
}

type RangeReaderIF added in v4.0.9

type RangeReaderIF interface {
	RangeRead(ctx context.Context, httpRange http_range.Range) (io.ReadCloser, error)
}

type SSHPublicKey

type SSHPublicKey struct {
	ID           uint      `json:"id" gorm:"primaryKey"`
	UserId       uint      `json:"-"`
	Title        string    `json:"title"`
	Fingerprint  string    `json:"fingerprint"`
	KeyStr       string    `gorm:"type:text" json:"-"`
	AddedTime    time.Time `json:"added_time"`
	LastUsedTime time.Time `json:"last_used_time"`
}

func (*SSHPublicKey) GetKey

func (k *SSHPublicKey) GetKey() (ssh.PublicKey, error)

func (*SSHPublicKey) UpdateLastUsedTime

func (k *SSHPublicKey) UpdateLastUsedTime()

type SearchNode

type SearchNode struct {
	Parent string `json:"parent" gorm:"index"`
	Name   string `json:"name"`
	IsDir  bool   `json:"is_dir"`
	Size   int64  `json:"size"`
}

func (*SearchNode) Type

func (s *SearchNode) Type() string

type SearchReq

type SearchReq struct {
	Parent   string `json:"parent"`
	Keywords string `json:"keywords"`
	// 0 for all, 1 for dir, 2 for file
	Scope int `json:"scope"`
	PageReq
}

func (*SearchReq) Validate

func (p *SearchReq) Validate() error

type SetPath

type SetPath interface {
	SetPath(path string)
}

type SettingItem

type SettingItem struct {
	Key            string `json:"key" gorm:"primaryKey" binding:"required"` // unique key
	Value          string `json:"value"`                                    // value
	MigrationValue string `json:"-" gorm:"-:all"`                           // deprecated value
	Help           string `json:"help"`                                     // help message
	Type           string `json:"type"`                                     // string, number, bool, select
	Options        string `json:"options"`                                  // values for select
	Group          int    `json:"group"`                                    // use to group setting in frontend
	Flag           int    `json:"flag"`                                     // 0 = public, 1 = private, 2 = readonly, 3 = deprecated, etc.
	Index          uint   `json:"index"`
}

func (SettingItem) IsDeprecated

func (s SettingItem) IsDeprecated() bool

type Sharing added in v4.1.2

type Sharing struct {
	*SharingDB
	Files   []string `json:"files"`
	Creator *User    `json:"-"`
}

func (*Sharing) Valid added in v4.1.2

func (s *Sharing) Valid() bool

func (*Sharing) Verify added in v4.1.2

func (s *Sharing) Verify(pwd string) bool

type SharingArchiveListArgs added in v4.1.2

type SharingArchiveListArgs struct {
	ArchiveListArgs
	Pwd string
}

type SharingArchiveMetaArgs added in v4.1.2

type SharingArchiveMetaArgs struct {
	ArchiveMetaArgs
	Pwd string
}

type SharingDB added in v4.1.2

type SharingDB struct {
	ID          string     `json:"id" gorm:"type:char(12);primaryKey"`
	FilesRaw    string     `json:"-" gorm:"type:text"`
	Expires     *time.Time `json:"expires"`
	Pwd         string     `json:"pwd"`
	Accessed    int        `json:"accessed"`
	MaxAccessed int        `json:"max_accessed"`
	CreatorId   uint       `json:"-"`
	Disabled    bool       `json:"disabled"`
	Remark      string     `json:"remark"`
	Readme      string     `json:"readme" gorm:"type:text"`
	Header      string     `json:"header" gorm:"type:text"`
	Sort
}

type SharingLinkArgs added in v4.1.2

type SharingLinkArgs struct {
	Pwd string
	LinkArgs
}

type SharingListArgs added in v4.1.2

type SharingListArgs struct {
	Refresh bool
	Pwd     string
}

type Sort

type Sort struct {
	OrderBy        string `json:"order_by"`
	OrderDirection string `json:"order_direction"`
	ExtractFolder  string `json:"extract_folder"`
}

type Storage

type Storage struct {
	ID              uint      `json:"id" gorm:"primaryKey"`                        // unique key
	MountPath       string    `json:"mount_path" gorm:"unique" binding:"required"` // must be standardized
	Order           int       `json:"order"`                                       // use to sort
	Driver          string    `json:"driver"`                                      // driver used
	CacheExpiration int       `json:"cache_expiration"`                            // cache expire time
	Status          string    `json:"status"`
	Addition        string    `json:"addition" gorm:"type:text"` // Additional information, defined in the corresponding driver
	Remark          string    `json:"remark"`
	Modified        time.Time `json:"modified"`
	Disabled        bool      `json:"disabled"` // if disabled
	DisableIndex    bool      `json:"disable_index"`
	EnableSign      bool      `json:"enable_sign"`
	Sort
	Proxy
}

func (*Storage) GetStorage

func (s *Storage) GetStorage() *Storage

func (*Storage) SetStatus

func (s *Storage) SetStatus(status string)

func (*Storage) SetStorage

func (s *Storage) SetStorage(storage Storage)

type StorageDetails added in v4.1.4

type StorageDetails struct {
	DiskUsage
}

type StorageDetailsWithName added in v4.1.4

type StorageDetailsWithName struct {
	*StorageDetails
	DriverName string `json:"driver_name"`
}

func GetStorageDetails added in v4.1.4

func GetStorageDetails(obj Obj) (*StorageDetailsWithName, bool)

type TaskItem

type TaskItem struct {
	Key         string `json:"key"`
	PersistData string `gorm:"type:text" json:"persist_data"`
}

type Thumb

type Thumb interface {
	Thumb() string
}

type Thumbnail

type Thumbnail struct {
	Thumbnail string
}

func (Thumbnail) Thumb

func (t Thumbnail) Thumb() string

type URL

type URL interface {
	URL() string
}

type UpdateProgress

type UpdateProgress func(percentage float64)

func UpdateProgressWithRange added in v4.0.9

func UpdateProgressWithRange(inner UpdateProgress, start, end float64) UpdateProgress

type Url

type Url struct {
	Url string
}

func (Url) URL

func (w Url) URL() string

type User

type User struct {
	ID       uint   `json:"id" gorm:"primaryKey"`                      // unique key
	Username string `json:"username" gorm:"unique" binding:"required"` // username
	PwdHash  string `json:"-"`                                         // password hash
	PwdTS    int64  `json:"-"`                                         // password timestamp
	Salt     string `json:"-"`                                         // unique salt
	Password string `json:"password"`                                  // password
	BasePath string `json:"base_path"`                                 // base path
	Role     int    `json:"role"`                                      // user's role
	Disabled bool   `json:"disabled"`
	// Determine permissions by bit
	//   0:  can see hidden files
	//   1:  can access without password
	//   2:  can add offline download tasks
	//   3:  can mkdir and upload
	//   4:  can rename
	//   5:  can move
	//   6:  can copy
	//   7:  can remove
	//   8:  webdav read
	//   9:  webdav write
	//   10: ftp/sftp login and read
	//   11: ftp/sftp write
	//   12: can read archives
	//   13: can decompress archives
	//   14: can share
	Permission int32  `json:"permission"`
	OtpSecret  string `json:"-"`
	SsoID      string `json:"sso_id"` // unique by sso platform
	Authn      string `gorm:"type:text" json:"-"`
}

func (*User) CanAccessWithoutPassword

func (u *User) CanAccessWithoutPassword() bool

func (*User) CanAddOfflineDownloadTasks

func (u *User) CanAddOfflineDownloadTasks() bool

func (*User) CanCopy

func (u *User) CanCopy() bool

func (*User) CanDecompress

func (u *User) CanDecompress() bool

func (*User) CanFTPAccess

func (u *User) CanFTPAccess() bool

func (*User) CanFTPManage

func (u *User) CanFTPManage() bool

func (*User) CanMove

func (u *User) CanMove() bool

func (*User) CanReadArchives

func (u *User) CanReadArchives() bool

func (*User) CanRemove

func (u *User) CanRemove() bool

func (*User) CanRename

func (u *User) CanRename() bool

func (*User) CanSeeHides

func (u *User) CanSeeHides() bool

func (*User) CanShare added in v4.1.2

func (u *User) CanShare() bool

func (*User) CanWebdavManage

func (u *User) CanWebdavManage() bool

func (*User) CanWebdavRead

func (u *User) CanWebdavRead() bool

func (*User) CanWrite

func (u *User) CanWrite() bool

func (*User) IsAdmin

func (u *User) IsAdmin() bool

func (*User) IsGuest

func (u *User) IsGuest() bool

func (*User) JoinPath

func (u *User) JoinPath(reqPath string) (string, error)

func (*User) SetPassword

func (u *User) SetPassword(pwd string) *User

func (*User) ValidatePwdStaticHash

func (u *User) ValidatePwdStaticHash(pwdStaticHash string) error

func (*User) ValidateRawPassword

func (u *User) ValidateRawPassword(password string) error

func (*User) WebAuthnCredentials

func (u *User) WebAuthnCredentials() []webauthn.Credential

func (*User) WebAuthnDisplayName

func (u *User) WebAuthnDisplayName() string

func (*User) WebAuthnID

func (u *User) WebAuthnID() []byte

func (*User) WebAuthnIcon

func (u *User) WebAuthnIcon() string

func (*User) WebAuthnName

func (u *User) WebAuthnName() string

Jump to

Keyboard shortcuts

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