model

package
v3.52.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	SessionActive = iota
	SessionInactive
)
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
	NEWGENERAL
)
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 FetchRole func(uint) (*Role, error)

FetchRole is used to load role details by id. It should be set by the op package to avoid an import cycle between model and op.

Functions

func ExtractFolder

func ExtractFolder(objs []Obj, extractFolder string)

func GetAllBasePathsFromRoles added in v3.49.0

func GetAllBasePathsFromRoles(u *User) []string

GetAllBasePathsFromRoles returns all permission paths from user's roles

func GetThumb added in v3.7.1

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

func GetUrl added in v3.7.1

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

func HashPwd added in v3.25.0

func HashPwd(static string, salt string) string

func SortFiles

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

func StaticHash added in v3.25.0

func StaticHash(password string) string

func TwoHashPwd added in v3.25.0

func TwoHashPwd(password string, salt string) string

func WrapObjsName added in v3.7.1

func WrapObjsName(objs []Obj)

Types

type ArchiveArgs added in v3.42.0

type ArchiveArgs struct {
	Password string
	LinkArgs
}

type ArchiveDecompressArgs added in v3.42.0

type ArchiveDecompressArgs struct {
	ArchiveInnerArgs
	CacheFull     bool
	PutIntoNewDir bool
}

type ArchiveInnerArgs added in v3.42.0

type ArchiveInnerArgs struct {
	ArchiveArgs
	InnerPath string
}

type ArchiveListArgs added in v3.42.0

type ArchiveListArgs struct {
	ArchiveInnerArgs
	Refresh bool
}

type ArchiveMeta added in v3.42.0

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 added in v3.42.0

type ArchiveMetaArgs struct {
	ArchiveArgs
	Refresh bool
}

type ArchiveMetaInfo added in v3.42.0

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

func (*ArchiveMetaInfo) GetComment added in v3.42.0

func (m *ArchiveMetaInfo) GetComment() string

func (*ArchiveMetaInfo) GetTree added in v3.42.0

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

func (*ArchiveMetaInfo) IsEncrypted added in v3.42.0

func (m *ArchiveMetaInfo) IsEncrypted() bool

type ArchiveMetaProvider added in v3.42.0

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

type File added in v3.27.0

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

File is basic file level accessing interface

func NewNopMFile added in v3.27.0

func NewNopMFile(r NopMFileIF) File

type FileStreamer

type FileStreamer interface {
	io.Reader
	io.Closer
	Obj
	GetMimetype() string
	//SetReader(io.Reader)
	NeedStore() bool
	IsForceStreamUpload() bool
	GetExist() Obj
	SetExist(Obj)
	//for a non-seekable Stream, RangeRead supports peeking some data, and CacheFullInTempFile still works
	RangeRead(http_range.Range) (io.Reader, error)
	//for a non-seekable Stream, if Read is called, this function won't work
	CacheFullInTempFile() (File, error)
	SetTmpFile(r *os.File)
	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 added in v3.6.0

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 Label added in v3.46.0

type Label struct {
	ID          uint      `json:"id" gorm:"primaryKey"` // unique key
	Type        int       `json:"type"`                 // use to type
	Name        string    `json:"name"`                 // use to name
	Description string    `json:"description"`          // use to description
	BgColor     string    `json:"bg_color"`             // use to bg_color
	CreateTime  time.Time `json:"create_time"`
}

type LabelFileBinding added in v3.50.0

type LabelFileBinding struct {
	ID         uint      `json:"id" gorm:"primaryKey"` // unique key
	UserId     uint      `json:"user_id"`              // use to user_id
	LabelId    uint      `json:"label_id"`             // use to label_id
	FileName   string    `json:"file_name"`            // use to file_name
	CreateTime time.Time `json:"create_time"`
}
type Link struct {
	URL             string            `json:"url"`    // most common way
	Header          http.Header       `json:"header"` // needed header (for url)
	RangeReadCloser RangeReadCloserIF `json:"-"`      // recommended way if can't use URL
	MFile           File              `json:"-"`      // best for local,smb... file system, which exposes MFile

	Expiration *time.Duration // local cache expire Duration
	IPCacheKey bool           `json:"-"` // add ip to cache key

	//for accelerating request, use multi-thread downloading
	Concurrency int `json:"concurrency"`
	PartSize    int `json:"part_size"`
}

type LinkArgs

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

type ListArgs

type ListArgs struct {
	ReqPath           string
	S3ShowPlaceholder bool
	Refresh           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 NopMFile added in v3.27.0

type NopMFile struct {
	NopMFileIF
}

func (NopMFile) Close added in v3.27.0

func (NopMFile) Close() error

type NopMFileIF added in v3.27.0

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

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 added in v3.7.1

func UnwrapObj(obj Obj) Obj

func WrapObjName added in v3.7.1

func WrapObjName(objs Obj) Obj

type ObjFile added in v3.46.0

type ObjFile struct {
	Id          string    `json:"id"`
	UserId      uint      `json:"user_id"`
	Path        string    `json:"path"`
	Name        string    `json:"name"`
	Size        int64     `json:"size"`
	IsDir       bool      `json:"is_dir"`
	Modified    time.Time `json:"modified"`
	Created     time.Time `json:"created"`
	Sign        string    `json:"sign"`
	Thumb       string    `json:"thumb"`
	Type        int       `json:"type"`
	HashInfoStr string    `json:"hashinfo"`
}

type ObjMerge added in v3.7.1

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

func NewObjMerge added in v3.7.1

func NewObjMerge() *ObjMerge

Merge

func (*ObjMerge) InitHideReg added in v3.7.1

func (om *ObjMerge) InitHideReg(hides string)

func (*ObjMerge) Merge added in v3.7.1

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

func (*ObjMerge) Reset added in v3.7.1

func (om *ObjMerge) Reset()

type ObjThumb

type ObjThumb struct {
	Object
	Thumbnail
}

type ObjThumbURL

type ObjThumbURL struct {
	Object
	Thumbnail
	Url
}

type ObjTree added in v3.42.0

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

type ObjUnwrap added in v3.9.0

type ObjUnwrap interface {
	Unwrap() Obj
}

type ObjWrapName added in v3.7.1

type ObjWrapName struct {
	Name string
	Obj
}

func (*ObjWrapName) GetName added in v3.7.1

func (o *ObjWrapName) GetName() string

func (*ObjWrapName) Unwrap added in v3.7.1

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 added in v3.29.0

func GetRawObject(obj Obj) *Object

func (*Object) CreateTime added in v3.27.0

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

func (*Object) GetHash added in v3.25.0

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 ObjectTree added in v3.42.0

type ObjectTree struct {
	Object
	Children []ObjTree
}

func (*ObjectTree) GetChildren added in v3.42.0

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 added in v3.6.0

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

func (*PageReq) Validate added in v3.6.0

func (p *PageReq) Validate()

type Paths added in v3.46.0

type Paths []string

func (*Paths) Scan added in v3.46.0

func (p *Paths) Scan(value interface{}) error

func (Paths) Value added in v3.46.0

func (p Paths) Value() (driver.Value, error)

type PermissionEntry added in v3.46.0

type PermissionEntry struct {
	Path       string `json:"path"`       // path prefix, e.g. "/admin"
	Permission int32  `json:"permission"` // bitmask permissions
}

PermissionEntry defines permission bitmask for a specific path.

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"`
}

func (Proxy) Webdav302

func (p Proxy) Webdav302() bool

func (Proxy) WebdavNative

func (p Proxy) WebdavNative() bool

func (Proxy) WebdavProxy

func (p Proxy) WebdavProxy() bool

type RangeReadCloser added in v3.25.0

type RangeReadCloser struct {
	RangeReader RangeReaderFunc
	utils.Closers
}

func (*RangeReadCloser) RangeRead added in v3.27.0

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

type RangeReadCloserIF added in v3.27.0

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

type RangeReaderFunc added in v3.25.0

type RangeReaderFunc func(ctx context.Context, httpRange http_range.Range) (io.ReadCloser, error)

type WriterFunc func(w io.Writer) error

type Role added in v3.46.0

type Role struct {
	ID          uint   `json:"id" gorm:"primaryKey"`
	Name        string `json:"name" gorm:"unique" binding:"required"`
	Description string `json:"description"`
	Default     bool   `json:"default" gorm:"default:false"`
	// PermissionScopes stores structured permission list and is ignored by gorm.
	PermissionScopes []PermissionEntry `json:"permission_scopes" gorm:"-"`
	// RawPermission is the JSON representation of PermissionScopes stored in DB.
	RawPermission string `json:"-" gorm:"type:text"`
}

Role represents a permission template which can be bound to users.

func (*Role) AfterFind added in v3.46.0

func (r *Role) AfterFind(tx *gorm.DB) error

AfterFind GORM hook deserializes RawPermission into PermissionScopes.

func (*Role) BeforeSave added in v3.46.0

func (r *Role) BeforeSave(tx *gorm.DB) error

BeforeSave GORM hook serializes PermissionScopes into RawPermission.

type Roles added in v3.46.0

type Roles []int

func (Roles) Contains added in v3.46.0

func (r Roles) Contains(role int) bool

func (*Roles) Scan added in v3.46.0

func (r *Roles) Scan(value interface{}) error

func (Roles) Value added in v3.46.0

func (r Roles) Value() (driver.Value, error)

type SSHPublicKey added in v3.42.0

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 added in v3.42.0

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

func (*SSHPublicKey) UpdateLastUsedTime added in v3.42.0

func (k *SSHPublicKey) UpdateLastUsedTime()

type SearchNode added in v3.6.0

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 added in v3.6.0

func (s *SearchNode) Type() string

type SearchReq added in v3.6.0

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 added in v3.6.0

func (p *SearchReq) Validate() error

type Session added in v3.52.0

type Session struct {
	UserID     uint   `json:"user_id" gorm:"index"`
	DeviceKey  string `json:"device_key" gorm:"primaryKey;size:64"`
	UserAgent  string `json:"user_agent" gorm:"size:255"`
	IP         string `json:"ip" gorm:"size:64"`
	LastActive int64  `json:"last_active"`
	Status     int    `json:"status"`
}

Session represents a device session of a user.

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
	PreDefault 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 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 added in v3.7.1

func (s *Storage) SetStorage(storage Storage)

type TaskItem added in v3.37.0

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 added in v3.42.0

type UpdateProgress func(percentage float64)

func UpdateProgressWithRange added in v3.48.0

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

Reference implementation from OpenListTeam: https://github.com/OpenListTeam/OpenList/blob/a703b736c9346c483bae56905a39bc07bf781cff/internal/model/obj.go#L58

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        Roles  `json:"role" gorm:"type:text"`                     // user's roles
	RolesDetail []Role `json:"-" gorm:"-"`
	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: check path limit
	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 added in v3.29.0

func (u *User) CanAddOfflineDownloadTasks() bool

func (*User) CanCopy

func (u *User) CanCopy() bool

func (*User) CanDecompress added in v3.42.0

func (u *User) CanDecompress() bool

func (*User) CanFTPAccess added in v3.41.0

func (u *User) CanFTPAccess() bool

func (*User) CanFTPManage added in v3.41.0

func (u *User) CanFTPManage() bool

func (*User) CanMove

func (u *User) CanMove() bool

func (*User) CanReadArchives added in v3.42.0

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

func (u *User) CanWebdavManage() bool

func (*User) CanWebdavRead

func (u *User) CanWebdavRead() bool

func (*User) CanWrite

func (u *User) CanWrite() bool

func (*User) CheckPathLimit added in v3.46.0

func (u *User) CheckPathLimit() bool

func (*User) IsAdmin

func (u *User) IsAdmin() bool

func (*User) IsGuest

func (u *User) IsGuest() bool

func (*User) JoinPath added in v3.6.0

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

func (*User) SetPassword added in v3.25.0

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

func (*User) ValidatePwdStaticHash added in v3.25.0

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

func (*User) ValidateRawPassword added in v3.25.0

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

func (*User) WebAuthnCredentials added in v3.26.0

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

func (*User) WebAuthnDisplayName added in v3.26.0

func (u *User) WebAuthnDisplayName() string

func (*User) WebAuthnID added in v3.26.0

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

func (*User) WebAuthnIcon added in v3.26.0

func (u *User) WebAuthnIcon() string

func (*User) WebAuthnName added in v3.26.0

func (u *User) WebAuthnName() string

Jump to

Keyboard shortcuts

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