webserver

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: GPL-2.0 Imports: 50 Imported by: 0

Documentation

Index

Constants

AuthFileName is the canonical web auth file name stored beside the database.

View Source
const AuthPasswordMinLength = authmaterial.AuthPasswordMinLength

AuthPasswordMinLength defines the minimum web auth password length.

Variables

This section is empty.

Functions

func AuthFilePath

func AuthFilePath(dbPath string) string

AuthFilePath returns the auth file path colocated with dbPath.

func BootstrapAuthFile

func BootstrapAuthFile(dbPath string, username string, password string) error

BootstrapAuthFile creates the canonical auth file beside dbPath.

func SaveCLIConfig

func SaveCLIConfig(dbPath string, cfg CLIConfig) error

Types

type Backend

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

Backend owns the embedded web API runtime and request-scoped background jobs.

func NewBackend

func NewBackend(cfg config.Config, hub *eventHub) (*Backend, error)

NewBackend constructs a Backend using a background context.

func NewBackendWithContext

func NewBackendWithContext(ctx context.Context, cfg config.Config, hub *eventHub) (*Backend, error)

NewBackendWithContext opens the shared repository, creates the logger, and starts the core service when cfg validates. Invalid config keeps settings routes usable while core-backed routes report the initialization error.

func (*Backend) BrowseDirectory

func (b *Backend) BrowseDirectory(path string, mode string) (api.BrowseDirectoryResponse, error)

func (*Backend) BrowseDirectoryWithinRoot

func (b *Backend) BrowseDirectoryWithinRoot(path string, mode string, root string) (api.BrowseDirectoryResponse, error)

func (*Backend) BrowseDirectoryWithinRoots

func (b *Backend) BrowseDirectoryWithinRoots(path string, mode string, roots []string) (api.BrowseDirectoryResponse, error)

func (*Backend) CancelDupeCheck

func (b *Backend) CancelDupeCheck(sessionID string, jobID string) error

CancelDupeCheck requests cancellation only for a dupe job owned by sessionID.

func (*Backend) CancelTrackerUpload

func (b *Backend) CancelTrackerUpload(sessionID string, jobID string) error

CancelTrackerUpload requests cancellation only for an upload job owned by sessionID.

func (*Backend) CheckDupes

func (b *Backend) CheckDupes(path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, trackersList []string) (api.DupeCheckSummary, error)

func (*Backend) Close

func (b *Backend) Close() error

Close stops active background work and releases runtime, repository, and log resources.

func (*Backend) DeleteHistoryRelease

func (b *Backend) DeleteHistoryRelease(sourcePath string) error

func (*Backend) DeleteScreenshot

func (b *Backend) DeleteScreenshot(path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, imagePath string) error

func (*Backend) DeleteTrackerImageURL

func (b *Backend) DeleteTrackerImageURL(path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, imageURL string) error

func (*Backend) DeleteUploadedImage

func (b *Backend) DeleteUploadedImage(path string, imagePath string, host string) error

func (*Backend) DetectDiscType

func (b *Backend) DetectDiscType(ctx context.Context, path string) (string, error)

func (*Backend) DiscoverPlaylists

func (b *Backend) DiscoverPlaylists(path string) ([]api.PlaylistInfo, error)

func (*Backend) ExportConfig

func (b *Backend) ExportConfig() (string, error)

ExportConfig returns the exportable config, using plaintext secrets only when auth material for the exported snapshot's DB path explicitly allows unencrypted export.

func (*Backend) FetchDescriptionBuilder

func (b *Backend) FetchDescriptionBuilder(path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, trackersList []string, ignoreDupesFor []string) (api.DescriptionBuilderPreview, error)

func (*Backend) FetchMetadata

func (b *Backend) FetchMetadata(sessionID string, path string, sourceLookupURL string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, trackersList []string, confirmBDMVRescan bool) (api.MetadataPreview, error)

func (*Backend) FetchPreparation

