model

package
v0.6.9 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPermission = errors.New("no permission")

Functions

func FormatAlistPath added in v0.6.0

func FormatAlistPath(serverID, filePath string) string

func FormatEmbyPath added in v0.6.0

func FormatEmbyPath(serverID, filePath string) string

func GenAlistServerID added in v0.3.2

func GenAlistServerID(a *AlistVendor)

func GetAlistServerIdFromPath added in v0.3.2

func GetAlistServerIdFromPath(path string) (serverID string, filePath string, err error)

func GetEmbyServerIdFromPath added in v0.3.2

func GetEmbyServerIdFromPath(path string) (serverID string, filePath string, err error)

Types

type AlistStreamingInfo added in v0.3.1

type AlistStreamingInfo struct {
	// {/}serverId/Path
	Path     string `gorm:"type:varchar(4096)" json:"path,omitempty"`
	Password string `gorm:"type:varchar(256)" json:"password,omitempty"`
}

func (*AlistStreamingInfo) AfterFind added in v0.3.1

func (a *AlistStreamingInfo) AfterFind(tx *gorm.DB) error

func (*AlistStreamingInfo) AfterSave added in v0.3.1

func (a *AlistStreamingInfo) AfterSave(tx *gorm.DB) error

func (*AlistStreamingInfo) BeforeSave added in v0.3.1

func (a *AlistStreamingInfo) BeforeSave(tx *gorm.DB) error

func (*AlistStreamingInfo) FilePath added in v0.6.0

func (a *AlistStreamingInfo) FilePath() (string, error)

func (*AlistStreamingInfo) ServerID added in v0.6.0

func (a *AlistStreamingInfo) ServerID() (string, error)

func (*AlistStreamingInfo) ServerIDAndFilePath added in v0.6.0

func (a *AlistStreamingInfo) ServerIDAndFilePath() (serverID, filePath string, err error)

func (*AlistStreamingInfo) SetServerIDAndFilePath added in v0.6.0

func (a *AlistStreamingInfo) SetServerIDAndFilePath(serverID, filePath string)

func (*AlistStreamingInfo) Validate added in v0.3.2

func (a *AlistStreamingInfo) Validate() error

type AlistVendor added in v0.3.1

type AlistVendor struct {
	CreatedAt      time.Time
	UpdatedAt      time.Time
	UserID         string `gorm:"primaryKey;type:char(32)"`
	Backend        string `gorm:"type:varchar(64)"`
	ServerID       string `gorm:"primaryKey;type:char(32)"`
	Host           string `gorm:"not null;type:varchar(256)"`
	Username       string `gorm:"type:varchar(256)"`
	HashedPassword []byte
}

func (*AlistVendor) AfterFind added in v0.3.1

func (a *AlistVendor) AfterFind(tx *gorm.DB) error

func (*AlistVendor) AfterSave added in v0.3.1

func (a *AlistVendor) AfterSave(tx *gorm.DB) error

func (*AlistVendor) BeforeSave added in v0.3.1

func (a *AlistVendor) BeforeSave(tx *gorm.DB) error

type Backend added in v0.3.1

type Backend struct {
	Endpoint  string `gorm:"primaryKey;type:varchar(512)" json:"endpoint"`
	Comment   string `gorm:"type:text" json:"comment"`
	Tls       bool   `gorm:"default:false" json:"tls"`
	JwtSecret string `gorm:"type:varchar(256)" json:"jwtSecret"`
	CustomCA  string `gorm:"type:text" json:"customCA"`
	TimeOut   string `gorm:"default:10s" json:"timeOut"`

	Consul Consul `gorm:"embedded;embeddedPrefix:consul_" json:"consul"`
	Etcd   Etcd   `gorm:"embedded;embeddedPrefix:etcd_" json:"etcd"`
}

func (*Backend) Validate added in v0.3.1

func (b *Backend) Validate() error

type BackendUsedBy added in v0.3.1

type BackendUsedBy struct {
	Enabled             bool   `gorm:"default:false" json:"enabled"`
	Bilibili            bool   `gorm:"default:false" json:"bilibili"`
	BilibiliBackendName string `gorm:"type:varchar(64)" json:"bilibiliBackendName"`
	Alist               bool   `gorm:"default:false" json:"alist"`
	AlistBackendName    string `gorm:"type:varchar(64)" json:"alistBackendName"`
	Emby                bool   `gorm:"default:false" json:"emby"`
	EmbyBackendName     string `gorm:"type:varchar(64)" json:"embyBackendName"`
}

type BilibiliStreamingInfo added in v0.3.1

