This commit is contained in:
ponzischeme89
2026-08-24 22:56:46 +12:00
parent 4f95767e2f
commit 396d35e2f5
48 changed files with 1541 additions and 672 deletions
+25 -2
View File
@@ -50,6 +50,7 @@ type KnownClient struct {
Protocol string `json:"protocol"`
Capabilities []string `json:"capabilities"`
LastSeen time.Time `json:"lastSeen"`
LastIP string `json:"lastIp"`
Versions []DeviceVersion `json:"versions"`
}
@@ -91,6 +92,8 @@ type MembyAccount struct {
LastSeen time.Time `json:"lastSeen"`
Devices []MembyDevice `json:"devices"`
RecommendationPreferences json.RawMessage `json:"-"`
Enabled bool `json:"enabled"`
LastIP string `json:"lastIp"`
}
type MembyDevice struct {
@@ -101,6 +104,7 @@ type MembyDevice struct {
Capabilities []string `json:"capabilities"`
SignedInAt time.Time `json:"signedInAt"`
LastSeen time.Time `json:"lastSeen"`
LastIP string `json:"lastIp"`
Versions []DeviceVersion `json:"versions"`
}
@@ -110,9 +114,21 @@ func (s *Store) MembyAccounts(ctx context.Context) ([]MembyAccount, error) {
rows, err := s.pool.Query(ctx, `
SELECT s.emby_user_id, s.username, s.device_id, s.device_name,
s.client_version, s.client_protocol, s.client_capabilities,
s.created_at, s.last_seen_at, COALESCE(o.preferences, '{}'::jsonb)
s.created_at, s.last_seen_at, COALESCE(o.preferences, '{}'::jsonb),
COALESCE(c.enabled, true), COALESCE(ip.address, ''), COALESCE(dip.address, '')
FROM sessions s
LEFT JOIN recommendation_onboarding o ON o.emby_user_id = s.emby_user_id
LEFT JOIN user_controls c ON c.emby_user_id = s.emby_user_id
LEFT JOIN LATERAL (
SELECT ip_address AS address FROM login_events
WHERE emby_user_id = s.emby_user_id AND success AND ip_address <> ''
ORDER BY occurred_at DESC, id DESC LIMIT 1
) ip ON true
LEFT JOIN LATERAL (
SELECT ip_address AS address FROM login_events
WHERE device_id = s.device_id AND success AND ip_address <> ''
ORDER BY occurred_at DESC, id DESC LIMIT 1
) dip ON true
ORDER BY s.last_seen_at DESC, s.emby_user_id, s.device_name`)
if err != nil {
return nil, fmt.Errorf("store: list Memby accounts: %w", err)
@@ -125,10 +141,12 @@ func (s *Store) MembyAccounts(ctx context.Context) ([]MembyAccount, error) {
var userID, username string
var device MembyDevice
var preferences []byte
var accountsEnabled bool
var lastIP string
if err := rows.Scan(
&userID, &username, &device.ID, &device.Name, &device.Version,
&device.Protocol, &device.Capabilities, &device.SignedInAt,
&device.LastSeen, &preferences,
&device.LastSeen, &preferences, &accountsEnabled, &lastIP, &device.LastIP,
); err != nil {
return nil, fmt.Errorf("store: scan Memby account: %w", err)
}
@@ -140,9 +158,14 @@ func (s *Store) MembyAccounts(ctx context.Context) ([]MembyAccount, error) {
ID: userID, Username: username, CreatedAt: device.SignedInAt,
LastSeen: device.LastSeen, Devices: []MembyDevice{},
RecommendationPreferences: json.RawMessage(preferences),
Enabled: accountsEnabled, LastIP: lastIP,
})
}
account := &accounts[index]
account.Enabled = accountsEnabled
if account.LastIP == "" {
account.LastIP = lastIP
}
if device.SignedInAt.Before(account.CreatedAt) {
account.CreatedAt = device.SignedInAt
}