From 21204cacf092f2200c87557cbf4065da0cc6cef1 Mon Sep 17 00:00:00 2001 From: zijiren233 Date: Tue, 26 Dec 2023 20:23:04 +0800 Subject: [PATCH] Feat: emby logout --- go.mod | 2 +- go.sum | 4 ++-- internal/vendor/emby.go | 4 ++++ server/handlers/vendors/vendorEmby/login.go | 13 +++++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d9680d2..b564e91 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/sirupsen/logrus v1.9.3 github.com/soheilhy/cmux v0.1.5 github.com/spf13/cobra v1.8.0 - github.com/synctv-org/vendors v0.2.2-0.20231226084816-6cd79508ca08 + github.com/synctv-org/vendors v0.2.2-0.20231226121731-35912737bbb2 github.com/ulule/limiter/v3 v3.11.2 github.com/zencoder/go-dash/v3 v3.0.3 github.com/zijiren233/gencontainer v0.0.0-20231213075414-f7f4c8261dca diff --git a/go.sum b/go.sum index ec2e30d..a620ef9 100644 --- a/go.sum +++ b/go.sum @@ -350,8 +350,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/synctv-org/vendors v0.2.2-0.20231226084816-6cd79508ca08 h1:jJ1xn6EInG8u02YUKDioF36Y9ab9IC9eA0Z3lQ8o7FU= -github.com/synctv-org/vendors v0.2.2-0.20231226084816-6cd79508ca08/go.mod h1:Q+KEUh8ZgCSMjY5rCfz44+7POlHcGttZ/bYFiTDVBds= +github.com/synctv-org/vendors v0.2.2-0.20231226121731-35912737bbb2 h1:c9R7idpWvnqKvMxGkzQvJMoQ8os1shy+rgaawjk6xKw= +github.com/synctv-org/vendors v0.2.2-0.20231226121731-35912737bbb2/go.mod h1:Q+KEUh8ZgCSMjY5rCfz44+7POlHcGttZ/bYFiTDVBds= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= diff --git a/internal/vendor/emby.go b/internal/vendor/emby.go index a193409..5fe7275 100644 --- a/internal/vendor/emby.go +++ b/internal/vendor/emby.go @@ -71,6 +71,10 @@ func (e *grpcEmby) Login(ctx context.Context, req *emby.LoginReq) (*emby.LoginRe return e.client.Login(ctx, req) } +func (e *grpcEmby) Logout(ctx context.Context, req *emby.LogoutReq) (*emby.Empty, error) { + return e.client.Logout(ctx, req) +} + func (e *grpcEmby) Me(ctx context.Context, req *emby.MeReq) (*emby.MeResp, error) { return e.client.Me(ctx, req) } diff --git a/server/handlers/vendors/vendorEmby/login.go b/server/handlers/vendors/vendorEmby/login.go index 8e2f50d..7aa41c9 100644 --- a/server/handlers/vendors/vendorEmby/login.go +++ b/server/handlers/vendors/vendorEmby/login.go @@ -107,7 +107,20 @@ func Logout(ctx *gin.Context) { return } + eucd := user.EmbyCache().Raw() user.EmbyCache().Clear() + go logoutEmby(eucd) + ctx.Status(http.StatusNoContent) } + +func logoutEmby(eucd *cache.EmbyUserCacheData) { + if eucd == nil || eucd.ApiKey == "" { + return + } + _, _ = vendor.LoadEmbyClient(eucd.Backend).Logout(context.Background(), &emby.LogoutReq{ + Host: eucd.Host, + Token: eucd.ApiKey, + }) +}