type BilibiliStreamingInfo struct {
	Bvid    string `json:"bvid,omitempty"`
	Cid     uint64 `json:"cid,omitempty"`
	Epid    uint64 `json:"epid,omitempty"`
	Quality uint64 `json:"quality,omitempty"`
	Shared  bool   `json:"shared,omitempty"`
}

func (*BilibiliStreamingInfo) Validate added in v0.3.1

func (b *BilibiliStreamingInfo) Validate() error

type BilibiliVendor added in v0.3.1

type BilibiliVendor struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	UserID    string            `gorm:"primaryKey;type:char(32)"`
	Backend   string            `gorm:"type:varchar(64)"`
	Cookies   map[string]string `gorm:"not null;serializer:fastjson;type:text"`
}

func (*BilibiliVendor) AfterFind added in v0.3.1

func (b *BilibiliVendor) AfterFind(tx *gorm.DB) error

func (*BilibiliVendor) AfterSave added in v0.3.1

func (b *BilibiliVendor) AfterSave(tx *gorm.DB) error

func (*BilibiliVendor) BeforeSave added in v0.3.1

func (b *BilibiliVendor) BeforeSave(tx *gorm.DB) error

type Consul added in v0.3.1

type Consul struct {
	ServiceName string `gorm:"type:varchar(64)" json:"serviceName"`
	Token       string `gorm:"type:varchar(256)" json:"token"`
	PathPrefix  string `gorm:"type:varchar(64)" json:"pathPrefix"`
	Namespace   string `gorm:"type:varchar(64)" json:"namespace"`
	Partition   string `gorm:"type:varchar(64)" json:"partition"`
}

type EmbyStreamingInfo added in v0.3.1

type EmbyStreamingInfo struct {
	// {/}serverId/ItemId
	Path      string `gorm:"type:varchar(52)" json:"path,omitempty"`
	Transcode bool   `json:"transcode,omitempty"`
}

func (*EmbyStreamingInfo) FilePath added in v0.6.0

func (e *EmbyStreamingInfo) FilePath() (string, error)

func (*EmbyStreamingInfo) ServerID added in v0.6.0

func (e *EmbyStreamingInfo) ServerID() (string, error)

func (*EmbyStreamingInfo) ServerIDAndFilePath added in v0.6.0

func (e *EmbyStreamingInfo) ServerIDAndFilePath() (serverID, filePath string, err error)

func (*EmbyStreamingInfo) SetServerIDAndFilePath added in v0.6.0

func (e *EmbyStreamingInfo) SetServerIDAndFilePath(serverID, filePath string)

func (*EmbyStreamingInfo) Validate added in v0.3.2

func (e *EmbyStreamingInfo) Validate() error

type EmbyVendor added in v0.3.1

type EmbyVendor struct {
	CreatedAt  time.Time
	UpdatedAt  time.Time
	UserID     string `gorm:"primaryKey;type:char(32)"`
	Backend    string `gorm:"type:varchar(64)"`
	ServerID   string `gorm:"primaryKey;type:char(32)"`
	Host       string `gorm:"not null;type:varchar(256)"`
	ApiKey     string `gorm:"not null;type:varchar(256)"`
	EmbyUserID string `gorm:"type:varchar(32)"`
}

func (*EmbyVendor) AfterFind added in v0.3.1

func (e *EmbyVendor) AfterFind(tx *gorm.DB) error

func (*EmbyVendor) AfterSave added in v0.3.1

func (e *EmbyVendor) AfterSave(tx *gorm.DB) error

func (*EmbyVendor) BeforeSave added in v0.3.1

func (e *EmbyVendor) BeforeSave(tx *gorm.DB) error

type EmptyNullString added in v0.6.0

type EmptyNullString string

func (*EmptyNullString) Scan added in v0.6.0

func (ns *EmptyNullString) Scan(value any) error

Scan implements the [Scanner] interface.

func (EmptyNullString) String added in v0.6.0

func (ns EmptyNullString) String() string

func (EmptyNullString) Value added in v0.6.0

func (ns EmptyNullString) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Etcd added in v0.3.1

type Etcd struct {
	ServiceName string `gorm:"type:varchar(64)" json:"serviceName"`
	Username    string `gorm:"type:varchar(64)" json:"username"`
	Password    string `gorm:"type:varchar(256)" json:"password"`
}

type MoreSource added in v0.6.0

type MoreSource struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Url  string `json:"url"`
}

type Movie

