diff --git a/internal/bootstrap/init.go b/internal/bootstrap/init.go index 558cc3c4..74dad02f 100644 --- a/internal/bootstrap/init.go +++ b/internal/bootstrap/init.go @@ -19,8 +19,8 @@ func WithTask(f ...BootstrapFunc) BootstrapConf { } type Bootstrap struct { - task []BootstrapFunc ctx context.Context + task []BootstrapFunc } func New(conf ...BootstrapConf) *Bootstrap { diff --git a/internal/cache/alist.go b/internal/cache/alist.go index 30e796b3..406d2dca 100644 --- a/internal/cache/alist.go +++ b/internal/cache/alist.go @@ -94,17 +94,17 @@ const ( ) type AlistSubtitle struct { + Cache *SubtitleDataCache Name string URL string Type string - Cache *SubtitleDataCache } type AlistMovieCacheData struct { + Ali *AlistAliCache URL string - Subtitles []*AlistSubtitle Provider string - Ali *AlistAliCache + Subtitles []*AlistSubtitle } type AlistAliCache struct { diff --git a/internal/cache/bilibili.go b/internal/cache/bilibili.go index ba6ea2e6..169189bd 100644 --- a/internal/cache/bilibili.go +++ b/internal/cache/bilibili.go @@ -28,9 +28,11 @@ type BilibiliMpdCache struct { Urls []string } -type BilibiliSubtitleCache map[string]*struct { - Url string +type BilibiliSubtitleCache map[string]*BilibiliSubtitleCacheItem + +type BilibiliSubtitleCacheItem struct { Srt *refreshcache0.RefreshCache[[]byte] + Url string } func NewBilibiliSharedMpdCacheInitFunc(movie *model.Movie) func(ctx context.Context, args *BilibiliUserCache) (*BilibiliMpdCache, error) { @@ -213,21 +215,21 @@ func BilibiliNoSharedMovieCacheInitFunc(ctx context.Context, movie *model.Movie, } type bilibiliSubtitleResp struct { - FontSize float64 `json:"font_size"` - FontColor string `json:"font_color"` - BackgroundAlpha float64 `json:"background_alpha"` - BackgroundColor string `json:"background_color"` - Stroke string `json:"Stroke"` - Type string `json:"type"` - Lang string `json:"lang"` - Version string `json:"version"` + FontColor string `json:"font_color"` + BackgroundColor string `json:"background_color"` + Stroke string `json:"Stroke"` + Type string `json:"type"` + Lang string `json:"lang"` + Version string `json:"version"` Body []struct { + Content string `json:"content"` From float64 `json:"from"` To float64 `json:"to"` Sid int `json:"sid"` Location int `json:"location"` - Content string `json:"content"` } `json:"body"` + FontSize float64 `json:"font_size"` + BackgroundAlpha float64 `json:"background_alpha"` } func NewBilibiliSubtitleCacheInitFunc(movie *model.Movie) func(ctx context.Context, args *BilibiliUserCache) (BilibiliSubtitleCache, error) { @@ -268,10 +270,7 @@ func BilibiliSubtitleCacheInitFunc(ctx context.Context, movie *model.Movie, args } subtitleCache := make(BilibiliSubtitleCache, len(resp.Subtitles)) for k, v := range resp.Subtitles { - subtitleCache[k] = &struct { - Url string - Srt *refreshcache0.RefreshCache[[]byte] - }{ + subtitleCache[k] = &BilibiliSubtitleCacheItem{ Url: v, Srt: refreshcache0.NewRefreshCache[[]byte](func(ctx context.Context) ([]byte, error) { return translateBilibiliSubtitleToSrt(ctx, v) @@ -379,8 +378,8 @@ func NewBilibiliMovieCache(movie *model.Movie) *BilibiliMovieCache { type BilibiliUserCache = refreshcache.RefreshCache[*BilibiliUserCacheData, struct{}] type BilibiliUserCacheData struct { - Cookies []*http.Cookie Backend string + Cookies []*http.Cookie } func NewBilibiliUserCache(userID string) *BilibiliUserCache { diff --git a/internal/cache/cache.go b/internal/cache/cache.go index 8cc70f7e..ebb661fe 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -12,10 +12,10 @@ import ( type MapRefreshFunc[T any, A any] func(ctx context.Context, key string, args ...A) (T, error) type MapCache[T any, A any] struct { - lock sync.RWMutex cache map[string]*refreshcache.RefreshCache[T, A] refreshFunc MapRefreshFunc[T, A] maxAge time.Duration + lock sync.RWMutex } func newMapCache[T any, A any](refreshFunc MapRefreshFunc[T, A], maxAge time.Duration) *MapCache[T, A] { diff --git a/internal/cache/cache0.go b/internal/cache/cache0.go index 55650b53..8b4a659b 100644 --- a/internal/cache/cache0.go +++ b/internal/cache/cache0.go @@ -12,10 +12,10 @@ import ( type MapRefreshFunc0[T any] func(ctx context.Context, key string) (T, error) type MapCache0[T any] struct { - lock sync.RWMutex cache map[string]*refreshcache0.RefreshCache[T] refreshFunc MapRefreshFunc0[T] maxAge time.Duration + lock sync.RWMutex } func newMapCache0[T any](refreshFunc MapRefreshFunc0[T], maxAge time.Duration) *MapCache0[T] { diff --git a/internal/cache/emby.go b/internal/cache/emby.go index 2837771e..ae31e047 100644 --- a/internal/cache/emby.go +++ b/internal/cache/emby.go @@ -58,19 +58,21 @@ func EmbyAuthorizationCacheWithUserIDInitFunc(userID, serverID string) (*EmbyUse type EmbySource struct { URL string - IsTranscode bool Name string - Subtitles []struct { - URL string - Type string - Name string - Cache *refreshcache0.RefreshCache[[]byte] - } + Subtitles []*EmbySubtitleCache + IsTranscode bool +} + +type EmbySubtitleCache struct { + Cache *refreshcache0.RefreshCache[[]byte] + URL string + Type string + Name string } type EmbyMovieCacheData struct { - Sources []EmbySource TranscodeSessionID string + Sources []EmbySource } type EmbyMovieCache = refreshcache1.RefreshCache[*EmbyMovieCacheData, *EmbyUserCache] @@ -211,12 +213,7 @@ func NewEmbyMovieCacheInitFunc(movie *model.Movie, subPath string) func(ctx cont name = msi.DisplayLanguage } } - resp.Sources[i].Subtitles = append(resp.Sources[i].Subtitles, struct { - URL string - Type string - Name string - Cache *refreshcache0.RefreshCache[[]byte] - }{ + resp.Sources[i].Subtitles = append(resp.Sources[i].Subtitles, &EmbySubtitleCache{ URL: url, Type: subtutleType, Name: name, diff --git a/internal/db/update.go b/internal/db/update.go index f1115d53..ea8101c6 100644 --- a/internal/db/update.go +++ b/internal/db/update.go @@ -11,8 +11,8 @@ import ( ) type dbVersion struct { - NextVersion string Upgrade func(*gorm.DB) error + NextVersion string } const CurrentVersion = "0.0.10" diff --git a/internal/model/member.go b/internal/model/member.go index 2fb2a5a3..73d11e77 100644 --- a/internal/model/member.go +++ b/internal/model/member.go @@ -140,13 +140,13 @@ func (p RoomAdminPermission) Remove(permission RoomAdminPermission) RoomAdminPer type RoomMember struct { CreatedAt time.Time UpdatedAt time.Time - UserID string `gorm:"primarykey;type:char(32)"` - RoomID string `gorm:"primarykey;type:char(32)"` - Room *Room `gorm:"foreignKey:RoomID;references:ID"` - Status RoomMemberStatus `gorm:"not null;default:2"` - Role RoomMemberRole `gorm:"not null;default:1"` + Room *Room `gorm:"foreignKey:RoomID;references:ID"` + UserID string `gorm:"primarykey;type:char(32)"` + RoomID string `gorm:"primarykey;type:char(32)"` Permissions RoomMemberPermission AdminPermissions RoomAdminPermission + Status RoomMemberStatus `gorm:"not null;default:2"` + Role RoomMemberRole `gorm:"not null;default:1"` } var ErrNoPermission = errors.New("no permission") diff --git a/internal/model/movie.go b/internal/model/movie.go index f77491f0..cfcca7ac 100644 --- a/internal/model/movie.go +++ b/internal/model/movie.go @@ -14,11 +14,11 @@ 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"` + Childrens []*Movie `gorm:"foreignKey:ParentID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"` MovieBase `gorm:"embedded;embeddedPrefix:base_" json:"base"` - Childrens []*Movie `gorm:"foreignKey:ParentID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"` + Position uint `gorm:"not null" json:"-"` } func (m *Movie) Clone() *Movie { @@ -65,18 +65,18 @@ type MoreSource struct { } type MovieBase struct { + VendorInfo VendorInfo `gorm:"embedded;embeddedPrefix:vendor_info_" json:"vendorInfo,omitempty"` + Headers map[string]string `gorm:"serializer:fastjson;type:text" json:"headers,omitempty"` + Subtitles map[string]*Subtitle `gorm:"serializer:fastjson;type:text" json:"subtitles,omitempty"` 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"` + Type string `json:"type"` + ParentID EmptyNullString `gorm:"type:char(32)" json:"parentId"` + MoreSources []*MoreSource `gorm:"serializer:fastjson;type:text" json:"moreSources,omitempty"` 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 (m *MovieBase) IsM3u8() bool { @@ -168,11 +168,11 @@ const ( ) 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"` + Vendor VendorName `gorm:"type:varchar(32)" json:"vendor"` + Backend string `gorm:"type:varchar(64)" json:"backend"` } type BilibiliStreamingInfo struct { diff --git a/internal/model/room.go b/internal/model/room.go index c0588eb3..ec6835f6 100644 --- a/internal/model/room.go +++ b/internal/model/room.go @@ -34,13 +34,13 @@ 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"` + Name string `gorm:"not null;uniqueIndex;type:varchar(32)"` CreatorID string `gorm:"index;type:char(32)"` HashedPassword []byte RoomMembers []*RoomMember `gorm:"foreignKey:RoomID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` Movies []*Movie `gorm:"foreignKey:RoomID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` + Status RoomStatus `gorm:"not null;default:2"` } func (r *Room) BeforeCreate(tx *gorm.DB) error { @@ -71,22 +71,21 @@ func (r *Room) IsActive() bool { } 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"` + ID string `gorm:"primaryKey;type:char(32)" json:"-"` 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"` + DisableGuest bool `gorm:"default:false" json:"disable_guest"` + JoinNeedReview bool `gorm:"default:false" json:"join_need_review"` + DisableJoinNewUser bool `gorm:"default:false" json:"disable_join_new_user"` + Hidden bool `gorm:"default:false" json:"hidden"` + 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() *RoomSettings { diff --git a/internal/model/user.go b/internal/model/user.go index d885b181..d7038079 100644 --- a/internal/model/user.go +++ b/internal/model/user.go @@ -39,23 +39,22 @@ func (r Role) String() string { } 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"` - + ID string `gorm:"primaryKey;type:char(32)" json:"id"` + CreatedAt time.Time + UpdatedAt time.Time + Username string `gorm:"not null;uniqueIndex;type:varchar(32)"` + Email EmptyNullString `gorm:"type:varchar(128);uniqueIndex"` + HashedPassword []byte `gorm:"not null"` + BilibiliVendor *BilibiliVendor `gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` + Movies []*Movie `gorm:"foreignKey:CreatorID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL"` + UserProviders []*UserProvider `gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` + RoomMembers []*RoomMember `gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` + Rooms []*Room `gorm:"foreignKey:CreatorID;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"` + Role Role `gorm:"not null;default:2"` + RegisteredByProvider bool `gorm:"not null;default:false"` + RegisteredByEmail bool `gorm:"not null;default:false"` autoAddUsernameSuffix bool } diff --git a/internal/model/vendorBackend.go b/internal/model/vendorBackend.go index 4772cfa6..1945d483 100644 --- a/internal/model/vendorBackend.go +++ b/internal/model/vendorBackend.go @@ -23,15 +23,14 @@ type Etcd struct { } type Backend struct { + Consul Consul `gorm:"embedded;embeddedPrefix:consul_" json:"consul"` + Etcd Etcd `gorm:"embedded;embeddedPrefix:etcd_" json:"etcd"` 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"` + Tls bool `gorm:"default:false" json:"tls"` } func (b *Backend) Validate() error { @@ -52,18 +51,18 @@ func (b *Backend) Validate() error { 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"` + Backend Backend `gorm:"embedded;embeddedPrefix:backend_" json:"backend"` } type BackendUsedBy struct { + BilibiliBackendName string `gorm:"type:varchar(64)" json:"bilibiliBackendName"` + AlistBackendName string `gorm:"type:varchar(64)" json:"alistBackendName"` + EmbyBackendName string `gorm:"type:varchar(64)" json:"embyBackendName"` 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"` } func (v *VendorBackend) BeforeSave(tx *gorm.DB) error { diff --git a/internal/model/vendorRecord.go b/internal/model/vendorRecord.go index 41d51d1f..47d18edd 100644 --- a/internal/model/vendorRecord.go +++ b/internal/model/vendorRecord.go @@ -11,9 +11,9 @@ import ( type BilibiliVendor struct { CreatedAt time.Time UpdatedAt time.Time + Cookies map[string]string `gorm:"not null;serializer:fastjson;type:text"` 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 (b *BilibiliVendor) BeforeSave(tx *gorm.DB) error { diff --git a/internal/op/client.go b/internal/op/client.go index e920f2ca..91f65274 100644 --- a/internal/op/client.go +++ b/internal/op/client.go @@ -16,8 +16,8 @@ type Client struct { r *Room h *Hub c chan Message - wg sync.WaitGroup conn *websocket.Conn + wg sync.WaitGroup timeOut time.Duration closed uint32 } diff --git a/internal/op/current.go b/internal/op/current.go index 9c26f129..da58d865 100644 --- a/internal/op/current.go +++ b/internal/op/current.go @@ -29,10 +29,10 @@ func newCurrent() *current { } type Status struct { + lastUpdate time.Time `json:"-"` CurrentTime float64 `json:"currentTime"` PlaybackRate float64 `json:"playbackRate"` IsPlaying bool `json:"isPlaying"` - lastUpdate time.Time `json:"-"` } func newStatus() Status { diff --git a/internal/op/hub.go b/internal/op/hub.go index b18c6782..9de4539d 100644 --- a/internal/op/hub.go +++ b/internal/op/hub.go @@ -15,19 +15,18 @@ import ( ) type clients struct { - lock sync.RWMutex m map[*Client]struct{} + lock sync.RWMutex } type Hub struct { - id string - clients rwmap.RWMap[string, *clients] broadcast chan *broadcastMessage exit chan struct{} - closed uint32 + clients rwmap.RWMap[string, *clients] + id string wg sync.WaitGroup - - once utils.Once + once utils.Once + closed uint32 } type broadcastMessage struct { diff --git a/internal/op/room.go b/internal/op/room.go index ad88b254..35b6c7e9 100644 --- a/internal/op/room.go +++ b/internal/op/room.go @@ -17,11 +17,11 @@ import ( ) type Room struct { - model.Room current *current hub atomic.Pointer[Hub] movies *movies members rwmap.RWMap[string, *model.RoomMember] + model.Room } func (r *Room) lazyInitHub() *Hub { diff --git a/internal/op/user.go b/internal/op/user.go index 4682638d..e7b50f03 100644 --- a/internal/op/user.go +++ b/internal/op/user.go @@ -17,11 +17,11 @@ import ( ) type User struct { - model.User - version uint32 alistCache atomic.Pointer[cache.AlistUserCache] bilibiliCache atomic.Pointer[cache.BilibiliUserCache] embyCache atomic.Pointer[cache.EmbyUserCache] + model.User + version uint32 } func (u *User) AlistCache() *cache.AlistUserCache { diff --git a/internal/provider/aggregations/rainbow.go b/internal/provider/aggregations/rainbow.go index 5f777511..2c51baae 100644 --- a/internal/provider/aggregations/rainbow.go +++ b/internal/provider/aggregations/rainbow.go @@ -102,11 +102,11 @@ func (p *rainbowGenericProvider) NewAuthURL(ctx context.Context, state string) ( } type rainbowNewAuthURLResp struct { - Code int `json:"code"` - ErrCode int `json:"errcode"` Msg string `json:"msg"` Type string `json:"type"` URL string `json:"url"` + Code int `json:"code"` + ErrCode int `json:"errcode"` } func (p *rainbowGenericProvider) GetUserInfo(ctx context.Context, code string) (*provider.UserInfo, error) { @@ -150,12 +150,12 @@ func (p *rainbowGenericProvider) GetUserInfo(ctx context.Context, code string) ( } type rainbowUserInfo struct { - Code int `json:"code"` - ErrCode int `json:"errcode"` Msg string `json:"msg"` Type string `json:"type"` SocialUID string `json:"social_uid"` Nickname string `json:"nickname"` + Code int `json:"code"` + ErrCode int `json:"errcode"` } func (r *Rainbow) ExtractProvider(p provider.OAuth2Provider) (provider.ProviderInterface, error) { diff --git a/internal/provider/providers/discord.go b/internal/provider/providers/discord.go index 8f4e1722..2270809b 100644 --- a/internal/provider/providers/discord.go +++ b/internal/provider/providers/discord.go @@ -2,7 +2,6 @@ package providers import ( "context" - "fmt" "net/http" json "github.com/json-iterator/go" @@ -54,7 +53,7 @@ func (p *DiscordProvider) GetUserInfo(ctx context.Context, code string) (*provid return nil, err } client := p.config.Client(ctx, tk) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("https://discord.com/api/v10/oauth2/@me"), nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://discord.com/api/v10/oauth2/@me", nil) if err != nil { return nil, err } diff --git a/internal/provider/providers/gitee.go b/internal/provider/providers/gitee.go index 1ef84104..36f2a870 100644 --- a/internal/provider/providers/gitee.go +++ b/internal/provider/providers/gitee.go @@ -75,8 +75,8 @@ func (p *GiteeProvider) GetUserInfo(ctx context.Context, code string) (*provider } type giteeUserInfo struct { - ID uint64 `json:"id"` Login string `json:"login"` + ID uint64 `json:"id"` } func init() { diff --git a/internal/provider/providers/qq.go b/internal/provider/providers/qq.go index 7dde0bbc..0fd1a8cf 100644 --- a/internal/provider/providers/qq.go +++ b/internal/provider/providers/qq.go @@ -128,7 +128,6 @@ type qqProviderMe struct { } type qqUserInfo struct { - Ret int `json:"ret"` Msg string `json:"msg"` Nickname string `json:"nickname"` Figureurl string `json:"figureurl"` @@ -137,6 +136,7 @@ type qqUserInfo struct { FigureurlQq1 string `json:"figureurl_qq_1"` FigureurlQq2 string `json:"figureurl_qq_2"` Gender string `json:"gender"` + Ret int `json:"ret"` } func init() { diff --git a/internal/settings/bool.go b/internal/settings/bool.go index cc35c3f6..82919484 100644 --- a/internal/settings/bool.go +++ b/internal/settings/bool.go @@ -23,11 +23,13 @@ type BoolSetting interface { var _ BoolSetting = (*Bool)(nil) type Bool struct { - value uint32 + beforeInit func(BoolSetting, bool) (bool, error) + beforeSet func(BoolSetting, bool) (bool, error) + afterInit func(BoolSetting, bool) + afterSet func(BoolSetting, bool) setting - defaultValue bool - beforeInit, beforeSet func(BoolSetting, bool) (bool, error) - afterInit, afterSet func(BoolSetting, bool) + value uint32 + defaultValue bool } type BoolSettingOption func(*Bool) diff --git a/internal/settings/floate64.go b/internal/settings/floate64.go index b6389f34..33bea923 100644 --- a/internal/settings/floate64.go +++ b/internal/settings/floate64.go @@ -24,12 +24,14 @@ type Float64Setting interface { var _ Float64Setting = (*Float64)(nil) type Float64 struct { - value uint64 + validator func(float64) error + beforeInit func(Float64Setting, float64) (float64, error) + beforeSet func(Float64Setting, float64) (float64, error) + afterInit func(Float64Setting, float64) + afterSet func(Float64Setting, float64) setting - defaultValue float64 - validator func(float64) error - beforeInit, beforeSet func(Float64Setting, float64) (float64, error) - afterInit, afterSet func(Float64Setting, float64) + value uint64 + defaultValue float64 } type Float64SettingOption func(*Float64) diff --git a/internal/settings/int64.go b/internal/settings/int64.go index c6b5f49f..91e5f0cd 100644 --- a/internal/settings/int64.go +++ b/internal/settings/int64.go @@ -23,12 +23,14 @@ type Int64Setting interface { var _ Int64Setting = (*Int64)(nil) type Int64 struct { - value int64 + validator func(int64) error + beforeInit func(Int64Setting, int64) (int64, error) + beforeSet func(Int64Setting, int64) (int64, error) + afterInit func(Int64Setting, int64) + afterSet func(Int64Setting, int64) setting - defaultValue int64 - validator func(int64) error - beforeInit, beforeSet func(Int64Setting, int64) (int64, error) - afterInit, afterSet func(Int64Setting, int64) + value int64 + defaultValue int64 } type Int64SettingOption func(*Int64) diff --git a/internal/settings/setting.go b/internal/settings/setting.go index b338b70a..9630f172 100644 --- a/internal/settings/setting.go +++ b/internal/settings/setting.go @@ -14,8 +14,8 @@ var ErrSettingAlreadyInited = errors.New("setting already inited") var _ heap.Interface[maxHeapItem] = (*maxHeap)(nil) type maxHeapItem struct { - priority int Setting + priority int } type maxHeap struct { diff --git a/internal/settings/string.go b/internal/settings/string.go index 30767ab2..84adb52a 100644 --- a/internal/settings/string.go +++ b/internal/settings/string.go @@ -22,13 +22,15 @@ type StringSetting interface { var _ StringSetting = (*String)(nil) type String struct { + validator func(string) error + beforeInit func(StringSetting, string) (string, error) + beforeSet func(StringSetting, string) (string, error) + afterInit func(StringSetting, string) + afterSet func(StringSetting, string) + defaultValue string + value string setting - defaultValue string - lock sync.RWMutex - value string - validator func(string) error - beforeInit, beforeSet func(StringSetting, string) (string, error) - afterInit, afterSet func(StringSetting, string) + lock sync.RWMutex } type StringSettingOption func(*String) diff --git a/internal/sysNotify/sysNotify.go b/internal/sysNotify/sysNotify.go index b25a6601..f30d62d6 100644 --- a/internal/sysNotify/sysNotify.go +++ b/internal/sysNotify/sysNotify.go @@ -27,8 +27,8 @@ func WaitCbk() { type SysNotify struct { c chan os.Signal - once sync.Once taskGroup rwmap.RWMap[NotifyType, *taskQueue] + once sync.Once } type NotifyType int @@ -39,14 +39,14 @@ const ( ) type taskQueue struct { - notifyTaskLock sync.Mutex notifyTaskQueue *pqueue.PQueue[*sysNotifyTask] + notifyTaskLock sync.Mutex } type sysNotifyTask struct { Task func() error - NotifyType NotifyType Name string + NotifyType NotifyType } func NewSysNotifyTask(name string, NotifyType NotifyType, task func() error) *sysNotifyTask { diff --git a/server/handlers/proxy/m3u8.go b/server/handlers/proxy/m3u8.go index fdde9e88..c47b18fa 100644 --- a/server/handlers/proxy/m3u8.go +++ b/server/handlers/proxy/m3u8.go @@ -18,11 +18,11 @@ import ( ) type m3u8TargetClaims struct { + jwt.RegisteredClaims RoomId string `json:"r"` MovieId string `json:"m"` TargetUrl string `json:"t"` IsM3u8File bool `json:"f"` - jwt.RegisteredClaims } func GetM3u8Target(token string) (*m3u8TargetClaims, error) { diff --git a/server/handlers/public.go b/server/handlers/public.go index 9b3c3565..815db700 100644 --- a/server/handlers/public.go +++ b/server/handlers/public.go @@ -13,16 +13,13 @@ import ( ) type publicSettings struct { - PasswordDisableSignup bool `json:"passwordDisableSignup"` - + EmailWhitelist []string `json:"emailWhitelist,omitempty"` + PasswordDisableSignup bool `json:"passwordDisableSignup"` EmailEnable bool `json:"emailEnable"` EmailDisableSignup bool `json:"emailDisableSignup"` EmailWhitelistEnabled bool `json:"emailWhitelistEnabled"` - EmailWhitelist []string `json:"emailWhitelist,omitempty"` - - Oauth2DisableSignup bool `json:"oauth2DisableSignup"` - - GuestEnable bool `json:"guestEnable"` + Oauth2DisableSignup bool `json:"oauth2DisableSignup"` + GuestEnable bool `json:"guestEnable"` } func Settings(ctx *gin.Context) { diff --git a/server/middlewares/auth.go b/server/middlewares/auth.go index f4c3a936..b2fd7f6e 100644 --- a/server/middlewares/auth.go +++ b/server/middlewares/auth.go @@ -36,9 +36,9 @@ var ( ) type AuthClaims struct { + jwt.RegisteredClaims UserId string `json:"u"` UserVersion uint32 `json:"uv"` - jwt.RegisteredClaims } func authUser(authorization string) (*AuthClaims, error) { diff --git a/server/model/admin.go b/server/model/admin.go index dbe452c8..5285d6bb 100644 --- a/server/model/admin.go +++ b/server/model/admin.go @@ -5,7 +5,6 @@ import ( "github.com/gin-gonic/gin" json "github.com/json-iterator/go" - "github.com/synctv-org/synctv/internal/model" dbModel "github.com/synctv-org/synctv/internal/model" "google.golang.org/grpc/connectivity" ) @@ -134,7 +133,7 @@ type GetVendorBackendResp struct { Status connectivity.State `json:"status"` } -type AddVendorBackendReq model.VendorBackend +type AddVendorBackendReq dbModel.VendorBackend func (avbr *AddVendorBackendReq) Validate() error { if avbr.UsedBy.AlistBackendName != "" { diff --git a/server/model/api.go b/server/model/api.go index 882328fa..0024274c 100644 --- a/server/model/api.go +++ b/server/model/api.go @@ -13,9 +13,9 @@ var ( ) type ApiResp struct { - Time int64 `json:"time"` - Error string `json:"error,omitempty"` Data any `json:"data,omitempty"` + Error string `json:"error,omitempty"` + Time int64 `json:"time"` } func (ar *ApiResp) SetError(err error) { diff --git a/server/model/member.go b/server/model/member.go index e3d57140..057f835f 100644 --- a/server/model/member.go +++ b/server/model/member.go @@ -9,13 +9,13 @@ import ( type RoomMembersResp struct { UserID string `json:"userId"` Username string `json:"username"` + RoomID string `json:"roomId"` JoinAt int64 `json:"joinAt"` OnlineCount int `json:"onlineCount"` - Role dbModel.RoomMemberRole `json:"role"` - Status dbModel.RoomMemberStatus `json:"status"` - RoomID string `json:"roomId"` Permissions dbModel.RoomMemberPermission `json:"permissions"` AdminPermissions dbModel.RoomAdminPermission `json:"adminPermissions"` + Role dbModel.RoomMemberRole `json:"role"` + Status dbModel.RoomMemberStatus `json:"status"` } type ( diff --git a/server/model/movie.go b/server/model/movie.go index 52ecd495..8300f4b5 100644 --- a/server/model/movie.go +++ b/server/model/movie.go @@ -198,16 +198,16 @@ type MoviesResp struct { type Movie struct { Id string `json:"id"` - CreatedAt int64 `json:"createAt"` - Base model.MovieBase `json:"base"` Creator string `json:"creator"` CreatorId string `json:"creatorId"` SubPath string `json:"subPath"` + Base model.MovieBase `json:"base"` + CreatedAt int64 `json:"createAt"` } type CurrentMovieResp struct { - Status op.Status `json:"status"` Movie *Movie `json:"movie"` + Status op.Status `json:"status"` ExpireId uint64 `json:"expireId"` } diff --git a/server/model/room.go b/server/model/room.go index 6c918c7a..85d43a73 100644 --- a/server/model/room.go +++ b/server/model/room.go @@ -7,7 +7,6 @@ import ( json "github.com/json-iterator/go" "github.com/gin-gonic/gin" - "github.com/synctv-org/synctv/internal/model" dbModel "github.com/synctv-org/synctv/internal/model" ) @@ -59,14 +58,14 @@ func (c *CreateRoomReq) Validate() error { } type RoomListResp struct { - RoomId string `json:"roomId"` - RoomName string `json:"roomName"` - ViewerCount int64 `json:"viewerCount"` - NeedPassword bool `json:"needPassword"` - CreatorID string `json:"creatorId"` - Creator string `json:"creator"` - CreatedAt int64 `json:"createdAt"` - Status model.RoomStatus `json:"status"` + RoomId string `json:"roomId"` + RoomName string `json:"roomName"` + CreatorID string `json:"creatorId"` + Creator string `json:"creator"` + ViewerCount int64 `json:"viewerCount"` + CreatedAt int64 `json:"createdAt"` + NeedPassword bool `json:"needPassword"` + Status dbModel.RoomStatus `json:"status"` } type JoinedRoomResp struct { @@ -152,11 +151,11 @@ func (c *CheckRoomPasswordReq) Validate() error { } type CheckRoomResp struct { - Name string `json:"name"` - Status model.RoomStatus `json:"status"` - CreatorID string `json:"creatorId"` - Creator string `json:"creator"` - NeedPassword bool `json:"needPassword"` - ViewerCount int64 `json:"viewerCount"` - EnabledGuest bool `json:"enabledGuest"` + Name string `json:"name"` + CreatorID string `json:"creatorId"` + Creator string `json:"creator"` + ViewerCount int64 `json:"viewerCount"` + Status dbModel.RoomStatus `json:"status"` + NeedPassword bool `json:"needPassword"` + EnabledGuest bool `json:"enabledGuest"` } diff --git a/server/model/user.go b/server/model/user.go index fe293463..0b599708 100644 --- a/server/model/user.go +++ b/server/model/user.go @@ -113,9 +113,9 @@ func (u *UserSignupPasswordReq) Validate() error { type UserInfoResp struct { ID string `json:"id"` Username string `json:"username"` - Role dbModel.Role `json:"role"` - CreatedAt int64 `json:"createdAt"` Email string `json:"email"` + CreatedAt int64 `json:"createdAt"` + Role dbModel.Role `json:"role"` } type SetUsernameReq struct { diff --git a/server/model/vendor.go b/server/model/vendor.go index 67633231..ac4fa490 100644 --- a/server/model/vendor.go +++ b/server/model/vendor.go @@ -10,8 +10,8 @@ import ( ) type VendorMeResp[T any] struct { - IsLogin bool `json:"isLogin"` Info T `json:"info,omitempty"` + IsLogin bool `json:"isLogin"` } type VendorFSListResp[T any] struct { diff --git a/utils/smtp/smtpool.go b/utils/smtp/smtpool.go index 254ea5d5..6eecc93b 100644 --- a/utils/smtp/smtpool.go +++ b/utils/smtp/smtpool.go @@ -12,11 +12,11 @@ import ( type SmtpConfig struct { Host string - Port uint32 Protocol string Username string Password string From string + Port uint32 } func validateSmtpConfig(c *SmtpConfig) error { @@ -71,11 +71,11 @@ func newSmtpClient(c *SmtpConfig) (*smtp.Client, error) { var ErrSmtpPoolClosed = fmt.Errorf("smtp pool is closed") type SmtpPool struct { - mu sync.Mutex - clients []*smtp.Client c *SmtpConfig + clients []*smtp.Client max int active int + mu sync.Mutex closed bool }