filehandlers

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: GPL-2.0, GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package filehandlers provides HTTP handlers for the /api/files/* endpoints.

S7 addressing contract: the wire carries NO filesystem paths in either direction. Listings expose the typed per-file identity (media_type, media_id, language, variant, source, ordinal) plus display metadata; deletion accepts that FileRef (or a server-minted orphan handle) and resolves the path from the store. S16: every disk delete routes through the subtitle-scoped gate (subtitlepath.RemoveUnderRoot), which refuses non-subtitle extensions loudly with 409 subtitle_extension_not_allowed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BulkDeleteRequest added in v0.1.148

type BulkDeleteRequest struct {
	MediaType api.MediaType `json:"media_type"`
	MediaID   string        `json:"media_id"`
}

BulkDeleteRequest is the typed body for DELETE /api/files/bulk: the media item whose external subtitle files are all deleted. MediaID keeps the store-ID semantics of the listing (exact ID, or a "tvdb-<id>-" series prefix covering every episode).

type DeleteFileRequest added in v0.1.148

type DeleteFileRequest struct {
	MediaType    api.MediaType `json:"media_type,omitempty"`
	MediaID      string        `json:"media_id,omitempty"`
	Language     string        `json:"language,omitempty"`
	Variant      string        `json:"variant,omitempty"`
	Source       string        `json:"source,omitempty"`
	OrphanHandle string        `json:"orphan_handle,omitempty"`
	Ordinal      int           `json:"ordinal,omitempty"`
}

DeleteFileRequest is the typed body for DELETE /api/files: either the FileRef fields addressing one stored subtitle file, or a server-minted orphan handle from the listing (mutually exclusive; orphan_handle wins).

type Deps

type Deps struct {
	Store     FileStore
	Resolve   *resolve.Resolver
	StateFunc func() *LiveState
	Events    EventPublisher
}

Deps holds the dependencies for file handlers.

type EventPublisher

type EventPublisher interface {
	Publish(e events.Event)
}

EventPublisher is the narrow interface for publishing events.

type FileEntry

type FileEntry struct {
	MediaID      string `json:"media_id"`
	Language     string `json:"language"`
	Variant      string `json:"variant"`
	Source       string `json:"source"`
	Codec        string `json:"codec,omitempty"`
	Name         string `json:"name,omitempty"`
	OrphanHandle string `json:"orphan_handle,omitempty"`
	Score        int    `json:"score,omitempty"`
	Ordinal      int    `json:"ordinal,omitempty"`
	OffsetMs     int64  `json:"offset_ms,omitempty"`
	Size         int64  `json:"size,omitempty"`
}

FileEntry is the JSON shape for the file manager API. It carries no filesystem paths: (media_id, language, variant, source, ordinal) is the FileRef identity a client echoes back to address the file; Name is the display basename. Orphan rows (on disk, no store row) additionally carry the single-use OrphanHandle and only Name/Size beside it.

type FileRadarrClient added in v0.1.148

type FileRadarrClient interface {
	GetMovieByID(ctx context.Context, id int) (arrapi.Movie, error)
}

FileRadarrClient is the Radarr surface the bound orphan fallback needs: the movie's identity for the media_id binding check plus its file path.

type FileSonarrClient added in v0.1.148

type FileSonarrClient interface {
	GetSeriesByID(ctx context.Context, id int) (arrapi.Series, error)
	GetEpisodes(ctx context.Context, seriesID int) ([]arrapi.Episode, error)
}

FileSonarrClient is the Sonarr surface the bound orphan fallback needs: the series identity for the media_id binding check plus the episodes' file paths for the per-episode directory narrowing.

type FileStore

type FileStore interface {
	GetSubtitleFiles(ctx context.Context, mediaType api.MediaType, mediaIDPrefix string) ([]api.SubtitleEntry, error)
	DeleteSubtitleFile(ctx context.Context, mediaType api.MediaType, mediaID, language string, variant api.Variant, source api.SubtitleSource, path string) error
	ManualSubtitlePaths(ctx context.Context, mediaType api.MediaType, mediaID, language string, variant api.Variant) ([]string, error)
	ClearManualLock(ctx context.Context, mediaType api.MediaType, mediaID, language string, variant api.Variant) error
	HistoryMediaIDs(ctx context.Context, mediaType api.MediaType, mediaIDPrefix string) ([]string, error)
}

FileStore is the narrow store interface used by file handlers.

type Handler

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

Handler provides HTTP handlers for the /api/files/* endpoints.

func NewHandler

func NewHandler(deps Deps) *Handler

NewHandler creates a file Handler with the given dependencies.

func (*Handler) HandleBulkDeleteFiles

func (h *Handler) HandleBulkDeleteFiles(w http.ResponseWriter, r *http.Request)

HandleBulkDeleteFiles deletes all external subtitle files for a media item. DELETE /api/files/bulk

func (*Handler) HandleDeleteFile

func (h *Handler) HandleDeleteFile(w http.ResponseWriter, r *http.Request)

HandleDeleteFile deletes a single external subtitle file addressed by FileRef (store-resolved path) or orphan handle (TTL table). DELETE /api/files

func (*Handler) HandleHistoryIDs

func (h *Handler) HandleHistoryIDs(w http.ResponseWriter, r *http.Request)

HandleHistoryIDs returns distinct media IDs that have download history. GET /api/state/ids?type=movie&prefix=tmdb-1271

func (*Handler) HandleListFiles

func (h *Handler) HandleListFiles(w http.ResponseWriter, r *http.Request)

HandleListFiles returns subtitle files for a media item with file sizes, including orphans discovered by the server-side directory walk. GET /api/files?media_type=movie&media_id=tmdb-1271[&arr_id=42]

type LiveState

type LiveState struct {
	Cfg    api.ConfigProvider
	Sonarr FileSonarrClient
	Radarr FileRadarrClient
}

LiveState holds the runtime state needed by file handlers. The arr clients (nil when unconfigured) feed the orphan walk's all-orphan fallback: a media item whose files are all orphans has no store-derivable directory, so its directory is resolved via the arr item — but only after the arr item's external identity is verified to match the requested media_id (the client-supplied media_id/arr_id pairing is never trusted).

Jump to

Keyboard shortcuts

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