type Movie struct {
	ID        string    `gorm:"primaryKey;type:char(32)" json:"id"`
	CreatedAt time.Time `json:"-"`
	UpdatedAt time.Time `json:"-"`
	Position  uint      `gorm:"not null" json:"-"`
	RoomID    string    `gorm:"not null;index;type:char(32)" json:"-"`
	CreatorID string    `gorm:"index;type:char(32)" json:"creatorId"`
	MovieBase `gorm:"embedded;embeddedPrefix:base_" json:"base"`
	Children  []*Movie `gorm:"foreignKey:ParentID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"`
}

func (*Movie) BeforeCreate

func (m *Movie) BeforeCreate(tx *gorm.DB) error

func (*Movie) BeforeSave added in v0.6.0

func (m *Movie) BeforeSave(tx *gorm.DB) (err error)

func (*Movie) Clone added in v0.6.0

func (m *Movie) Clone() *Movie

type MovieBase added in v0.6.0

type MovieBase struct {
	Url         string               `gorm:"type:varchar(8192)" json:"url"`
	MoreSources []*MoreSource        `gorm:"serializer:fastjson;type:text" json:"moreSources,omitempty"`
	Name        string               `gorm:"not null;type:varchar(256)" json:"name"`
	Live        bool                 `json:"live"`
	Proxy       bool                 `json:"proxy"`
	RtmpSource  bool                 `json:"rtmpSource"`
	Type        string               `json:"type"`
	Headers     map[string]string    `gorm:"serializer:fastjson;type:text" json:"headers,omitempty"`
	Subtitles   map[string]*Subtitle `gorm:"serializer:fastjson;type:text" json:"subtitles,omitempty"`
	VendorInfo  VendorInfo           `gorm:"embedded;embeddedPrefix:vendor_info_" json:"vendorInfo,omitempty"`
	IsFolder    bool                 `json:"isFolder"`
	ParentID    EmptyNullString      `gorm:"type:char(32)" json:"parentId"`
}

func (*MovieBase) Clone added in v0.6.0

func (m *MovieBase) Clone() *MovieBase

func (*MovieBase) IsDynamicFolder added in v0.6.0

func (m *MovieBase) IsDynamicFolder() bool

type Role

type Role uint8
const (
	RoleBanned  Role = 1
	RolePending Role = 2
	RoleUser    Role = 3
	RoleAdmin   Role = 4
	RoleRoot    Role = 5
)

func (Role) String

func (r Role) String() string

type Room

type Room struct {
	ID                 string `gorm:"primaryKey;type:char(32)" json:"id"`
	CreatedAt          time.Time
	UpdatedAt          time.Time
	Status             RoomStatus    `gorm:"not null;default:2"`
	Name               string        `gorm:"not null;uniqueIndex;type:varchar(32)"`
	Settings           *RoomSettings `gorm:"foreignKey:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"settings"`
	CreatorID          string        `gorm:"index;type:char(32)"`
	HashedPassword     []byte
	GroupUserRelations []*RoomMember `gorm:"foreignKey:RoomID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	Movies             []*Movie      `gorm:"foreignKey:RoomID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
}

func (*Room) BeforeCreate

func (r *Room) BeforeCreate(tx *gorm.DB) error

func (*Room) CheckPassword

func (r *Room) CheckPassword(password string) bool

func (*Room) IsActive

func (r *Room) IsActive() bool

func (*Room) IsBanned

func (r *Room) IsBanned() bool

func (*Room) IsPending

func (r *Room) IsPending() bool

func (*Room) NeedPassword

func (r *Room) NeedPassword() bool

type RoomAdminPermission added in v0.5.0

type RoomAdminPermission uint32
const (
	PermissionApprovePendingMember RoomAdminPermission = 1 << iota
	PermissionBanRoomMember
	PermissionSetUserPermission
	PermissionSetRoomSettings
	PermissionSetRoomPassword
	PermissionDeleteRoom

	AllAdminPermissions     RoomAdminPermission = math.MaxUint32
	NoAdminPermission       RoomAdminPermission = 0
	DefaultAdminPermissions RoomAdminPermission = PermissionApprovePendingMember |
		PermissionBanRoomMember |
		PermissionSetUserPermission |
		PermissionSetRoomSettings |
		PermissionSetRoomPassword
)

func (RoomAdminPermission) Add added in v0.5.0

func (RoomAdminPermission) Has added in v0.5.0

func (p RoomAdminPermission) Has(permission RoomAdminPermission) bool

func (RoomAdminPermission) Remove added in v0.5.0

type RoomMember added in v0.5.0

type RoomMember struct {
	CreatedAt        time.Time
	UpdatedAt        time.Time
	UserID           string           `gorm:"primarykey;type:char(32)"`
	RoomID           string           `gorm:"primarykey;type:char(32)"`
	Status           RoomMemberStatus `gorm:"not null;default:2"`
	Role             RoomMemberRole   `gorm:"not null;default:1"`
	Permissions      RoomMemberPermission
	AdminPermissions RoomAdminPermission
}

