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 (removeSubtitleUnderRoot), which refuses non-subtitle extensions loudly with 409 subtitle_extension_not_allowed.
Index ¶
- type BulkDeleteRequest
- type DeleteFileRequest
- type Deps
- type EventPublisher
- type FileEntry
- type FileRadarrClient
- type FileSonarrClient
- type FileStore
- type Handler
- func (h *Handler) HandleBulkDeleteFiles(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleDeleteFile(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleHistoryIDs(w http.ResponseWriter, r *http.Request)
- func (h *Handler) HandleListFiles(w http.ResponseWriter, r *http.Request)
- type LiveState
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 subflux.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 subflux.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 ¶
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
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 {
SeriesByID(ctx context.Context, id int) (arrapi.Series, error)
Episodes(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 {
SubtitleFiles(ctx context.Context, mediaType subflux.MediaType, mediaIDPrefix string) ([]subflux.SubtitleEntry, error)
DeleteSubtitleFile(ctx context.Context, mediaType subflux.MediaType, mediaID, language string, variant subflux.Variant, source subflux.SubtitleSource, path string) error
ManualSubtitlePaths(ctx context.Context, key subflux.ManualLockKey) ([]string, error)
ClearManualLock(ctx context.Context, key subflux.ManualLockKey) error
HistoryMediaIDs(ctx context.Context, mediaType subflux.MediaType, mediaIDPrefix string) ([]string, error)
}
FileStore is what deleting a subtitle file has to touch: find the rows, drop the one row, release a manual lock the deletion emptied, and answer the media-ID listing. 5 of the 36 methods the store offers.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler provides HTTP handlers for the /api/files/* endpoints.
func NewHandler ¶
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 pathGuard
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).