fix: refresh emby realtime user sessions

This commit is contained in:
ShukeBta
2026-06-25 00:36:41 +08:00
parent f49ef7f1df
commit 29f5df673c
6 changed files with 196 additions and 8 deletions
+29
View File
@@ -8,6 +8,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/ShukeBta/MediaStationGo/internal/middleware"
"github.com/ShukeBta/MediaStationGo/internal/service"
)
// embyError 返回 Emby 风格的错误(顶层 Code/Message)。
@@ -49,6 +50,34 @@ func embyAuthRequiredWithSessionFallback(secret string) gin.HandlerFunc {
}
}
func embyRealtimeSessionActivity(svc *service.Container) gin.HandlerFunc {
return func(c *gin.Context) {
if svc != nil && svc.Sessions != nil {
if uid := embyUserID(c); uid != "" {
clientInfo := embyClientInfoFromRequest(c)
svc.Sessions.RecordActivity(c.Request.Context(), uid, embyContextUserName(c),
clientInfo.DeviceID,
clientInfo.DeviceName,
clientInfo.Client,
c.ClientIP())
}
}
c.Next()
}
}
func embyContextUserName(c *gin.Context) string {
if c == nil {
return ""
}
if value, ok := c.Get(embyCtxUserName); ok {
if username, ok := value.(string); ok {
return strings.TrimSpace(username)
}
}
return ""
}
func embyRememberCompatSession(c *gin.Context, token string) {
token = strings.TrimSpace(token)
if token == "" {