func (*RoomMember) HasAdminPermission added in v0.5.0

func (r *RoomMember) HasAdminPermission(permission RoomAdminPermission) bool

func (*RoomMember) HasPermission added in v0.5.0

func (r *RoomMember) HasPermission(permission RoomMemberPermission) bool

type RoomMemberPermission added in v0.5.0

type RoomMemberPermission uint32
const (
	PermissionGetMovieList RoomMemberPermission = 1 << iota
	PermissionAddMovie
	PermissionDeleteMovie
	PermissionEditMovie
	PermissionSetCurrentMovie
	PermissionSetCurrentStatus
	PermissionSendChatMessage

	AllPermissions     RoomMemberPermission = math.MaxUint32
	NoPermission       RoomMemberPermission = 0
	DefaultPermissions RoomMemberPermission = PermissionGetMovieList | PermissionSendChatMessage
)

func (RoomMemberPermission) Add added in v0.5.0

func (RoomMemberPermission) Has added in v0.5.0

func (RoomMemberPermission) Remove added in v0.5.0

type RoomMemberRole added in v0.5.0

type RoomMemberRole uint8
const (
	RoomMemberRoleUnknown RoomMemberRole = iota
	RoomMemberRoleMember
	RoomMemberRoleAdmin
	RoomMemberRoleCreator
)

func (RoomMemberRole) IsAdmin added in v0.5.0

func (r RoomMemberRole) IsAdmin() bool

func (RoomMemberRole) IsCreator added in v0.5.0

func (r RoomMemberRole) IsCreator() bool

func (RoomMemberRole) IsMember added in v0.5.0

func (r RoomMemberRole) IsMember() bool

func (RoomMemberRole) String added in v0.5.0

func (r RoomMemberRole) String() string

type RoomMemberStatus added in v0.5.0

type RoomMemberStatus uint8
const (
	RoomMemberStatusUnknown RoomMemberStatus = iota
	RoomMemberStatusBanned
	RoomMemberStatusPending
	RoomMemberStatusActive
)

func (RoomMemberStatus) IsActive added in v0.5.0

func (r RoomMemberStatus) IsActive() bool

func (RoomMemberStatus) IsBanned added in v0.5.0

func (r RoomMemberStatus) IsBanned() bool

func (RoomMemberStatus) IsNotActive added in v0.5.0

func (r RoomMemberStatus) IsNotActive() bool

func (RoomMemberStatus) IsPending added in v0.5.0

func (r RoomMemberStatus) IsPending() bool

func (RoomMemberStatus) String added in v0.5.0

func (r RoomMemberStatus) String() string

type RoomSettings

type RoomSettings struct {
	ID                     string               `gorm:"primaryKey;type:char(32)" json:"-"`
	UpdatedAt              time.Time            `gorm:"autoUpdateTime" json:"-"`
	Hidden                 bool                 `gorm:"default:false" json:"hidden"`
	DisableJoinNewUser     bool                 `gorm:"default:false" json:"disable_join_new_user"`
	JoinNeedReview         bool                 `gorm:"default:false" json:"join_need_review"`
	UserDefaultPermissions RoomMemberPermission `json:"user_default_permissions"`
	DisableGuest           bool                 `gorm:"default:false" json:"disable_guest"`
	GuestPermissions       RoomMemberPermission `json:"guest_permissions"`

	CanGetMovieList     bool `gorm:"default:true" json:"can_get_movie_list"`
	CanAddMovie         bool `gorm:"default:true" json:"can_add_movie"`
	CanDeleteMovie      bool `gorm:"default:true" json:"can_delete_movie"`
	CanEditMovie        bool `gorm:"default:true" json:"can_edit_movie"`
	CanSetCurrentMovie  bool `gorm:"default:true" json:"can_set_current_movie"`
	CanSetCurrentStatus bool `gorm:"default:true" json:"can_set_current_status"`
	CanSendChatMessage  bool `gorm:"default:true" json:"can_send_chat_message"`
}

func DefaultRoomSettings added in v0.5.0

func DefaultRoomSettings() *RoomSettings

type RoomStatus

type RoomStatus uint8
const (
	RoomStatusBanned  RoomStatus = 1
	RoomStatusPending RoomStatus = 2
	RoomStatusActive  RoomStatus = 3
)

func (RoomStatus) String

func (r RoomStatus) String() string

type Setting

