models

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: GPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorTypeConnection     = "connection"
	ErrorTypeAuthentication = "authentication"
	ErrorTypeBan            = "ban"
	ErrorTypeAPI            = "api"
)

Error types for categorization

View Source
const (
	LicenseStatusActive  = "active"
	LicenseStatusInvalid = "invalid"
)

LicenseStatus constants

Variables

View Source
var ErrAPIKeyNotFound = errors.New("api key not found")
View Source
var ErrClientAPIKeyNotFound = errors.New("client api key not found")
View Source
var ErrInstanceNotFound = errors.New("instance not found")
View Source
var ErrInvalidAPIKey = errors.New("invalid api key")
View Source
var (
	ErrLicenseNotFound = errors.New("license not found")
)
View Source
var ErrUserAlreadyExists = errors.New("user already exists")
View Source
var ErrUserNotFound = errors.New("user not found")

Functions

func GenerateAPIKey

func GenerateAPIKey() (string, error)

GenerateAPIKey generates a new API key

func HashAPIKey

func HashAPIKey(key string) string

HashAPIKey creates a SHA256 hash of the API key

Types

type APIKey

type APIKey struct {
	ID         int        `json:"id"`
	KeyHash    string     `json:"-"`
	Name       string     `json:"name"`
	CreatedAt  time.Time  `json:"createdAt"`
	LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
}

type APIKeyStore

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

func NewAPIKeyStore

func NewAPIKeyStore(db dbinterface.Querier) *APIKeyStore

func (*APIKeyStore) Create

func (s *APIKeyStore) Create(ctx context.Context, name string) (string, *APIKey, error)

func (*APIKeyStore) Delete

func (s *APIKeyStore) Delete(ctx context.Context, id int) error

func (*APIKeyStore) GetByHash

func (s *APIKeyStore) GetByHash(ctx context.Context, keyHash string) (*APIKey, error)

func (*APIKeyStore) List

func (s *APIKeyStore) List(ctx context.Context) ([]*APIKey, error)

func (*APIKeyStore) UpdateLastUsed

func (s *APIKeyStore) UpdateLastUsed(ctx context.Context, id int) error

func (*APIKeyStore) ValidateAPIKey

func (s *APIKeyStore) ValidateAPIKey(ctx context.Context, rawKey string) (*APIKey, error)

ValidateAPIKey validates a raw API key and returns the associated APIKey if valid

type BackupItem added in v1.5.0

type BackupItem struct {
	ID              int64     `json:"id"`
	RunID           int64     `json:"runId"`
	TorrentHash     string    `json:"torrentHash"`
	Name            string    `json:"name"`
	Category        *string   `json:"category,omitempty"`
	SizeBytes       int64     `json:"sizeBytes"`
	ArchiveRelPath  *string   `json:"archiveRelPath,omitempty"`
	InfoHashV1      *string   `json:"infohashV1,omitempty"`
	InfoHashV2      *string   `json:"infohashV2,omitempty"`
	Tags            *string   `json:"tags,omitempty"`
	TorrentBlobPath *string   `json:"torrentBlobPath,omitempty"`
	CreatedAt       time.Time `json:"createdAt"`
}

type BackupRun added in v1.5.0

type BackupRun struct {
	ID             int64                       `json:"id"`
	InstanceID     int                         `json:"instanceId"`
	Kind           BackupRunKind               `json:"kind"`
	Status         BackupRunStatus             `json:"status"`
	RequestedBy    string                      `json:"requestedBy"`
	RequestedAt    time.Time                   `json:"requestedAt"`
	StartedAt      *time.Time                  `json:"startedAt,omitempty"`
	CompletedAt    *time.Time                  `json:"completedAt,omitempty"`
	ArchivePath    *string                     `json:"archivePath,omitempty"`
	ManifestPath   *string                     `json:"manifestPath,omitempty"`
	TotalBytes     int64                       `json:"totalBytes"`
	TorrentCount   int                         `json:"torrentCount"`
	CategoryCounts map[string]int              `json:"categoryCounts,omitempty"`
	ErrorMessage   *string                     `json:"errorMessage,omitempty"`
	Categories     map[string]CategorySnapshot `json:"categories,omitempty"`
	Tags           []string                    `json:"tags,omitempty"`
	// contains filtered or unexported fields
}

type BackupRunKind added in v1.5.0

type BackupRunKind string
const (
	BackupRunKindManual  BackupRunKind = "manual"
	BackupRunKindHourly  BackupRunKind = "hourly"
	BackupRunKindDaily   BackupRunKind = "daily"
	BackupRunKindWeekly  BackupRunKind = "weekly"
	BackupRunKindMonthly BackupRunKind = "monthly"
)

type BackupRunStatus added in v1.5.0

type BackupRunStatus string
const (
	BackupRunStatusPending  BackupRunStatus = "pending"
	BackupRunStatusRunning  BackupRunStatus = "running"
	BackupRunStatusSuccess  BackupRunStatus = "success"
	BackupRunStatusFailed   BackupRunStatus = "failed"
	BackupRunStatusCanceled BackupRunStatus = "canceled"
)

type BackupSettings added in v1.5.0

type BackupSettings struct {
	InstanceID        int       `json:"instanceId"`
	Enabled           bool      `json:"enabled"`
	HourlyEnabled     bool      `json:"hourlyEnabled"`
	DailyEnabled      bool      `json:"dailyEnabled"`
	WeeklyEnabled     bool      `json:"weeklyEnabled"`
	MonthlyEnabled    bool      `json:"monthlyEnabled"`
	KeepHourly        int       `json:"keepHourly"`
	KeepDaily         int       `json:"keepDaily"`
	KeepWeekly        int       `json:"keepWeekly"`
	KeepMonthly       int       `json:"keepMonthly"`
	IncludeCategories bool      `json:"includeCategories"`
	IncludeTags       bool      `json:"includeTags"`
	CustomPath        *string   `json:"customPath,omitempty"`
	CreatedAt         time.Time `json:"createdAt"`
	UpdatedAt         time.Time `json:"updatedAt"`
}

func DefaultBackupSettings added in v1.5.0

func DefaultBackupSettings(instanceID int) *BackupSettings

type BackupStore added in v1.5.0

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

func NewBackupStore added in v1.5.0

func NewBackupStore(db dbinterface.TxBeginner) *BackupStore

func (*BackupStore) CleanupRun added in v1.5.0

func (s *BackupStore) CleanupRun(ctx context.Context, runID int64) error

func (*BackupStore) CountBlobReferences added in v1.5.0

func (s *BackupStore) CountBlobReferences(ctx context.Context, relPath string) (int, error)

func (*BackupStore) CountRunsByKind added in v1.5.0

func (s *BackupStore) CountRunsByKind(ctx context.Context, instanceID int, kind BackupRunKind) (int, error)

func (*BackupStore) CreateRun added in v1.5.0

func (s *BackupStore) CreateRun(ctx context.Context, run *BackupRun) error

func (*BackupStore) DeleteItemsByRunIDs added in v1.5.0

func (s *BackupStore) DeleteItemsByRunIDs(ctx context.Context, runIDs []int64) error

func (*BackupStore) DeleteRun added in v1.5.0

func (s *BackupStore) DeleteRun(ctx context.Context, runID int64) error

func (*BackupStore) DeleteRunsByIDs added in v1.5.0

func (s *BackupStore) DeleteRunsByIDs(ctx context.Context, runIDs []int64) error

func (*BackupStore) DeleteRunsOlderThan added in v1.5.0

func (s *BackupStore) DeleteRunsOlderThan(ctx context.Context, instanceID int, kind BackupRunKind, keep int) ([]int64, error)

func (*BackupStore) FindCachedTorrentBlob added in v1.5.0

func (s *BackupStore) FindCachedTorrentBlob(ctx context.Context, instanceID int, hash string) (*string, error)

func (*BackupStore) FindIncompleteRuns added in v1.6.0

func (s *BackupStore) FindIncompleteRuns(ctx context.Context) ([]*BackupRun, error)

FindIncompleteRuns returns all backup runs that are in pending or running status. These are runs that were interrupted by a restart or crash.

func (*BackupStore) GetInstanceName added in v1.5.0

func (s *BackupStore) GetInstanceName(ctx context.Context, instanceID int) (string, error)

func (*BackupStore) GetItemByHash added in v1.5.0

func (s *BackupStore) GetItemByHash(ctx context.Context, runID int64, hash string) (*BackupItem, error)

func (*BackupStore) GetRun added in v1.5.0

func (s *BackupStore) GetRun(ctx context.Context, runID int64) (*BackupRun, error)

func (*BackupStore) GetSettings added in v1.5.0

func (s *BackupStore) GetSettings(ctx context.Context, instanceID int) (*BackupSettings, error)

func (*BackupStore) InsertItems added in v1.5.0

func (s *BackupStore) InsertItems(ctx context.Context, runID int64, items []BackupItem) error

func (*BackupStore) LatestRunByKind added in v1.5.0

func (s *BackupStore) LatestRunByKind(ctx context.Context, instanceID int, kind BackupRunKind) (*BackupRun, error)

func (*BackupStore) ListEnabledSettings added in v1.5.0

func (s *BackupStore) ListEnabledSettings(ctx context.Context) ([]*BackupSettings, error)

func (*BackupStore) ListItems added in v1.5.0

func (s *BackupStore) ListItems(ctx context.Context, runID int64) ([]*BackupItem, error)

func (*BackupStore) ListRunIDs added in v1.5.0

func (s *BackupStore) ListRunIDs(ctx context.Context, instanceID int) ([]int64, error)

func (*BackupStore) ListRuns added in v1.5.0

func (s *BackupStore) ListRuns(ctx context.Context, instanceID int, limit, offset int) ([]*BackupRun, error)

func (*BackupStore) ListRunsByKind added in v1.5.0

func (s *BackupStore) ListRunsByKind(ctx context.Context, instanceID int, kind BackupRunKind, limit int) ([]*BackupRun, error)

func (*BackupStore) RemoveFailedRunsBefore added in v1.5.0

func (s *BackupStore) RemoveFailedRunsBefore(ctx context.Context, cutoff time.Time) (int64, error)

RemoveFailedRunsBefore deletes failed runs older than the provided cutoff and returns the number of rows affected.

func (*BackupStore) UpdateRunMetadata added in v1.5.0

func (s *BackupStore) UpdateRunMetadata(ctx context.Context, runID int64, updateFn func(*BackupRun) error) error

func (*BackupStore) UpsertSettings added in v1.5.0

func (s *BackupStore) UpsertSettings(ctx context.Context, settings *BackupSettings) error

type CategorySnapshot added in v1.5.0

type CategorySnapshot struct {
	SavePath string `json:"savePath,omitempty"`
}

type ClientAPIKey added in v1.0.0

type ClientAPIKey struct {
	ID         int        `json:"id"`
	KeyHash    string     `json:"-"`
	ClientName string     `json:"clientName"`
	InstanceID int        `json:"instanceId"`
	CreatedAt  time.Time  `json:"createdAt"`
	LastUsedAt *time.Time `json:"lastUsedAt,omitempty"`
}

type ClientAPIKeyStore added in v1.0.0

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

func NewClientAPIKeyStore added in v1.0.0

func NewClientAPIKeyStore(db dbinterface.Querier) *ClientAPIKeyStore

func (*ClientAPIKeyStore) Create added in v1.0.0

func (s *ClientAPIKeyStore) Create(ctx context.Context, clientName string, instanceID int) (string, *ClientAPIKey, error)

func (*ClientAPIKeyStore) Delete added in v1.0.0

func (s *ClientAPIKeyStore) Delete(ctx context.Context, id int) error

func (*ClientAPIKeyStore) DeleteByInstanceID added in v1.0.0

func (s *ClientAPIKeyStore) DeleteByInstanceID(ctx context.Context, instanceID int) error

func (*ClientAPIKeyStore) GetAll added in v1.0.0

func (s *ClientAPIKeyStore) GetAll(ctx context.Context) ([]*ClientAPIKey, error)

func (*ClientAPIKeyStore) GetByKeyHash added in v1.0.0

func (s *ClientAPIKeyStore) GetByKeyHash(ctx context.Context, keyHash string) (*ClientAPIKey, error)

func (*ClientAPIKeyStore) UpdateLastUsed added in v1.0.0

func (s *ClientAPIKeyStore) UpdateLastUsed(ctx context.Context, keyHash string) error

func (*ClientAPIKeyStore) ValidateKey added in v1.0.0

func (s *ClientAPIKeyStore) ValidateKey(ctx context.Context, rawKey string) (*ClientAPIKey, error)

type Instance

type Instance struct {
	ID                     int     `json:"id"`
	Name                   string  `json:"name"`
	Host                   string  `json:"host"`
	Username               string  `json:"username"`
	PasswordEncrypted      string  `json:"-"`
	BasicUsername          *string `json:"basic_username,omitempty"`
	BasicPasswordEncrypted *string `json:"-"`
	TLSSkipVerify          bool    `json:"tlsSkipVerify"`
}

func (Instance) MarshalJSON added in v1.0.0

func (i Instance) MarshalJSON() ([]byte, error)

func (*Instance) UnmarshalJSON added in v1.0.0

func (i *Instance) UnmarshalJSON(data []byte) error

type InstanceError added in v1.0.0

type InstanceError struct {
	ID           int       `json:"id"`
	InstanceID   int       `json:"instanceId"`
	ErrorType    string    `json:"errorType"`
	ErrorMessage string    `json:"errorMessage"`
	OccurredAt   time.Time `json:"occurredAt"`
}

type InstanceErrorStore added in v1.0.0

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

func NewInstanceErrorStore added in v1.0.0

func NewInstanceErrorStore(db dbinterface.Querier) *InstanceErrorStore

func (*InstanceErrorStore) ClearErrors added in v1.0.0

func (s *InstanceErrorStore) ClearErrors(ctx context.Context, instanceID int) error

ClearErrors removes all errors for an instance (called on successful connection)

func (*InstanceErrorStore) GetRecentErrors added in v1.0.0

func (s *InstanceErrorStore) GetRecentErrors(ctx context.Context, instanceID int, limit int) ([]InstanceError, error)

GetRecentErrors retrieves the last N errors for an instance

func (*InstanceErrorStore) RecordError added in v1.0.0

func (s *InstanceErrorStore) RecordError(ctx context.Context, instanceID int, err error) error

RecordError stores an error for an instance with simple deduplication

type InstanceStore

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

func NewInstanceStore

func NewInstanceStore(db dbinterface.Querier, encryptionKey []byte) (*InstanceStore, error)

func (*InstanceStore) Create

func (s *InstanceStore) Create(ctx context.Context, name, rawHost, username, password string, basicUsername, basicPassword *string, tlsSkipVerify bool) (*Instance, error)

func (*InstanceStore) Delete

func (s *InstanceStore) Delete(ctx context.Context, id int) error

func (*InstanceStore) Get

func (s *InstanceStore) Get(ctx context.Context, id int) (*Instance, error)

func (*InstanceStore) GetDecryptedBasicPassword

func (s *InstanceStore) GetDecryptedBasicPassword(instance *Instance) (*string, error)

GetDecryptedBasicPassword returns the decrypted basic auth password for an instance

func (*InstanceStore) GetDecryptedPassword

func (s *InstanceStore) GetDecryptedPassword(instance *Instance) (string, error)

GetDecryptedPassword returns the decrypted password for an instance

func (*InstanceStore) List

func (s *InstanceStore) List(ctx context.Context) ([]*Instance, error)

func (*InstanceStore) Update

func (s *InstanceStore) Update(ctx context.Context, id int, name, rawHost, username, password string, basicUsername, basicPassword *string, tlsSkipVerify *bool) (*Instance, error)

type LicenseInfo added in v1.0.0

type LicenseInfo struct {
	Key          string     `json:"key"`
	ProductName  string     `json:"productName"`
	CustomerID   string     `json:"customerId"`
	ProductID    string     `json:"productId"`
	ExpiresAt    *time.Time `json:"expiresAt,omitempty"`
	Valid        bool       `json:"valid"`
	ErrorMessage string     `json:"errorMessage,omitempty"`
}

LicenseInfo contains license validation information

type ProductLicense added in v1.0.0

type ProductLicense struct {
	ID                int        `json:"id"`
	LicenseKey        string     `json:"licenseKey"`
	ProductName       string     `json:"productName"`
	Status            string     `json:"status"`
	ActivatedAt       time.Time  `json:"activatedAt"`
	ExpiresAt         *time.Time `json:"expiresAt,omitempty"`
	LastValidated     time.Time  `json:"lastValidated"`
	PolarCustomerID   *string    `json:"polarCustomerId,omitempty"`
	PolarProductID    *string    `json:"polarProductId,omitempty"`
	PolarActivationID string     `json:"polarActivationId,omitempty"`
	Username          string     `json:"username"`
	CreatedAt         time.Time  `json:"createdAt"`
	UpdatedAt         time.Time  `json:"updatedAt"`
}

ProductLicense represents a product license in the database

type User

type User struct {
	ID           int    `json:"id"`
	Username     string `json:"username"`
	PasswordHash string `json:"-"`
}

type UserStore

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

func NewUserStore

func NewUserStore(db dbinterface.Querier) *UserStore

func (*UserStore) Create

func (s *UserStore) Create(ctx context.Context, username, passwordHash string) (*User, error)

func (*UserStore) Exists

func (s *UserStore) Exists(ctx context.Context) (bool, error)

func (*UserStore) Get

func (s *UserStore) Get(ctx context.Context) (*User, error)

func (*UserStore) GetByUsername

func (s *UserStore) GetByUsername(ctx context.Context, username string) (*User, error)

func (*UserStore) UpdatePassword

func (s *UserStore) UpdatePassword(ctx context.Context, passwordHash string) error

Jump to

Keyboard shortcuts

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