func (b *Backend) FetchPreparation(sessionID string, path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, trackersList []string, ignoreDupesFor []string) (api.PreparationPreview, error)

func (*Backend) FetchScreenshotPlan

func (b *Backend) FetchScreenshotPlan(path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides) (api.ScreenshotPlan, error)

func (*Backend) FetchTrackerDryRun

func (b *Backend) FetchTrackerDryRun(sessionID string, path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, trackersList []string, ignoreDupesFor []string, questionnaireAnswers map[string]map[string]string, descriptionGroups []api.DescriptionBuilderGroup, debug bool, noSeed bool, runLogLevel string) (api.TrackerDryRunPreview, error)

func (*Backend) GenerateScreenshots

func (b *Backend) GenerateScreenshots(path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, selections []api.ScreenshotSelection, purpose api.ScreenshotPurpose) (api.ScreenshotResult, error)

func (*Backend) GetApplicationInfo

func (b *Backend) GetApplicationInfo() (api.ApplicationInfo, error)

func (*Backend) GetConfig

func (b *Backend) GetConfig() (string, error)

GetConfig returns the current exportable config as JSON with encrypted secret fields for browser settings consumers.

func (*Backend) GetDefaultConfig

func (b *Backend) GetDefaultConfig() (string, error)

func (*Backend) GetDupeCheckSnapshot

func (b *Backend) GetDupeCheckSnapshot(sessionID string, jobID string) (DupeCheckSnapshot, error)

GetDupeCheckSnapshot returns a dupe job snapshot only to the session that started the job.

func (*Backend) GetHistoryOverview

func (b *Backend) GetHistoryOverview(sourcePath string) (api.HistoryOverview, error)

func (*Backend) GetImageHostPolicyMetadata

func (b *Backend) GetImageHostPolicyMetadata() (imagehostpolicy.Metadata, error)

func (*Backend) GetLogExclusions

func (b *Backend) GetLogExclusions() ([]string, error)

func (*Backend) GetLogPath

func (b *Backend) GetLogPath() (string, error)

func (*Backend) GetRecentLogs

func (b *Backend) GetRecentLogs(limit int) ([]logging.Entry, error)

func (*Backend) GetTrackerUploadSnapshot

func (b *Backend) GetTrackerUploadSnapshot(sessionID string, jobID string) (TrackerUploadSnapshot, error)

GetTrackerUploadSnapshot returns an upload job snapshot only to the session that started the job.

func (*Backend) ImportConfig

func (b *Backend) ImportConfig(fileName, fileContent string) (string, []string, error)

ImportConfig imports browser-uploaded config content, validates the saved and env-applied runtime forms, builds the replacement runtime, persists the non-env config, then attempts shared cookie migration before installing the runtime. Runtime build or save failures leave the persisted config and active runtime unchanged.

func (*Backend) ImportMenuImages

func (b *Backend) ImportMenuImages(path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, paths []string) error

func (*Backend) ListHistory

func (b *Backend) ListHistory() ([]api.HistoryEntry, error)

func (*Backend) ListKnownTrackers

func (b *Backend) ListKnownTrackers() ([]string, error)

func (*Backend) ListUploadCandidates

func (b *Backend) ListUploadCandidates(path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides) ([]api.ScreenshotImage, error)

func (*Backend) ListUploadedImages

func (b *Backend) ListUploadedImages(path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides) ([]api.UploadedImageLink, error)

func (*Backend) LoadPlaylistSelection

func (b *Backend) LoadPlaylistSelection(path string) (api.PlaylistSelection, error)

func (*Backend) PreviewScreenshotFrame

func (b *Backend) PreviewScreenshotFrame(path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, timestampSeconds float64) (string, error)

func (*Backend) ReadScreenshotImage

func (b *Backend) ReadScreenshotImage(path string) (string, error)

func (*Backend) RenderDescription

func (b *Backend) RenderDescription(raw string) (string, error)

func (*Backend) ResetMetadata

func (b *Backend) ResetMetadata(sessionID string, path string, sourceLookupURL string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, trackersList []string, confirmBDMVRescan bool) (api.MetadataPreview, error)

func (*Backend) RetryFailedTrackerUpload

func (b *Backend) RetryFailedTrackerUpload(sessionID string, jobID string) (string, error)

RetryFailedTrackerUpload starts a retry job for failed trackers only when sessionID owns the original upload job. The retry reuses the original job's run options, upload options, questionnaire answers, description groups, and ignore-dupe list instead of rebuilding them from current settings.

func (*Backend) SaveConfig

func (b *Backend) SaveConfig(payload string) error

SaveConfig validates encrypted browser settings, builds the replacement runtime, persists the non-env config, then attempts shared cookie migration before installing the runtime. Runtime build or save failures leave the persisted config and active runtime unchanged; env overrides apply only to the installed runtime config.

func (*Backend) SaveDescriptionOverride

func (b *Backend) SaveDescriptionOverride(path string, groupKey string, raw string, trackers []string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides) (api.DescriptionBuilderGroup, error)

func (*Backend) SaveFinalScreenshotSelections

func (b *Backend) SaveFinalScreenshotSelections(path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, images []api.ScreenshotImage) error

func (*Backend) SavePlaylistSelection

func (b *Backend) SavePlaylistSelection(path string, playlists []string, useAll bool) error

func (*Backend) SelectBlurayCandidate

func (b *Backend) SelectBlurayCandidate(path string, releaseID string) (api.MetadataPreview, error)

func (*Backend) StartDupeCheck

func (b *Backend) StartDupeCheck(sessionID string, path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, trackers []string) (string, error)

func (*Backend) StartLogStream

func (b *Backend) StartLogStream(sessionID string) (string, error)

StartLogStream subscribes the browser session to live log events. Active streams are rebound when settings replace the runtime logger. If no logger or event hub is installed, it returns an error without registering a stream.

func (*Backend) StartTrackerUpload

func (b *Backend) StartTrackerUpload(sessionID string, path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, trackers []string, ignoreDupesFor []string, questionnaireAnswers map[string]map[string]string, descriptionGroups []api.DescriptionBuilderGroup, debug bool, noSeed bool, runLogLevel string) (string, error)

StartTrackerUpload starts an upload job owned by sessionID for selected trackers and returns its job ID. Snapshots preserve partial upload counts returned with later tracker errors or cancellation. The job captures upload options at start time so failed-tracker retries reuse the original option set.

func (*Backend) StopLogStream

func (b *Backend) StopLogStream(sessionID string, streamID string) error

StopLogStream stops streamID only when it belongs to sessionID. Unknown streams and streams owned by other sessions are treated as no-ops.

func (*Backend) StopSessionLogStreams

func (b *Backend) StopSessionLogStreams(sessionID string)

StopSessionLogStreams closes all active log streams owned by sessionID.

func (*Backend) UpdateLogExclusions

func (b *Backend) UpdateLogExclusions(patterns []string) error

func (*Backend) UploadImages

func (b *Backend) UploadImages(path string, overrides api.ExternalIDOverrides, nameOverrides api.ReleaseNameOverrides, trackersList []string, host string, images []api.ScreenshotImage) (api.UploadImagesResult, error)

type CLIConfig

type CLIConfig struct {
	Host           string   `json:"host"`
	Port           int      `json:"port"`
	OpenBrowser    bool     `json:"open_browser"`
	TrustedProxies []string `json:"trusted_proxies"`
	BaseURL        string   `json:"base_url"`
	SessionTTL     int      `json:"session_ttl"`
}

func DefaultCLIConfig

func DefaultCLIConfig() CLIConfig

func LoadCLIConfig

func LoadCLIConfig(dbPath string) (CLIConfig, error)

type DupeCheckSnapshot

type DupeCheckSnapshot struct {
	JobID          string                  `json:"jobID"`
	SourcePath     string                  `json:"sourcePath"`
	Status         string                  `json:"status"`
	Trackers       []DupeCheckTrackerState `json:"trackers"`
	CompletedCount int                     `json:"completedCount"`
	TotalCount     int                     `json:"totalCount"`
	Summary        api.DupeCheckSummary    `json:"summary"`
	Error          string                  `json:"error"`
	StartedAt      string                  `json:"startedAt"`
	FinishedAt     string                  `json:"finishedAt"`
}

type DupeCheckTrackerState

type DupeCheckTrackerState struct {
	Tracker    string              `json:"tracker"`
	Status     string              `json:"status"`
	Message    string              `json:"message"`
	Result     api.DupeCheckResult `json:"result"`
	StartedAt  string              `json:"startedAt"`
	FinishedAt string              `json:"finishedAt"`
}

type Options

type Options struct {
	// Config supplies the application configuration used by the backend.
	Config config.Config
	// CLIConfig supplies persisted or command-line web server settings.
	CLIConfig CLIConfig
	// DevelopmentNoAuth enables the development-only auth bypass for loopback hosts.
	DevelopmentNoAuth bool
}

Options configures the embedded web UI server.

type Server

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

Server owns the embedded web UI HTTP server, backend services, auth stores, and event hub.

func New

func New(opts Options) (*Server, error)

New constructs a server from application and web CLI configuration. It rejects development no-auth mode for non-loopback hosts.

func (*Server) Close

func (s *Server) Close() error

Close releases session and backend resources owned by the server.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run binds the configured TCP address and serves until ctx is cancelled or a shutdown signal arrives.

func (*Server) RunAfterListen added in v0.2.0

func (s *Server) RunAfterListen(ctx context.Context, afterListen func() error) error

RunAfterListen runs the server and calls afterListen once the TCP listener has bound successfully, before HTTP serving starts. If afterListen fails, the listener is closed and the server does not start accepting requests.

type TrackerUploadSnapshot

type TrackerUploadSnapshot struct {
	JobID                  string                      `json:"jobID"`
	SourcePath             string                      `json:"sourcePath"`
	Status                 string                      `json:"status"`
	CurrentTask            string                      `json:"currentTask"`
	CurrentTaskStatus      string                      `json:"currentTaskStatus"`
	CurrentMessage         string                      `json:"currentMessage"`
	CurrentCompletedPieces int                         `json:"currentCompletedPieces"`
	CurrentTotalPieces     int                         `json:"currentTotalPieces"`
	CurrentPercent         int                         `json:"currentPercent"`
	CurrentHashRateMiB     float64                     `json:"currentHashRateMiB"`
	Trackers               []TrackerUploadTrackerState `json:"trackers"`
	FailedTrackers         []string                    `json:"failedTrackers"`
	UploadedCount          int                         `json:"uploadedCount"`
	Error                  string                      `json:"error"`
	StartedAt              string                      `json:"startedAt"`
	FinishedAt             string                      `json:"finishedAt"`
}

TrackerUploadSnapshot reports frontend-visible state for a tracker upload job. UploadedCount is the sum of per-tracker accepted uploads, including partial counts returned with non-nil errors.

type TrackerUploadTrackerState

type TrackerUploadTrackerState struct {
	Tracker         string  `json:"tracker"`
	Status          string  `json:"status"`
	Task            string  `json:"task"`
	TaskStatus      string  `json:"taskStatus"`
	Message         string  `json:"message"`
	CompletedPieces int     `json:"completedPieces"`
	TotalPieces     int     `json:"totalPieces"`
	Percent         int     `json:"percent"`
	HashRateMiB     float64 `json:"hashRateMiB"`
	UploadedCount   int     `json:"uploadedCount"`
	StartedAt       string  `json:"startedAt"`
	FinishedAt      string  `json:"finishedAt"`
}

TrackerUploadTrackerState reports frontend-visible state for one tracker in an upload job. UploadedCount includes accepted uploads returned before a later tracker error or cancellation.

Jump to

Keyboard shortcuts

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