correctly distinguish user/pass auth errors from other connectivity errors again
This commit is contained in:
@@ -23,6 +23,17 @@ type JellyfinServer struct {
|
||||
jellyfin.Client
|
||||
}
|
||||
|
||||
func (j *JellyfinServer) Login(user, pass string) mediaprovider.LoginResponse {
|
||||
if _, err := j.Ping(); err != nil {
|
||||
return mediaprovider.LoginResponse{Error: err}
|
||||
}
|
||||
err := j.Client.Login(user, pass)
|
||||
return mediaprovider.LoginResponse{
|
||||
Error: err,
|
||||
IsAuthError: err != nil,
|
||||
}
|
||||
}
|
||||
|
||||
func (j *JellyfinServer) MediaProvider() mediaprovider.MediaProvider {
|
||||
return newJellyfinMediaProvider(&j.Client)
|
||||
}
|
||||
|
||||
@@ -61,8 +61,13 @@ type Favorites struct {
|
||||
Tracks []*Track
|
||||
}
|
||||
|
||||
type LoginResponse struct {
|
||||
Error error
|
||||
IsAuthError bool
|
||||
}
|
||||
|
||||
type Server interface {
|
||||
Login(username, password string) error
|
||||
Login(username, password string) LoginResponse
|
||||
MediaProvider() MediaProvider
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,13 @@ type SubsonicServer struct {
|
||||
subsonicCli.Client
|
||||
}
|
||||
|
||||
func (s *SubsonicServer) Login(username, password string) error {
|
||||
func (s *SubsonicServer) Login(username, password string) mediaprovider.LoginResponse {
|
||||
s.User = username
|
||||
return s.Client.Authenticate(password)
|
||||
err := s.Client.Authenticate(password)
|
||||
return mediaprovider.LoginResponse{
|
||||
Error: err,
|
||||
IsAuthError: err == subsonicCli.ErrAuthenticationFailure,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SubsonicServer) MediaProvider() mediaprovider.MediaProvider {
|
||||
|
||||
@@ -199,12 +199,16 @@ func (s *ServerManager) connect(connection ServerConnection, password string) (m
|
||||
},
|
||||
}
|
||||
}
|
||||
var authError error
|
||||
pingChan := make(chan bool, 2) // false for primary hostname, true for alternate
|
||||
pingFunc := func(delay time.Duration, cli mediaprovider.Server, val bool) {
|
||||
<-time.After(delay)
|
||||
if err := cli.Login(connection.Username, password); err == nil {
|
||||
pingChan <- val
|
||||
resp := cli.Login(connection.Username, password)
|
||||
if resp.Error != nil && !resp.IsAuthError {
|
||||
return
|
||||
}
|
||||
authError = resp.Error
|
||||
pingChan <- val // reached the server
|
||||
}
|
||||
go pingFunc(0, cli, false)
|
||||
if connection.AltHostname != "" {
|
||||
@@ -218,8 +222,8 @@ func (s *ServerManager) connect(connection ServerConnection, password string) (m
|
||||
return nil, ErrUnreachable
|
||||
case altPing := <-pingChan:
|
||||
if altPing {
|
||||
return altCli, nil
|
||||
return altCli, authError
|
||||
}
|
||||
return cli, nil
|
||||
return cli, authError
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ require (
|
||||
github.com/deluan/sanitize v0.0.0-20230310221930-6e18967d9fc1
|
||||
github.com/dweymouth/go-jellyfin v0.0.0-20231114014232-1e011bb03a9f
|
||||
github.com/dweymouth/go-mpv v0.0.0-20230406003141-7f1858e503ee
|
||||
github.com/dweymouth/go-subsonic v0.0.0-20231105161622-54b5aec28363
|
||||
github.com/dweymouth/go-subsonic v0.0.0-20231115012731-a3d1f90274c1
|
||||
github.com/fsnotify/fsnotify v1.6.0
|
||||
github.com/godbus/dbus/v5 v5.1.0
|
||||
github.com/google/uuid v1.3.0
|
||||
|
||||
@@ -75,8 +75,8 @@ github.com/dweymouth/go-jellyfin v0.0.0-20231114014232-1e011bb03a9f h1:sJY4MjrNa
|
||||
github.com/dweymouth/go-jellyfin v0.0.0-20231114014232-1e011bb03a9f/go.mod h1:BMwS4vdjEYf1gmjPGSKCzWP/I6YlI6fkefJ9nsjBjaU=
|
||||
github.com/dweymouth/go-mpv v0.0.0-20230406003141-7f1858e503ee h1:ZGyJ6wp7CAfT31BugypcF/TPKEy2RrGR9JFq1JOjOpY=
|
||||
github.com/dweymouth/go-mpv v0.0.0-20230406003141-7f1858e503ee/go.mod h1:Ov0ieN90M7i+0k3OxhA/g1dozGs+UcPHDsMKqPgRDk0=
|
||||
github.com/dweymouth/go-subsonic v0.0.0-20231105161622-54b5aec28363 h1:MIH7MAWWPPVRKEKxz+RJubn+ycyQPimHn1Zvoxs1KRI=
|
||||
github.com/dweymouth/go-subsonic v0.0.0-20231105161622-54b5aec28363/go.mod h1:dVriurACA/XTnE7BgSOTapYOtxMq7jTOVExrIbwi84c=
|
||||
github.com/dweymouth/go-subsonic v0.0.0-20231115012731-a3d1f90274c1 h1:1I5/hlV4lQ0B0NdBZvwWSqL8hvvKhRRbJK6fGsxFSLs=
|
||||
github.com/dweymouth/go-subsonic v0.0.0-20231115012731-a3d1f90274c1/go.mod h1:OWtcumdQsan8uM6wmx6PqKhldaCthH10CQ+vb+94kzo=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
|
||||
Reference in New Issue
Block a user