type Setting struct {
	Name      string `gorm:"primaryKey;type:varchar(256)"`
	UpdatedAt time.Time
	Value     string       `gorm:"not null;type:text"`
	Type      SettingType  `gorm:"not null;default:string"`
	Group     SettingGroup `gorm:"not null"`
}

type SettingGroup

type SettingGroup = string
const (
	SettingGroupRoom     SettingGroup = "room"
	SettingGroupUser     SettingGroup = "user"
	SettingGroupProxy    SettingGroup = "proxy"
	SettingGroupRtmp     SettingGroup = "rtmp"
	SettingGroupDatabase SettingGroup = "database"
	SettingGroupServer   SettingGroup = "server"
	SettingGroupOauth2   SettingGroup = "oauth2"
	SettingGroupEmail    SettingGroup = "email"
)

type SettingType

type SettingType string
const (
	SettingTypeBool    SettingType = "bool"
	SettingTypeInt64   SettingType = "int64"
	SettingTypeFloat64 SettingType = "float64"
	SettingTypeString  SettingType = "string"
)

type Subtitle added in v0.3.1

type Subtitle struct {
	URL  string `json:"url"`
	Type string `json:"type"`
}

type User

type User struct {
	ID                   string `gorm:"primaryKey;type:char(32)" json:"id"`
	CreatedAt            time.Time
	UpdatedAt            time.Time
	RegisteredByProvider bool            `gorm:"not null;default:false"`
	RegisteredByEmail    bool            `gorm:"not null;default:false"`
	UserProviders        []*UserProvider `gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	Username             string          `gorm:"not null;uniqueIndex;type:varchar(32)"`
	HashedPassword       []byte          `gorm:"not null"`
	Email                EmptyNullString `gorm:"type:varchar(128);uniqueIndex"`
	Role                 Role            `gorm:"not null;default:2"`
	RoomMembers          []*RoomMember   `gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	Rooms                []*Room         `gorm:"foreignKey:CreatorID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	Movies               []*Movie        `gorm:"foreignKey:CreatorID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL"`
	BilibiliVendor       *BilibiliVendor `gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	AlistVendor          []*AlistVendor  `gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	EmbyVendor           []*EmbyVendor   `gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
}

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) error

func (*User) CheckPassword

func (u *User) CheckPassword(password string) bool

func (*User) IsAdmin

func (u *User) IsAdmin() bool

func (*User) IsBanned

func (u *User) IsBanned() bool

func (*User) IsPending

func (u *User) IsPending() bool

func (*User) IsRoot

func (u *User) IsRoot() bool

func (*User) IsUser

func (u *User) IsUser() bool

type UserProvider

type UserProvider struct {
	Provider       provider.OAuth2Provider `gorm:"primarykey;type:varchar(32);uniqueIndex:idx_provider_user_id"`
	ProviderUserID string                  `gorm:"primarykey;type:varchar(64)"`
	CreatedAt      time.Time
	UpdatedAt      time.Time
	UserID         string `gorm:"not null;type:char(32);uniqueIndex:idx_provider_user_id"`
}

type VendorBackend added in v0.3.1

type VendorBackend struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	Backend   Backend       `gorm:"embedded;embeddedPrefix:backend_" json:"backend"`
	UsedBy    BackendUsedBy `gorm:"embedded;embeddedPrefix:used_by_" json:"usedBy"`
}

func (*VendorBackend) AfterFind added in v0.3.1

func (v *VendorBackend) AfterFind(tx *gorm.DB) error

func (*VendorBackend) AfterSave added in v0.3.1

func (v *VendorBackend) AfterSave(tx *gorm.DB) error

func (*VendorBackend) BeforeSave added in v0.3.1

func (v *VendorBackend) BeforeSave(tx *gorm.DB) error

type VendorInfo

type VendorInfo struct {
	Vendor   VendorName             `gorm:"type:varchar(32)" json:"vendor"`
	Backend  string                 `gorm:"type:varchar(64)" json:"backend"`
	Bilibili *BilibiliStreamingInfo `gorm:"embedded;embeddedPrefix:bilibili_" json:"bilibili,omitempty"`
	Alist    *AlistStreamingInfo    `gorm:"embedded;embeddedPrefix:alist_" json:"alist,omitempty"`
	Emby     *EmbyStreamingInfo     `gorm:"embedded;embeddedPrefix:emby_" json:"emby,omitempty"`
}

type VendorName added in v0.3.1

type VendorName = string
const (
	VendorBilibili VendorName = "bilibili"
	VendorAlist    VendorName = "alist"
	VendorEmby     VendorName = "emby"
)

Jump to

Keyboard shortcuts

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