0.1.38 gateway

This commit is contained in:
ponzischeme89
2026-08-14 09:40:03 +12:00
parent abc392d30b
commit 5e2ed3d12e
2847 changed files with 1072928 additions and 3783 deletions
+27
View File
@@ -18,6 +18,33 @@ type MediaRequest struct {
RequestedAt time.Time `json:"requestedAt"`
}
// RequestUsage is the operator-facing use of the request feature. A recorded request is
// one that Memby has already handed to Radarr or Sonarr; their later download state is
// deliberately not duplicated here.
type RequestUsage struct {
UserID string `json:"userId"`
Requests int64 `json:"requests"`
LastRequest time.Time `json:"lastRequest,omitempty"`
}
func (s *Store) RequestUsage(ctx context.Context) ([]RequestUsage, error) {
rows, err := s.pool.Query(ctx, `SELECT emby_user_id, count(*), max(requested_at)
FROM media_requests GROUP BY emby_user_id`)
if err != nil {
return nil, fmt.Errorf("store: request usage: %w", err)
}
defer rows.Close()
out := []RequestUsage{}
for rows.Next() {
var value RequestUsage
if err := rows.Scan(&value.UserID, &value.Requests, &value.LastRequest); err != nil {
return nil, err
}
out = append(out, value)
}
return out, rows.Err()
}
// MediaRequestLimit caps what one viewer's page will read back. A household that has been
// asking for things for two years should not turn the page into an unbounded query, and
// nobody scrolls past the most recent hundred by remote.