Feat: oauth2 settings

pull/39/head
zijiren233 2 years ago
parent f0136b0134
commit e3c92fb7b4

@ -29,11 +29,11 @@ var ServerCmd = &cobra.Command{
bootstrap.InitLog,
bootstrap.InitGinMode,
bootstrap.InitDatabase,
bootstrap.InitSetting,
bootstrap.InitProvider,
bootstrap.InitOp,
bootstrap.InitRtmp,
bootstrap.InitVendor,
bootstrap.InitSetting,
)
if !flags.DisableUpdateCheck {
boot.Add(bootstrap.InitCheckUpdate)

@ -2,6 +2,7 @@ package bootstrap
import (
"context"
"fmt"
"os"
"path/filepath"
@ -9,20 +10,24 @@ import (
log "github.com/sirupsen/logrus"
"github.com/synctv-org/synctv/cmd/flags"
"github.com/synctv-org/synctv/internal/conf"
"github.com/synctv-org/synctv/internal/model"
"github.com/synctv-org/synctv/internal/provider"
"github.com/synctv-org/synctv/internal/provider/plugins"
"github.com/synctv-org/synctv/internal/provider/providers"
"github.com/synctv-org/synctv/internal/settings"
serverAuth "github.com/synctv-org/synctv/server/oauth2"
"github.com/synctv-org/synctv/utils"
"golang.org/x/oauth2"
)
var ProviderGroupSettings = make(map[model.SettingGroup][]settings.Setting)
func InitProvider(ctx context.Context) (err error) {
logOur := log.StandardLogger().Writer()
logLevle := hclog.Info
if flags.Dev {
logLevle = hclog.Debug
}
for _, op := range conf.Conf.OAuth2.Plugins {
for _, op := range conf.Conf.OAuth2 {
op.PluginFile, err = utils.OptFilePath(op.PluginFile)
if err != nil {
log.Fatalf("oauth2 plugin file path error: %v", err)
@ -34,7 +39,7 @@ func InitProvider(ctx context.Context) (err error) {
log.Fatalf("create plugin dir: %s failed: %s", filepath.Dir(op.PluginFile), err)
return err
}
err = plugins.InitProviderPlugins(op.PluginFile, op.Arges, hclog.New(&hclog.LoggerOptions{
err = plugins.InitProviderPlugins(op.PluginFile, op.Args, hclog.New(&hclog.LoggerOptions{
Name: op.PluginFile,
Level: logLevle,
Output: logOur,
@ -45,23 +50,64 @@ func InitProvider(ctx context.Context) (err error) {
return err
}
}
for op, v := range conf.Conf.OAuth2.Providers {
opt := provider.Oauth2Option{
ClientID: v.ClientID,
ClientSecret: v.ClientSecret,
RedirectURL: v.RedirectURL,
}
if v.Endpoint != nil {
opt.Endpoint = &oauth2.Endpoint{
AuthURL: v.Endpoint.AuthURL,
DeviceAuthURL: v.Endpoint.DeviceAuthURL,
TokenURL: v.Endpoint.TokenURL,
for op, pi := range providers.AllProvider() {
op, pi := op, pi
group := model.SettingGroup(fmt.Sprintf("%s_%s", model.SettingGroupOauth2, op))
e := settings.NewBoolSetting(fmt.Sprintf("%s_enabled", group), false, group, settings.WithBeforeInitBool(func(bs settings.BoolSetting, b bool) error {
defer serverAuth.Oauth2EnabledCache.Refresh()
if b {
return providers.EnableProvider(op)
} else {
providers.DisableProvider(op)
return nil
}
}
err := providers.InitProvider(op, opt)
if err != nil {
return err
}
}), settings.WithBeforeSetBool(func(bs settings.BoolSetting, b bool) error {
defer serverAuth.Oauth2EnabledCache.Refresh()
if b {
return providers.EnableProvider(op)
} else {
providers.DisableProvider(op)
return nil
}
}))
ProviderGroupSettings[group] = []settings.Setting{e}
opt := provider.Oauth2Option{}
cid := settings.NewStringSetting(fmt.Sprintf("%s_client_id", group), opt.ClientID, group, settings.WithBeforeInitString(func(ss settings.StringSetting, s string) error {
opt.ClientID = s
pi.Init(opt)
return nil
}), settings.WithBeforeSetString(func(ss settings.StringSetting, s string) error {
opt.ClientID = s
pi.Init(opt)
return nil
}))
ProviderGroupSettings[group] = append(ProviderGroupSettings[group], cid)
cs := settings.NewStringSetting(fmt.Sprintf("%s_client_secret", group), opt.ClientSecret, group, settings.WithBeforeInitString(func(ss settings.StringSetting, s string) error {
opt.ClientSecret = s
pi.Init(opt)
return nil
}), settings.WithBeforeSetString(func(ss settings.StringSetting, s string) error {
opt.ClientSecret = s
pi.Init(opt)
return nil
}))
ProviderGroupSettings[group] = append(ProviderGroupSettings[group], cs)
ru := settings.NewStringSetting(fmt.Sprintf("%s_redirect_url", group), opt.RedirectURL, group, settings.WithBeforeInitString(func(ss settings.StringSetting, s string) error {
opt.RedirectURL = s
pi.Init(opt)
return nil
}), settings.WithBeforeSetString(func(ss settings.StringSetting, s string) error {
opt.RedirectURL = s
pi.Init(opt)
return nil
}))
ProviderGroupSettings[group] = append(ProviderGroupSettings[group], ru)
}
return nil
}

@ -1,35 +1,12 @@
package conf
import (
"github.com/synctv-org/synctv/internal/provider"
)
type OAuth2Config struct {
Providers map[provider.OAuth2Provider]OAuth2ProviderConfig `yaml:"providers"`
Plugins []Oauth2Plugin `yaml:"plugins"`
}
type OAuth2Config []Oauth2Plugin
type Oauth2Plugin struct {
PluginFile string `yaml:"plugin_file"`
Arges []string `yaml:"arges"`
}
type Endpoint struct {
AuthURL string `yaml:"auth_url"`
DeviceAuthURL string `yaml:"device_auth_url"`
TokenURL string `yaml:"token_url"`
}
type OAuth2ProviderConfig struct {
ClientID string `yaml:"client_id"`
ClientSecret string `yaml:"client_secret"`
RedirectURL string `yaml:"redirect_url"`
Endpoint *Endpoint `yaml:"endpoint,omitempty"`
Args []string `yaml:"args"`
}
func DefaultOAuth2Config() OAuth2Config {
return OAuth2Config{
Providers: map[provider.OAuth2Provider]OAuth2ProviderConfig{},
Plugins: []Oauth2Plugin{},
}
return nil
}

@ -21,6 +21,7 @@ const (
SettingGroupProxy SettingGroup = "proxy"
SettingGroupRtmp SettingGroup = "rtmp"
SettingGroupDatabase SettingGroup = "database"
SettingGroupOauth2 SettingGroup = "oauth2"
)
type Setting struct {

@ -19,13 +19,6 @@ func (c *GRPCClient) Init(o provider.Oauth2Option) {
ClientSecret: o.ClientSecret,
RedirectUrl: o.RedirectURL,
}
if o.Endpoint != nil {
opt.Endpoint = &providerpb.InitReq_Endpoint{
AuthUrl: o.Endpoint.AuthURL,
DeviceAuthUrl: o.Endpoint.DeviceAuthURL,
TokenUrl: o.Endpoint.TokenURL,
}
}
c.client.Init(context.Background(), &opt)
}

@ -4,12 +4,13 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
plugin "github.com/hashicorp/go-plugin"
"github.com/synctv-org/synctv/internal/provider"
"github.com/synctv-org/synctv/internal/provider/plugins"
"golang.org/x/oauth2"
"net/http"
"os"
)
// Mac/Linux:
@ -39,12 +40,20 @@ type FeishuProvider struct {
ssoid string // Your SSO Application ID in Feishu Anycross
}
func (p *FeishuProvider) Init(c provider.Oauth2Option) {
p.config.Scopes = []string{"profile"}
p.config.Endpoint = oauth2.Endpoint{
AuthURL: fmt.Sprintf("https://anycross.feishu.cn/sso/%s/oauth2/auth", p.ssoid), // 认证端点
TokenURL: fmt.Sprintf("https://anycross.feishu.cn/sso/%s/oauth2/token", p.ssoid), //Token 端点
func newFeishuProvider(ssoid string) provider.ProviderInterface {
return &FeishuProvider{
config: oauth2.Config{
Scopes: []string{"profile"},
Endpoint: oauth2.Endpoint{
AuthURL: fmt.Sprintf("https://anycross.feishu.cn/sso/%s/oauth2/auth", ssoid), // 认证端点
TokenURL: fmt.Sprintf("https://anycross.feishu.cn/sso/%s/oauth2/token", ssoid), //Token 端点
},
},
ssoid: ssoid,
}
}
func (p *FeishuProvider) Init(c provider.Oauth2Option) {
p.config.ClientID = c.ClientID
p.config.ClientSecret = c.ClientSecret
p.config.RedirectURL = c.RedirectURL
@ -96,7 +105,7 @@ type feishuUserInfo struct {
func main() {
args := os.Args
var pluginMap = map[string]plugin.Plugin{
"Provider": &plugins.ProviderPlugin{Impl: &FeishuProvider{ssoid: args[1]}},
"Provider": &plugins.ProviderPlugin{Impl: newFeishuProvider(args[1])},
}
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: plugins.HandshakeConfig,

@ -31,16 +31,19 @@ type GiteeProvider struct {
config oauth2.Config
}
func (p *GiteeProvider) Init(c provider.Oauth2Option) {
p.config.Scopes = []string{"user_info"}
if c.Endpoint != nil {
p.config.Endpoint = *c.Endpoint
} else {
p.config.Endpoint = oauth2.Endpoint{
AuthURL: "https://gitee.com/oauth/authorize",
TokenURL: "https://gitee.com/oauth/token",
}
func newGiteeProvider() provider.ProviderInterface {
return &GiteeProvider{
config: oauth2.Config{
Scopes: []string{"user_info"},
Endpoint: oauth2.Endpoint{
AuthURL: "https://gitee.com/oauth/authorize",
TokenURL: "https://gitee.com/oauth/token",
},
},
}
}
func (p *GiteeProvider) Init(c provider.Oauth2Option) {
p.config.ClientID = c.ClientID
p.config.ClientSecret = c.ClientSecret
p.config.RedirectURL = c.RedirectURL
@ -91,7 +94,7 @@ type giteeUserInfo struct {
func main() {
var pluginMap = map[string]plugin.Plugin{
"Provider": &plugins.ProviderPlugin{Impl: &GiteeProvider{}},
"Provider": &plugins.ProviderPlugin{Impl: newGiteeProvider()},
}
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: plugins.HandshakeConfig,

@ -20,13 +20,6 @@ func (s *GRPCServer) Init(ctx context.Context, req *providerpb.InitReq) (*provid
ClientSecret: req.ClientSecret,
RedirectURL: req.RedirectUrl,
}
if req.Endpoint != nil {
opt.Endpoint = &oauth2.Endpoint{
AuthURL: req.Endpoint.AuthUrl,
DeviceAuthURL: req.Endpoint.DeviceAuthUrl,
TokenURL: req.Endpoint.TokenUrl,
}
}
s.Impl.Init(opt)
return &providerpb.Enpty{}, nil
}

@ -17,7 +17,6 @@ type Oauth2Option struct {
ClientID string
ClientSecret string
RedirectURL string
Endpoint *oauth2.Endpoint
}
type ProviderInterface interface {

@ -16,16 +16,19 @@ type BaiduNetDiskProvider struct {
config oauth2.Config
}
func (p *BaiduNetDiskProvider) Init(c provider.Oauth2Option) {
p.config.Scopes = []string{"basic", "netdisk"}
if c.Endpoint != nil {
p.config.Endpoint = *c.Endpoint
} else {
p.config.Endpoint = oauth2.Endpoint{
AuthURL: "https://openapi.baidu.com/oauth/2.0/authorize",
TokenURL: "https://openapi.baidu.com/oauth/2.0/token",
}
func newBaiduNetDiskProvider() provider.ProviderInterface {
return &BaiduNetDiskProvider{
config: oauth2.Config{
Scopes: []string{"basic", "netdisk"},
Endpoint: oauth2.Endpoint{
AuthURL: "https://openapi.baidu.com/oauth/2.0/authorize",
TokenURL: "https://openapi.baidu.com/oauth/2.0/token",
},
},
}
}
func (p *BaiduNetDiskProvider) Init(c provider.Oauth2Option) {
p.config.ClientID = c.ClientID
p.config.ClientSecret = c.ClientSecret
p.config.RedirectURL = c.RedirectURL
@ -80,5 +83,5 @@ type baiduNetDiskProviderUserInfo struct {
}
func init() {
RegisterProvider(new(BaiduNetDiskProvider))
RegisterProvider(newBaiduNetDiskProvider())
}

@ -15,16 +15,19 @@ type BaiduProvider struct {
config oauth2.Config
}
func (p *BaiduProvider) Init(c provider.Oauth2Option) {
p.config.Scopes = []string{"basic"}
if c.Endpoint != nil {
p.config.Endpoint = *c.Endpoint
} else {
p.config.Endpoint = oauth2.Endpoint{
AuthURL: "https://openapi.baidu.com/oauth/2.0/authorize",
TokenURL: "https://openapi.baidu.com/oauth/2.0/token",
}
func newBaiduProvider() provider.ProviderInterface {
return &BaiduProvider{
config: oauth2.Config{
Scopes: []string{"basic"},
Endpoint: oauth2.Endpoint{
AuthURL: "https://openapi.baidu.com/oauth/2.0/authorize",
TokenURL: "https://openapi.baidu.com/oauth/2.0/token",
},
},
}
}
func (p *BaiduProvider) Init(c provider.Oauth2Option) {
p.config.ClientID = c.ClientID
p.config.ClientSecret = c.ClientSecret
p.config.RedirectURL = c.RedirectURL
@ -68,11 +71,11 @@ func (p *BaiduProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*pro
}, nil
}
func init() {
RegisterProvider(new(BaiduProvider))
}
type baiduProviderUserInfo struct {
Uname string `json:"uname"`
Openid string `json:"openid"`
}
func init() {
RegisterProvider(newBaiduProvider())
}

@ -14,16 +14,19 @@ type GiteeProvider struct {
config oauth2.Config
}
func (p *GiteeProvider) Init(c provider.Oauth2Option) {
p.config.Scopes = []string{"user_info"}
if c.Endpoint != nil {
p.config.Endpoint = *c.Endpoint
} else {
p.config.Endpoint = oauth2.Endpoint{
AuthURL: "https://gitee.com/oauth/authorize",
TokenURL: "https://gitee.com/oauth/token",
}
func newGiteeProvider() provider.ProviderInterface {
return &GiteeProvider{
config: oauth2.Config{
Scopes: []string{"user_info"},
Endpoint: oauth2.Endpoint{
AuthURL: "https://gitee.com/oauth/authorize",
TokenURL: "https://gitee.com/oauth/token",
},
},
}
}
func (p *GiteeProvider) Init(c provider.Oauth2Option) {
p.config.ClientID = c.ClientID
p.config.ClientSecret = c.ClientSecret
p.config.RedirectURL = c.RedirectURL
@ -73,5 +76,5 @@ type giteeUserInfo struct {
}
func init() {
RegisterProvider(new(GiteeProvider))
RegisterProvider(newGiteeProvider())
}

@ -15,13 +15,16 @@ type GithubProvider struct {
config oauth2.Config
}
func (p *GithubProvider) Init(c provider.Oauth2Option) {
p.config.Scopes = []string{"user"}
if c.Endpoint != nil {
p.config.Endpoint = *c.Endpoint
} else {
p.config.Endpoint = github.Endpoint
func newGithubProvider() provider.ProviderInterface {
return &GithubProvider{
config: oauth2.Config{
Scopes: []string{"user"},
Endpoint: github.Endpoint,
},
}
}
func (p *GithubProvider) Init(c provider.Oauth2Option) {
p.config.ClientID = c.ClientID
p.config.ClientSecret = c.ClientSecret
p.config.RedirectURL = c.RedirectURL
@ -71,5 +74,5 @@ type githubUserInfo struct {
}
func init() {
RegisterProvider(new(GithubProvider))
RegisterProvider(newGithubProvider())
}

@ -13,13 +13,16 @@ type GitlabProvider struct {
config oauth2.Config
}
func (g *GitlabProvider) Init(c provider.Oauth2Option) {
g.config.Scopes = []string{"read_user"}
if c.Endpoint != nil {
g.config.Endpoint = *c.Endpoint
} else {
g.config.Endpoint = gitlab.Endpoint
func newGitlabProvider() provider.ProviderInterface {
return &GitlabProvider{
config: oauth2.Config{
Scopes: []string{"read_user"},
Endpoint: gitlab.Endpoint,
},
}
}
func (g *GitlabProvider) Init(c provider.Oauth2Option) {
g.config.ClientID = c.ClientID
g.config.ClientSecret = c.ClientSecret
g.config.RedirectURL = c.RedirectURL
@ -56,5 +59,5 @@ func (g *GitlabProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*pr
}
func init() {
RegisterProvider(new(GitlabProvider))
RegisterProvider(newGitlabProvider())
}

@ -14,13 +14,16 @@ type GoogleProvider struct {
config oauth2.Config
}
func (g *GoogleProvider) Init(c provider.Oauth2Option) {
g.config.Scopes = []string{"profile"}
if c.Endpoint != nil {
g.config.Endpoint = *c.Endpoint
} else {
g.config.Endpoint = google.Endpoint
func newGoogleProvider() provider.ProviderInterface {
return &GoogleProvider{
config: oauth2.Config{
Scopes: []string{"profile"},
Endpoint: google.Endpoint,
},
}
}
func (g *GoogleProvider) Init(c provider.Oauth2Option) {
g.config.ClientID = c.ClientID
g.config.ClientSecret = c.ClientSecret
g.config.RedirectURL = c.RedirectURL
@ -65,7 +68,7 @@ func (g *GoogleProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*pr
}
func init() {
RegisterProvider(new(GoogleProvider))
RegisterProvider(newGoogleProvider())
}
type googleUserInfo struct {

@ -14,13 +14,16 @@ type MicrosoftProvider struct {
config oauth2.Config
}
func (p *MicrosoftProvider) Init(c provider.Oauth2Option) {
p.config.Scopes = []string{"user.read"}
if c.Endpoint != nil {
p.config.Endpoint = *c.Endpoint
} else {
p.config.Endpoint = microsoft.LiveConnectEndpoint
func newMicrosoftProvider() provider.ProviderInterface {
return &MicrosoftProvider{
config: oauth2.Config{
Scopes: []string{"user.read"},
Endpoint: microsoft.LiveConnectEndpoint,
},
}
}
func (p *MicrosoftProvider) Init(c provider.Oauth2Option) {
p.config.ClientID = c.ClientID
p.config.ClientSecret = c.ClientSecret
p.config.RedirectURL = c.RedirectURL
@ -70,5 +73,5 @@ type microsoftUserInfo struct {
}
func init() {
RegisterProvider(new(MicrosoftProvider))
RegisterProvider(newMicrosoftProvider())
}

@ -4,46 +4,56 @@ import (
"fmt"
"github.com/synctv-org/synctv/internal/provider"
"github.com/zijiren233/gencontainer/rwmap"
)
var (
enabledProviders map[provider.OAuth2Provider]provider.ProviderInterface
allowedProviders = make(map[provider.OAuth2Provider]provider.ProviderInterface)
enabledProviders rwmap.RWMap[provider.OAuth2Provider, provider.ProviderInterface]
allProviders = make(map[provider.OAuth2Provider]provider.ProviderInterface)
)
func InitProvider(p provider.OAuth2Provider, c provider.Oauth2Option) error {
pi, ok := allowedProviders[p]
func InitProvider(p provider.OAuth2Provider, c provider.Oauth2Option) (provider.ProviderInterface, error) {
pi, ok := allProviders[p]
if !ok {
return FormatErrNotImplemented(p)
return nil, FormatErrNotImplemented(p)
}
pi.Init(c)
if enabledProviders == nil {
enabledProviders = make(map[provider.OAuth2Provider]provider.ProviderInterface)
}
enabledProviders[pi.Provider()] = pi
return nil
return pi, nil
}
func RegisterProvider(ps ...provider.ProviderInterface) {
for _, p := range ps {
allowedProviders[p.Provider()] = p
allProviders[p.Provider()] = p
}
}
func GetProvider(p provider.OAuth2Provider) (provider.ProviderInterface, error) {
pi, ok := enabledProviders[p]
pi, ok := enabledProviders.Load(p)
if !ok {
return nil, FormatErrNotImplemented(p)
}
return pi, nil
}
func AllowedProvider() map[provider.OAuth2Provider]provider.ProviderInterface {
return allowedProviders
func AllProvider() map[provider.OAuth2Provider]provider.ProviderInterface {
return allProviders
}
func EnabledProvider() *rwmap.RWMap[provider.OAuth2Provider, provider.ProviderInterface] {
return &enabledProviders
}
func EnableProvider(p provider.OAuth2Provider) error {
pi, ok := allProviders[p]
if !ok {
return FormatErrNotImplemented(p)
}
enabledProviders.Store(p, pi)
return nil
}
func EnabledProvider() map[provider.OAuth2Provider]provider.ProviderInterface {
return enabledProviders
func DisableProvider(p provider.OAuth2Provider) {
enabledProviders.Delete(p)
}
type FormatErrNotImplemented string

@ -14,16 +14,19 @@ type QQProvider struct {
config oauth2.Config
}
func (p *QQProvider) Init(c provider.Oauth2Option) {
p.config.Scopes = []string{"get_user_info"}
if c.Endpoint != nil {
p.config.Endpoint = *c.Endpoint
} else {
p.config.Endpoint = oauth2.Endpoint{
AuthURL: "https://graph.qq.com/oauth2.0/authorize",
TokenURL: "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code",
}
func newQQProvider() provider.ProviderInterface {
return &QQProvider{
config: oauth2.Config{
Scopes: []string{"get_user_info"},
Endpoint: oauth2.Endpoint{
AuthURL: "https://graph.qq.com/oauth2.0/authorize",
TokenURL: "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code",
},
},
}
}
func (p *QQProvider) Init(c provider.Oauth2Option) {
p.config.ClientID = c.ClientID
p.config.ClientSecret = c.ClientSecret
p.config.RedirectURL = c.RedirectURL
@ -67,11 +70,11 @@ func (p *QQProvider) GetUserInfo(ctx context.Context, tk *oauth2.Token) (*provid
}, nil
}
func init() {
RegisterProvider(new(QQProvider))
}
type qqProviderUserInfo struct {
ClientID string `json:"client_id"`
Openid string `json:"openid"`
}
func init() {
RegisterProvider(newQQProvider())
}

@ -5,6 +5,7 @@ import (
"strconv"
"sync/atomic"
"github.com/synctv-org/synctv/internal/db"
"github.com/synctv-org/synctv/internal/model"
)
@ -21,13 +22,19 @@ var _ BoolSetting = (*Bool)(nil)
type Bool struct {
setting
defaultValue bool
value uint32
beforeSet func(BoolSetting, bool) error
defaultValue bool
value uint32
beforeInit, beforeSet func(BoolSetting, bool) error
}
type BoolSettingOption func(*Bool)
func WithBeforeInitBool(beforeInit func(BoolSetting, bool) error) BoolSettingOption {
return func(s *Bool) {
s.beforeInit = beforeInit
}
}
func WithBeforeSetBool(beforeSet func(BoolSetting, bool) error) BoolSettingOption {
return func(s *Bool) {
s.beforeSet = beforeSet
@ -67,6 +74,14 @@ func (b *Bool) Init(value string) error {
if err != nil {
return err
}
if b.beforeInit != nil {
err = b.beforeInit(b, v)
if err != nil {
return err
}
}
b.set(v)
return nil
}
@ -108,6 +123,11 @@ func (b *Bool) SetString(value string) error {
}
}
err = db.UpdateSettingItemValue(b.name, b.Stringify(v))
if err != nil {
return err
}
b.set(v)
return nil
}
@ -120,6 +140,11 @@ func (b *Bool) Set(value bool) (err error) {
}
}
err = db.UpdateSettingItemValue(b.name, b.Stringify(value))
if err != nil {
return err
}
b.set(value)
return
}

@ -6,6 +6,7 @@ import (
"strconv"
"sync/atomic"
"github.com/synctv-org/synctv/internal/db"
"github.com/synctv-org/synctv/internal/model"
)
@ -22,10 +23,10 @@ var _ Float64Setting = (*Float64)(nil)
type Float64 struct {
setting
defaultValue float64
value uint64
validator func(float64) error
beforeSet func(Float64Setting, float64) error
defaultValue float64
value uint64
validator func(float64) error
beforeInit, beforeSet func(Float64Setting, float64) error
}
type Float64SettingOption func(*Float64)
@ -36,6 +37,12 @@ func WithValidatorFloat64(validator func(float64) error) Float64SettingOption {
}
}
func WithBeforeInitFloat64(beforeInit func(Float64Setting, float64) error) Float64SettingOption {
return func(s *Float64) {
s.beforeInit = beforeInit
}
}
func WithBeforeSetFloat64(beforeSet func(Float64Setting, float64) error) Float64SettingOption {
return func(s *Float64) {
s.beforeSet = beforeSet
@ -78,6 +85,14 @@ func (f *Float64) Init(value string) error {
if err != nil {
return err
}
if f.beforeInit != nil {
err = f.beforeInit(f, v)
if err != nil {
return err
}
}
f.set(v)
return nil
}
@ -111,6 +126,11 @@ func (f *Float64) SetString(value string) error {
}
}
err = db.UpdateSettingItemValue(f.name, f.Stringify(v))
if err != nil {
return err
}
f.set(v)
return nil
}
@ -134,6 +154,11 @@ func (f *Float64) Set(value float64) (err error) {
}
}
err = db.UpdateSettingItemValue(f.name, f.Stringify(value))
if err != nil {
return err
}
f.set(value)
return
}

@ -5,6 +5,7 @@ import (
"strconv"
"sync/atomic"
"github.com/synctv-org/synctv/internal/db"
"github.com/synctv-org/synctv/internal/model"
)
@ -21,10 +22,10 @@ var _ Int64Setting = (*Int64)(nil)
type Int64 struct {
setting
defaultValue int64
value int64
validator func(int64) error
beforeSet func(Int64Setting, int64) error
defaultValue int64
value int64
validator func(int64) error
beforeInit, beforeSet func(Int64Setting, int64) error
}
type Int64SettingOption func(*Int64)
@ -35,6 +36,12 @@ func WithValidatorInt64(validator func(int64) error) Int64SettingOption {
}
}
func WithBeforeInitInt64(beforeInit func(Int64Setting, int64) error) Int64SettingOption {
return func(s *Int64) {
s.beforeInit = beforeInit
}
}
func WithBeforeSetInt64(beforeSet func(Int64Setting, int64) error) Int64SettingOption {
return func(s *Int64) {
s.beforeSet = beforeSet
@ -77,6 +84,14 @@ func (i *Int64) Init(value string) error {
if err != nil {
return err
}
if i.beforeInit != nil {
err = i.beforeInit(i, v)
if err != nil {
return err
}
}
i.set(v)
return nil
}
@ -110,6 +125,11 @@ func (i *Int64) SetString(value string) error {
}
}
err = db.UpdateSettingItemValue(i.name, i.Stringify(v))
if err != nil {
return err
}
i.set(v)
return nil
}
@ -133,6 +153,11 @@ func (i *Int64) Set(value int64) (err error) {
}
}
err = db.UpdateSettingItemValue(i.name, i.Stringify(value))
if err != nil {
return err
}
i.set(value)
return
}

@ -4,6 +4,7 @@ import (
"fmt"
"sync"
"github.com/synctv-org/synctv/internal/db"
"github.com/synctv-org/synctv/internal/model"
)
@ -20,11 +21,11 @@ var _ StringSetting = (*String)(nil)
type String struct {
setting
defaultValue string
lock sync.RWMutex
value string
validator func(string) error
beforeSet func(StringSetting, string) error
defaultValue string
lock sync.RWMutex
value string
validator func(string) error
beforeInit, beforeSet func(StringSetting, string) error
}
type StringSettingOption func(*String)
@ -35,6 +36,12 @@ func WithValidatorString(validator func(string) error) StringSettingOption {
}
}
func WithBeforeInitString(beforeInit func(StringSetting, string) error) StringSettingOption {
return func(s *String) {
s.beforeInit = beforeInit
}
}
func WithBeforeSetString(beforeSet func(StringSetting, string) error) StringSettingOption {
return func(s *String) {
s.beforeSet = beforeSet
@ -73,6 +80,14 @@ func (s *String) Init(value string) error {
if err != nil {
return err
}
if s.beforeInit != nil {
err = s.beforeInit(s, v)
if err != nil {
return err
}
}
s.set(v)
return nil
}
@ -106,6 +121,11 @@ func (s *String) SetString(value string) error {
}
}
err = db.UpdateSettingItemValue(s.name, s.Stringify(v))
if err != nil {
return err
}
s.set(v)
return nil
}
@ -131,6 +151,11 @@ func (s *String) Set(value string) (err error) {
}
}
err = db.UpdateSettingItemValue(s.name, s.Stringify(value))
if err != nil {
return err
}
s.set(value)
return
}

@ -4,52 +4,35 @@ import (
"errors"
"time"
"github.com/synctv-org/synctv/internal/db"
"github.com/synctv-org/synctv/internal/model"
)
func BeforeSetBoolFunc(s BoolSetting, v bool) error {
return db.UpdateSettingItemValue(s.Name(), s.Stringify(v))
}
func BeforeSetStringFunc(s StringSetting, v string) error {
return db.UpdateSettingItemValue(s.Name(), s.Stringify(v))
}
func BeforeSetInt64Func(s Int64Setting, v int64) error {
return db.UpdateSettingItemValue(s.Name(), s.Stringify(v))
}
func BeforeSetFloat64Func(s Float64Setting, v float64) error {
return db.UpdateSettingItemValue(s.Name(), s.Stringify(v))
}
var (
DisableCreateRoom = NewBoolSetting("disable_create_room", false, model.SettingGroupRoom, WithBeforeSetBool(BeforeSetBoolFunc))
RoomMustNeedPwd = NewBoolSetting("room_must_need_pwd", false, model.SettingGroupRoom, WithBeforeSetBool(BeforeSetBoolFunc))
CreateRoomNeedReview = NewBoolSetting("create_room_need_review", false, model.SettingGroupRoom, WithBeforeSetBool(BeforeSetBoolFunc))
RoomTTL = NewInt64Setting("room_ttl", int64(time.Hour*48), model.SettingGroupRoom, WithBeforeSetInt64(BeforeSetInt64Func))
UserMaxRoomCount = NewInt64Setting("user_max_room_count", 3, model.SettingGroupRoom, WithBeforeSetInt64(BeforeSetInt64Func))
DisableCreateRoom = NewBoolSetting("disable_create_room", false, model.SettingGroupRoom)
RoomMustNeedPwd = NewBoolSetting("room_must_need_pwd", false, model.SettingGroupRoom)
CreateRoomNeedReview = NewBoolSetting("create_room_need_review", false, model.SettingGroupRoom)
RoomTTL = NewInt64Setting("room_ttl", int64(time.Hour*48), model.SettingGroupRoom)
UserMaxRoomCount = NewInt64Setting("user_max_room_count", 3, model.SettingGroupRoom)
)
var (
DisableUserSignup = NewBoolSetting("disable_user_signup", false, model.SettingGroupUser, WithBeforeSetBool(BeforeSetBoolFunc))
SignupNeedReview = NewBoolSetting("signup_need_review", false, model.SettingGroupUser, WithBeforeSetBool(BeforeSetBoolFunc))
DisableUserSignup = NewBoolSetting("disable_user_signup", false, model.SettingGroupUser)
SignupNeedReview = NewBoolSetting("signup_need_review", false, model.SettingGroupUser)
)
var (
MovieProxy = NewBoolSetting("movie_proxy", true, model.SettingGroupProxy, WithBeforeSetBool(BeforeSetBoolFunc))
LiveProxy = NewBoolSetting("live_proxy", true, model.SettingGroupProxy, WithBeforeSetBool(BeforeSetBoolFunc))
AllowProxyToLocal = NewBoolSetting("allow_proxy_to_local", false, model.SettingGroupProxy, WithBeforeSetBool(BeforeSetBoolFunc))
MovieProxy = NewBoolSetting("movie_proxy", true, model.SettingGroupProxy)
LiveProxy = NewBoolSetting("live_proxy", true, model.SettingGroupProxy)
AllowProxyToLocal = NewBoolSetting("allow_proxy_to_local", false, model.SettingGroupProxy)
)
var (
// can watch live streams through the RTMP protocol (without authentication, insecure).
RtmpPlayer = NewBoolSetting("rtmp_player", false, model.SettingGroupRtmp, WithBeforeSetBool(BeforeSetBoolFunc))
RtmpPlayer = NewBoolSetting("rtmp_player", false, model.SettingGroupRtmp)
// default use http header host
CustomPublishHost = NewStringSetting("custom_publish_host", "", model.SettingGroupRtmp, WithBeforeSetString(BeforeSetStringFunc))
CustomPublishHost = NewStringSetting("custom_publish_host", "", model.SettingGroupRtmp)
// disguise the .ts file as a .png file
TsDisguisedAsPng = NewBoolSetting("ts_disguised_as_png", true, model.SettingGroupRtmp, WithBeforeSetBool(BeforeSetBoolFunc))
TsDisguisedAsPng = NewBoolSetting("ts_disguised_as_png", true, model.SettingGroupRtmp)
)
var (

@ -25,10 +25,9 @@ type InitReq struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
ClientSecret string `protobuf:"bytes,2,opt,name=client_secret,json=clientSecret,proto3" json:"client_secret,omitempty"`
RedirectUrl string `protobuf:"bytes,3,opt,name=redirect_url,json=redirectUrl,proto3" json:"redirect_url,omitempty"`
Endpoint *InitReq_Endpoint `protobuf:"bytes,4,opt,name=endpoint,proto3,oneof" json:"endpoint,omitempty"`
ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
ClientSecret string `protobuf:"bytes,2,opt,name=client_secret,json=clientSecret,proto3" json:"client_secret,omitempty"`
RedirectUrl string `protobuf:"bytes,3,opt,name=redirect_url,json=redirectUrl,proto3" json:"redirect_url,omitempty"`
}
func (x *InitReq) Reset() {
@ -84,13 +83,6 @@ func (x *InitReq) GetRedirectUrl() string {
return ""
}
func (x *InitReq) GetEndpoint() *InitReq_Endpoint {
if x != nil {
return x.Endpoint
}
return nil
}
type GetTokenReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -584,150 +576,76 @@ func (*Enpty) Descriptor() ([]byte, []int) {
return file_proto_provider_plugin_proto_rawDescGZIP(), []int{10}
}
type InitReq_Endpoint struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
AuthUrl string `protobuf:"bytes,1,opt,name=auth_url,json=authUrl,proto3" json:"auth_url,omitempty"`
DeviceAuthUrl string `protobuf:"bytes,2,opt,name=device_auth_url,json=deviceAuthUrl,proto3" json:"device_auth_url,omitempty"`
TokenUrl string `protobuf:"bytes,3,opt,name=token_url,json=tokenUrl,proto3" json:"token_url,omitempty"`
}
func (x *InitReq_Endpoint) Reset() {
*x = InitReq_Endpoint{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_provider_plugin_proto_msgTypes[11]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *InitReq_Endpoint) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*InitReq_Endpoint) ProtoMessage() {}
func (x *InitReq_Endpoint) ProtoReflect() protoreflect.Message {
mi := &file_proto_provider_plugin_proto_msgTypes[11]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use InitReq_Endpoint.ProtoReflect.Descriptor instead.
func (*InitReq_Endpoint) Descriptor() ([]byte, []int) {
return file_proto_provider_plugin_proto_rawDescGZIP(), []int{0, 0}
}
func (x *InitReq_Endpoint) GetAuthUrl() string {
if x != nil {
return x.AuthUrl
}
return ""
}
func (x *InitReq_Endpoint) GetDeviceAuthUrl() string {
if x != nil {
return x.DeviceAuthUrl
}
return ""
}
func (x *InitReq_Endpoint) GetTokenUrl() string {
if x != nil {
return x.TokenUrl
}
return ""
}
var File_proto_provider_plugin_proto protoreflect.FileDescriptor
var file_proto_provider_plugin_proto_rawDesc = []byte{
0x0a, 0x1b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72,
0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa1, 0x02, 0x0a, 0x07, 0x49, 0x6e, 0x69, 0x74, 0x52, 0x65, 0x71,
0x12, 0x1b, 0x0a, 0x09, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20,
0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x23, 0x0a,
0x0d, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x63, 0x72,
0x65, 0x74, 0x12, 0x21, 0x0a, 0x0c, 0x72, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x5f, 0x75,
0x72, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x72, 0x65, 0x64, 0x69, 0x72, 0x65,
0x63, 0x74, 0x55, 0x72, 0x6c, 0x12, 0x38, 0x0a, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e,
0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x49, 0x6e, 0x69, 0x74, 0x52, 0x65, 0x71, 0x2e, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74,
0x48, 0x00, 0x52, 0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x88, 0x01, 0x01, 0x1a,
0x6a, 0x0a, 0x08, 0x45, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x61,
0x75, 0x74, 0x68, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61,
0x75, 0x74, 0x68, 0x55, 0x72, 0x6c, 0x12, 0x26, 0x0a, 0x0f, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65,
0x5f, 0x61, 0x75, 0x74, 0x68, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x0d, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x41, 0x75, 0x74, 0x68, 0x55, 0x72, 0x6c, 0x12, 0x1b,
0x0a, 0x09, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28,
0x09, 0x52, 0x08, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x55, 0x72, 0x6c, 0x42, 0x0b, 0x0a, 0x09, 0x5f,
0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x22, 0x21, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x54,
0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x86, 0x01, 0x0a, 0x05,
0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f,
0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63,
0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x74, 0x6f, 0x6b, 0x65,
0x6e, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x6f,
0x6b, 0x65, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x66, 0x72, 0x65,
0x73, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c,
0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x16, 0x0a, 0x06,
0x65, 0x78, 0x70, 0x69, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x65, 0x78,
0x70, 0x69, 0x72, 0x79, 0x22, 0x36, 0x0a, 0x0f, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54,
0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x66, 0x72, 0x65,
0x73, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c,
0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x36, 0x0a, 0x10,
0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70,
0x12, 0x22, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x0c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x05, 0x74,
0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x22, 0x0a, 0x0c, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72,
0x52, 0x65, 0x73, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x25, 0x0a, 0x0d, 0x4e, 0x65, 0x77, 0x41,
0x75, 0x74, 0x68, 0x55, 0x52, 0x4c, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61,
0x74, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22,
0x22, 0x0a, 0x0e, 0x4e, 0x65, 0x77, 0x41, 0x75, 0x74, 0x68, 0x55, 0x52, 0x4c, 0x52, 0x65, 0x73,
0x70, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
0x75, 0x72, 0x6c, 0x22, 0x34, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e,
0x66, 0x6f, 0x52, 0x65, 0x71, 0x12, 0x22, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01,
0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x6f, 0x6b,
0x65, 0x6e, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x57, 0x0a, 0x0f, 0x47, 0x65, 0x74,
0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1a, 0x0a, 0x08,
0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x28, 0x0a, 0x10, 0x70, 0x72, 0x6f, 0x76,
0x69, 0x64, 0x65, 0x72, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x0e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72,
0x49, 0x64, 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6e, 0x70, 0x74, 0x79, 0x32, 0xd7, 0x02, 0x0a, 0x0c,
0x4f, 0x61, 0x75, 0x74, 0x68, 0x32, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x12, 0x26, 0x0a, 0x04,
0x49, 0x6e, 0x69, 0x74, 0x12, 0x0e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x49, 0x6e, 0x69,
0x74, 0x52, 0x65, 0x71, 0x1a, 0x0c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x6e, 0x70,
0x74, 0x79, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72,
0x12, 0x0c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x6e, 0x70, 0x74, 0x79, 0x1a, 0x13,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52,
0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x3b, 0x0a, 0x0a, 0x4e, 0x65, 0x77, 0x41, 0x75, 0x74, 0x68,
0x55, 0x52, 0x4c, 0x12, 0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x65, 0x77, 0x41,
0x75, 0x74, 0x68, 0x55, 0x52, 0x4c, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74,
0x6f, 0x2e, 0x4e, 0x65, 0x77, 0x41, 0x75, 0x74, 0x68, 0x55, 0x52, 0x4c, 0x52, 0x65, 0x73, 0x70,
0x22, 0x00, 0x12, 0x2e, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x12,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52,
0x65, 0x71, 0x1a, 0x0c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e,
0x22, 0x00, 0x12, 0x41, 0x0a, 0x0c, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b,
0x65, 0x6e, 0x12, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65, 0x66, 0x72, 0x65,
0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x2e, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52,
0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x3e, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72,
0x49, 0x6e, 0x66, 0x6f, 0x12, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74,
0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52,
0x65, 0x73, 0x70, 0x22, 0x00, 0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x76, 0x69,
0x64, 0x65, 0x72, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x72, 0x6f, 0x74, 0x6f, 0x22, 0x6e, 0x0a, 0x07, 0x49, 0x6e, 0x69, 0x74, 0x52, 0x65, 0x71, 0x12,
0x1b, 0x0a, 0x09, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x08, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d,
0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x63, 0x72, 0x65,
0x74, 0x12, 0x21, 0x0a, 0x0c, 0x72, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x5f, 0x75, 0x72,
0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x72, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63,
0x74, 0x55, 0x72, 0x6c, 0x22, 0x21, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e,
0x52, 0x65, 0x71, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x22, 0x86, 0x01, 0x0a, 0x05, 0x54, 0x6f, 0x6b, 0x65,
0x6e, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x74, 0x6f, 0x6b, 0x65,
0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54,
0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x1d, 0x0a, 0x0a, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x74, 0x79,
0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x54,
0x79, 0x70, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x5f, 0x74,
0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x66, 0x72,
0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x78, 0x70, 0x69,
0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x65, 0x78, 0x70, 0x69, 0x72, 0x79,
0x22, 0x36, 0x0a, 0x0f, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e,
0x52, 0x65, 0x71, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x5f, 0x74,
0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x72, 0x65, 0x66, 0x72,
0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x36, 0x0a, 0x10, 0x52, 0x65, 0x66, 0x72,
0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x22, 0x0a, 0x05,
0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e,
0x22, 0x22, 0x0a, 0x0c, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70,
0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
0x6e, 0x61, 0x6d, 0x65, 0x22, 0x25, 0x0a, 0x0d, 0x4e, 0x65, 0x77, 0x41, 0x75, 0x74, 0x68, 0x55,
0x52, 0x4c, 0x52, 0x65, 0x71, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0x22, 0x0a, 0x0e, 0x4e,
0x65, 0x77, 0x41, 0x75, 0x74, 0x68, 0x55, 0x52, 0x4c, 0x52, 0x65, 0x73, 0x70, 0x12, 0x10, 0x0a,
0x03, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x6c, 0x22,
0x34, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65,
0x71, 0x12, 0x22, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x0c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x05,
0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x57, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72,
0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72,
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72,
0x6e, 0x61, 0x6d, 0x65, 0x12, 0x28, 0x0a, 0x10, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72,
0x5f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e,
0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x07,
0x0a, 0x05, 0x45, 0x6e, 0x70, 0x74, 0x79, 0x32, 0xd7, 0x02, 0x0a, 0x0c, 0x4f, 0x61, 0x75, 0x74,
0x68, 0x32, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x12, 0x26, 0x0a, 0x04, 0x49, 0x6e, 0x69, 0x74,
0x12, 0x0e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x49, 0x6e, 0x69, 0x74, 0x52, 0x65, 0x71,
0x1a, 0x0c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x6e, 0x70, 0x74, 0x79, 0x22, 0x00,
0x12, 0x2f, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x0c, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x6e, 0x70, 0x74, 0x79, 0x1a, 0x13, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x2e, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x22,
0x00, 0x12, 0x3b, 0x0a, 0x0a, 0x4e, 0x65, 0x77, 0x41, 0x75, 0x74, 0x68, 0x55, 0x52, 0x4c, 0x12,
0x14, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x65, 0x77, 0x41, 0x75, 0x74, 0x68, 0x55,
0x52, 0x4c, 0x52, 0x65, 0x71, 0x1a, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4e, 0x65,
0x77, 0x41, 0x75, 0x74, 0x68, 0x55, 0x52, 0x4c, 0x52, 0x65, 0x73, 0x70, 0x22, 0x00, 0x12, 0x2e,
0x0a, 0x08, 0x47, 0x65, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x12, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x1a, 0x0c,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x00, 0x12, 0x41,
0x0a, 0x0c, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x16,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f,
0x6b, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x52,
0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x22,
0x00, 0x12, 0x3e, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f,
0x12, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72,
0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e,
0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x22,
0x00, 0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x70,
0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -742,7 +660,7 @@ func file_proto_provider_plugin_proto_rawDescGZIP() []byte {
return file_proto_provider_plugin_proto_rawDescData
}
var file_proto_provider_plugin_proto_msgTypes = make([]protoimpl.MessageInfo, 12)
var file_proto_provider_plugin_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
var file_proto_provider_plugin_proto_goTypes = []interface{}{
(*InitReq)(nil), // 0: proto.InitReq
(*GetTokenReq)(nil), // 1: proto.GetTokenReq
@ -755,29 +673,27 @@ var file_proto_provider_plugin_proto_goTypes = []interface{}{
(*GetUserInfoReq)(nil), // 8: proto.GetUserInfoReq
(*GetUserInfoResp)(nil), // 9: proto.GetUserInfoResp
(*Enpty)(nil), // 10: proto.Enpty
(*InitReq_Endpoint)(nil), // 11: proto.InitReq.Endpoint
}
var file_proto_provider_plugin_proto_depIdxs = []int32{
11, // 0: proto.InitReq.endpoint:type_name -> proto.InitReq.Endpoint
2, // 1: proto.RefreshTokenResp.token:type_name -> proto.Token
2, // 2: proto.GetUserInfoReq.token:type_name -> proto.Token
0, // 3: proto.Oauth2Plugin.Init:input_type -> proto.InitReq
10, // 4: proto.Oauth2Plugin.Provider:input_type -> proto.Enpty
6, // 5: proto.Oauth2Plugin.NewAuthURL:input_type -> proto.NewAuthURLReq
1, // 6: proto.Oauth2Plugin.GetToken:input_type -> proto.GetTokenReq
3, // 7: proto.Oauth2Plugin.RefreshToken:input_type -> proto.RefreshTokenReq
8, // 8: proto.Oauth2Plugin.GetUserInfo:input_type -> proto.GetUserInfoReq
10, // 9: proto.Oauth2Plugin.Init:output_type -> proto.Enpty
5, // 10: proto.Oauth2Plugin.Provider:output_type -> proto.ProviderResp
7, // 11: proto.Oauth2Plugin.NewAuthURL:output_type -> proto.NewAuthURLResp
2, // 12: proto.Oauth2Plugin.GetToken:output_type -> proto.Token
4, // 13: proto.Oauth2Plugin.RefreshToken:output_type -> proto.RefreshTokenResp
9, // 14: proto.Oauth2Plugin.GetUserInfo:output_type -> proto.GetUserInfoResp
9, // [9:15] is the sub-list for method output_type
3, // [3:9] is the sub-list for method input_type
3, // [3:3] is the sub-list for extension type_name
3, // [3:3] is the sub-list for extension extendee
0, // [0:3] is the sub-list for field type_name
2, // 0: proto.RefreshTokenResp.token:type_name -> proto.Token
2, // 1: proto.GetUserInfoReq.token:type_name -> proto.Token
0, // 2: proto.Oauth2Plugin.Init:input_type -> proto.InitReq
10, // 3: proto.Oauth2Plugin.Provider:input_type -> proto.Enpty
6, // 4: proto.Oauth2Plugin.NewAuthURL:input_type -> proto.NewAuthURLReq
1, // 5: proto.Oauth2Plugin.GetToken:input_type -> proto.GetTokenReq
3, // 6: proto.Oauth2Plugin.RefreshToken:input_type -> proto.RefreshTokenReq
8, // 7: proto.Oauth2Plugin.GetUserInfo:input_type -> proto.GetUserInfoReq
10, // 8: proto.Oauth2Plugin.Init:output_type -> proto.Enpty
5, // 9: proto.Oauth2Plugin.Provider:output_type -> proto.ProviderResp
7, // 10: proto.Oauth2Plugin.NewAuthURL:output_type -> proto.NewAuthURLResp
2, // 11: proto.Oauth2Plugin.GetToken:output_type -> proto.Token
4, // 12: proto.Oauth2Plugin.RefreshToken:output_type -> proto.RefreshTokenResp
9, // 13: proto.Oauth2Plugin.GetUserInfo:output_type -> proto.GetUserInfoResp
8, // [8:14] is the sub-list for method output_type
2, // [2:8] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
}
func init() { file_proto_provider_plugin_proto_init() }
@ -918,27 +834,14 @@ func file_proto_provider_plugin_proto_init() {
return nil
}
}
file_proto_provider_plugin_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*InitReq_Endpoint); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
file_proto_provider_plugin_proto_msgTypes[0].OneofWrappers = []interface{}{}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto_provider_plugin_proto_rawDesc,
NumEnums: 0,
NumMessages: 12,
NumMessages: 11,
NumExtensions: 0,
NumServices: 1,
},

@ -4,15 +4,9 @@ option go_package = ".;providerpb";
package proto;
message InitReq {
message Endpoint {
string auth_url = 1;
string device_auth_url = 2;
string token_url = 3;
}
string client_id = 1;
string client_secret = 2;
string redirect_url = 3;
optional Endpoint endpoint = 4;
}
message GetTokenReq { string code = 1; }

@ -4,6 +4,7 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/synctv-org/synctv/internal/bootstrap"
"github.com/synctv-org/synctv/internal/db"
dbModel "github.com/synctv-org/synctv/internal/model"
"github.com/synctv-org/synctv/internal/op"
@ -35,31 +36,45 @@ func EditAdminSettings(ctx *gin.Context) {
func AdminSettings(ctx *gin.Context) {
// user := ctx.MustGet("user").(*op.User)
group := ctx.Param("group")
if group == "" {
switch group {
case "oauth2":
resp := make(model.AdminSettingsResp, len(bootstrap.ProviderGroupSettings))
for k, v := range bootstrap.ProviderGroupSettings {
if resp[k] == nil {
resp[k] = make(gin.H, len(v))
}
for _, s2 := range v {
resp[k][s2.Name()] = s2.Interface()
}
}
ctx.JSON(http.StatusOK, model.NewApiDataResp(resp))
case "":
resp := make(model.AdminSettingsResp, len(settings.GroupSettings))
for sg, v := range settings.GroupSettings {
if resp[string(sg)] == nil {
resp[string(sg)] = make(gin.H, len(v))
if resp[sg] == nil {
resp[sg] = make(gin.H, len(v))
}
for _, s2 := range v {
resp[string(sg)][s2.Name()] = s2.Interface()
resp[sg][s2.Name()] = s2.Interface()
}
}
ctx.JSON(http.StatusOK, model.NewApiDataResp(resp))
return
}
default:
s, ok := settings.GroupSettings[dbModel.SettingGroup(group)]
if !ok {
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp("group not found"))
return
}
resp := make(gin.H, len(s))
for _, v := range s {
resp[v.Name()] = v.Interface()
}
s, ok := settings.GroupSettings[dbModel.SettingGroup(group)]
if !ok {
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp("group not found"))
return
}
resp := make(gin.H, len(s))
for _, v := range s {
resp[v.Name()] = v.Interface()
ctx.JSON(http.StatusOK, model.NewApiDataResp(resp))
}
ctx.JSON(http.StatusOK, model.NewApiDataResp(resp))
}
func Users(ctx *gin.Context) {

@ -7,6 +7,7 @@ import (
"github.com/synctv-org/synctv/internal/db"
dbModel "github.com/synctv-org/synctv/internal/model"
"github.com/synctv-org/synctv/internal/op"
"github.com/synctv-org/synctv/internal/provider"
"github.com/synctv-org/synctv/internal/provider/providers"
"github.com/synctv-org/synctv/server/middlewares"
"github.com/synctv-org/synctv/server/model"
@ -185,8 +186,9 @@ func UserBindProviders(ctx *gin.Context) {
m := providers.EnabledProvider()
resp := make(model.UserBindProviderResp, len(up))
for _, v := range up {
if _, ok := m[v.Provider]; ok {
if _, ok := m.Load(v.Provider); ok {
resp[v.Provider] = struct {
ProviderUserID string "json:\"providerUserID\""
CreatedAt int64 "json:\"createdAt\""
@ -197,7 +199,7 @@ func UserBindProviders(ctx *gin.Context) {
}
}
for p := range m {
m.Range(func(p provider.OAuth2Provider, pi provider.ProviderInterface) bool {
if _, ok := resp[p]; !ok {
resp[p] = struct {
ProviderUserID string "json:\"providerUserID\""
@ -207,7 +209,8 @@ func UserBindProviders(ctx *gin.Context) {
CreatedAt: 0,
}
}
}
return true
})
ctx.JSON(http.StatusOK, resp)
}

@ -22,7 +22,7 @@ func (asr *AdminSettingsReq) Decode(ctx *gin.Context) error {
return json.NewDecoder(ctx.Request.Body).Decode(asr)
}
type AdminSettingsResp map[string]map[string]any
type AdminSettingsResp map[dbModel.SettingGroup]map[string]any
type AddUserReq struct {
Username string `json:"username"`

@ -1,31 +1,39 @@
package auth
import (
"sync"
"net/http"
"time"
"github.com/gin-gonic/gin"
"github.com/synctv-org/synctv/internal/provider"
"github.com/synctv-org/synctv/internal/provider/providers"
"github.com/synctv-org/synctv/server/model"
"github.com/zijiren233/gencontainer/refreshcache"
"github.com/zijiren233/gencontainer/vec"
"golang.org/x/exp/maps"
)
var (
oauth2EnabledCache []provider.OAuth2Provider
oauth2EnabledOnce sync.Once
)
func OAuth2EnabledApi(ctx *gin.Context) {
oauth2EnabledOnce.Do(func() {
oauth2EnabledCache = maps.Keys(providers.EnabledProvider())
Oauth2EnabledCache = refreshcache.NewRefreshCache[[]provider.OAuth2Provider](func() ([]provider.OAuth2Provider, error) {
a := vec.New[provider.OAuth2Provider](vec.WithCmpEqual[provider.OAuth2Provider](func(v1, v2 provider.OAuth2Provider) bool {
return v1 == v2
}), vec.WithCmpLess[provider.OAuth2Provider](func(v1, v2 provider.OAuth2Provider) bool {
return v1 < v2
}))
a.Push(oauth2EnabledCache...).SortStable().Slice()
})
providers.EnabledProvider().Range(func(key provider.OAuth2Provider, value provider.ProviderInterface) bool {
a.Push(key)
return true
})
return a.SortStable().Slice(), nil
}, time.Hour)
)
func OAuth2EnabledApi(ctx *gin.Context) {
data, err := Oauth2EnabledCache.Get()
if err != nil {
ctx.AbortWithStatusJSON(http.StatusInternalServerError, model.NewApiErrorResp(err))
return
}
ctx.JSON(200, gin.H{
"enabled": oauth2EnabledCache,
"enabled": data,
})
}

Loading…
Cancel
Save