api

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version   = "1.0.0"
	BuildTime = "unknown"
	GoVersion = runtime.Version()
)

Set at build time via -ldflags

Functions

func GetFormatRank added in v1.0.0

func GetFormatRank(format string, ranking []string) int

GetFormatRank returns the rank index of a format in the quality profile. Lower rank = better. Returns -1 if not found.

func RateLimitMiddleware

func RateLimitMiddleware(rl *RateLimiter, next http.Handler) http.Handler

RateLimitMiddleware wraps an HTTP handler with rate limiting.

Types

type ExportEnvelope added in v1.0.0

type ExportEnvelope struct {
	Version    string      `json:"version"`
	ExportedAt string      `json:"exported_at"`
	ItemCount  int         `json:"item_count"`
	Items      interface{} `json:"items"`
}

ExportEnvelope wraps exported data with metadata.

type MetricsCollector

type MetricsCollector struct {
	// contains filtered or unexported fields
}

MetricsCollector tracks simple counters for Prometheus exposition.

func NewMetricsCollector

func NewMetricsCollector() *MetricsCollector

NewMetricsCollector creates a new metrics collector.

func (*MetricsCollector) Inc

func (m *MetricsCollector) Inc(name string, labels map[string]string)

Inc increments a counter.

type OIDCHandler

type OIDCHandler struct {
	// contains filtered or unexported fields
}

OIDCHandler manages OIDC authentication flow.

func NewOIDCHandler

func NewOIDCHandler(cfg *config.Config, database *db.DB, sessions *SessionStore) *OIDCHandler

NewOIDCHandler initializes the OIDC provider and returns a handler. Returns nil if OIDC is not configured.

func (*OIDCHandler) HandleCallback

func (h *OIDCHandler) HandleCallback(w http.ResponseWriter, r *http.Request)

HandleCallback handles the OIDC provider callback.

func (*OIDCHandler) HandleLogin

func (h *OIDCHandler) HandleLogin(w http.ResponseWriter, r *http.Request)

HandleLogin redirects to the OIDC provider.

type PendingTOTP

type PendingTOTP struct {
	UserID int64
	Expiry time.Time
}

PendingTOTP holds a pending TOTP verification.

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter is an in-memory per-IP rate limiter with per-route rules.

func NewRateLimiter

func NewRateLimiter(windowSec int, rules map[string]int) *RateLimiter

NewRateLimiter creates a rate limiter with the given window and rules.

func (*RateLimiter) Check

func (rl *RateLimiter) Check(identity, path string) (allowed bool, retryAfter int, rule string, limit int)

Check returns whether a request is allowed and rate limit info.

type ScannedFile added in v1.0.0

type ScannedFile struct {
	Path   string `json:"path"`
	Name   string `json:"name"`
	Size   int64  `json:"size"`
	Format string `json:"format"`
	Title  string `json:"title"`
	Author string `json:"author"`
}

ScannedFile represents a file found during directory scan.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server holds the API dependencies.

func NewServer

func NewServer(cfg *config.Config, database *db.DB, searchMgr *search.Manager, downloadMgr *download.Manager, qb *download.QBittorrentClient, sab *download.SABnzbdClient, organizer *organize.Organizer, targets *organize.LibraryTargets) *Server

NewServer creates the HTTP API server.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the HTTP handler with middleware.

func (*Server) StartScheduler added in v1.0.0

func (s *Server) StartScheduler(ctx context.Context)

StartScheduler starts the background scheduler loop.

type SessionData

type SessionData struct {
	UserID   int64
	Username string
	Role     string
	Expiry   time.Time
}

SessionData holds session metadata.

type SessionStore

type SessionStore struct {
	// contains filtered or unexported fields
}

SessionStore manages session-based authentication with user tracking.

func NewSessionStore

func NewSessionStore() *SessionStore

NewSessionStore creates a new session store.

func (*SessionStore) Create

func (s *SessionStore) Create(userID int64, username, role string) string

Create generates a new session token for a user, valid for 24 hours.

func (*SessionStore) CreatePendingTOTP

func (s *SessionStore) CreatePendingTOTP(userID int64) string

CreatePendingTOTP creates a temporary token for TOTP verification (5 min expiry).

func (*SessionStore) Delete

func (s *SessionStore) Delete(token string)

Delete removes a session.

func (*SessionStore) Get

func (s *SessionStore) Get(token string) (*SessionData, bool)

Get retrieves session data if the token is valid.

func (*SessionStore) Valid

func (s *SessionStore) Valid(token string) bool

Valid checks if a session token is valid and not expired (backward compat).

func (*SessionStore) ValidatePendingTOTP

func (s *SessionStore) ValidatePendingTOTP(token string) (int64, bool)

ValidatePendingTOTP checks and consumes a pending TOTP token.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL