api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api is piecemeal's native REST API under /api/piecemeal/v1, built with Huma. The OpenAPI document is generated from these handlers and committed as api/openapi.json; the web UI's client is generated from that file.

Index

Constants

View Source
const (
	FilterAll         = "all"
	FilterDownloading = "downloading"
	FilterSeeding     = "seeding"
	FilterCompleted   = "completed"
	FilterStopped     = "stopped"
	FilterActive      = "active"
	FilterInactive    = "inactive"
	FilterStalled     = "stalled"
	FilterChecking    = "checking"
	FilterErrored     = "errored"
)

Filters accepted by the torrent list.

View Source
const CSRFHeader = "X-Requested-With"

CSRFHeader must be sent with unsafe requests authenticated by a session cookie. Browsers can't send custom headers cross-origin without a CORS preflight, which piecemeal never allows.

View Source
const Prefix = "/api/piecemeal/v1"

Prefix is where the API is served.

Variables

This section is empty.

Functions

func MatchesFilter

func MatchesFilter(t engine.Torrent, filter string) bool

MatchesFilter reports whether a torrent matches a list filter.

func Principal

func Principal(ctx context.Context) *auth.Principal

Principal returns the authenticated principal of a request handled by the API.

func SortTorrents

func SortTorrents(items []engine.Torrent, field string, reverse bool)

SortTorrents sorts by a field name, ties broken by hash.

Types

type API

type API struct {
	Deps
	// contains filtered or unexported fields
}

API is the native API.

func New

func New(mux *http.ServeMux, d Deps) *API

New registers the API's routes on mux.

func (*API) Close

func (a *API) Close()

Close ends open event streams. Call it when the HTTP server starts shutting down (http.Server.RegisterOnShutdown).

func (*API) OpenAPI

func (a *API) OpenAPI() *huma.OpenAPI

OpenAPI returns the API description.

type AddTorrentRequest

type AddTorrentRequest struct {
	Magnet                   string   `json:"magnet,omitempty" doc:"A magnet URI."`
	URL                      string   `json:"url,omitempty" doc:"An http(s) URL of a .torrent file, or one that redirects to a magnet URI."`
	TorrentFile              []byte   `json:"torrentFile,omitempty" doc:"The .torrent file, base64."`
	SavePath                 string   `json:"savePath,omitempty"`
	Category                 string   `json:"category,omitempty"`
	Tags                     []string `json:"tags,omitempty"`
	Stopped                  *bool    `json:"stopped,omitempty" doc:"Add without starting; defaults to the addStopped setting."`
	Sequential               bool     `json:"sequential,omitempty"`
	FirstLastPiece           bool     `json:"firstLastPiece,omitempty"`
	Name                     string   `json:"name,omitempty" doc:"Display name instead of the torrent's own."`
	RatioLimit               *float64 `json:"ratioLimit,omitempty"`
	SeedingTimeLimit         *int64   `json:"seedingTimeLimit,omitempty" doc:"Minutes."`
	InactiveSeedingTimeLimit *int64   `json:"inactiveSeedingTimeLimit,omitempty" doc:"Minutes."`
	DownloadLimit            int64    `json:"downloadLimit,omitempty" minimum:"0"`
	UploadLimit              int64    `json:"uploadLimit,omitempty" minimum:"0"`
	SkipChecking             bool     `json:"skipChecking,omitempty" doc:"Trust data already on disk instead of verifying it."`
}

AddTorrentRequest adds a torrent from exactly one of magnet, url and torrentFile.

type AuthConfig

type AuthConfig struct {
	LocalLogin bool `json:"localLogin"`
	OIDC       bool `json:"oidc"`
}

AuthConfig tells the sign-in page which methods are available.

type BulkAction

type BulkAction struct {
	Hashes     []string `json:"hashes" minItems:"1" doc:"Infohashes, or [\"all\"]."`
	Action     string   `json:"action" enum:"start,stop,forceStart,recheck,reannounce,remove,setCategory,addTags,removeTags"`
	DeleteData bool     `json:"deleteData,omitempty" doc:"With remove: also delete the files."`
	Category   string   `json:"category,omitempty" doc:"With setCategory; empty removes the category."`
	Tags       []string `json:"tags,omitempty" doc:"With addTags and removeTags; removeTags without tags removes all."`
}

BulkAction applies an action to several torrents.

type CategoriesEvent

type CategoriesEvent struct {
	Items []engine.Category `json:"items"`
}

CategoriesEvent is the new list of categories.

type CreateAPIKeyRequest

type CreateAPIKeyRequest struct {
	Name  string     `json:"name" minLength:"1" maxLength:"100"`
	Scope auth.Scope `json:"scope" enum:"full,qbittorrent,read-only"`
}

CreateAPIKeyRequest creates an API key.

type CreatedAPIKey

type CreatedAPIKey struct {
	auth.APIKey
	Key string `json:"key" doc:"The secret. It is not stored and can't be shown again."`
}

CreatedAPIKey includes the secret, shown only once.

type Deps

type Deps struct {
	Version   string
	StartedAt time.Time
	Engine    *engine.Engine
	Settings  *settings.Manager
	Auth      *auth.Service
	Fetcher   *fetch.Fetcher
	Logs      *logbuf.Buffer
	// NATPMP is nil when port forwarding isn't configured.
	NATPMP *natpmp.Mapper
	Log    *slog.Logger
	// System is static information for GET /system.
	System SystemInfo
}

Deps are the services the API uses.

type LoginRequest

type LoginRequest struct {
	Username string `json:"username" maxLength:"200"`
	Password string `json:"password" maxLength:"1000"`
}

LoginRequest signs in with the local admin's password.

type SetFilePriority

type SetFilePriority struct {
	Indices  []int           `json:"indices" minItems:"1"`
	Priority engine.Priority `json:"priority" enum:"0,1,6,7" doc:"0 skip, 1 normal, 6 high, 7 highest."`
}

SetFilePriority sets the priority of some of a torrent's files.

type SettingsEvent

type SettingsEvent struct {
	Settings settings.Settings `json:"settings"`
}

SettingsEvent is the new settings.

type SettingsPatch

type SettingsPatch settings.Settings

SettingsPatch is a partial settings object; absent settings are left as they are.

func (SettingsPatch) Schema

func (SettingsPatch) Schema(r huma.Registry) *huma.Schema

Schema makes every property optional.

type SettingsResponse

type SettingsResponse struct {
	Settings settings.Settings `json:"settings"`
	Locked   map[string]string `json:"locked" doc:"Settings set by environment variables, which can't be changed here, mapped to the variable."`
}

SettingsResponse is the current settings and which are pinned.

type SnapshotEvent

type SnapshotEvent struct {
	Torrents   []engine.Torrent      `json:"torrents"`
	Transfer   engine.TransferStatus `json:"transfer"`
	Categories []engine.Category     `json:"categories"`
	Tags       []string              `json:"tags"`
}

SnapshotEvent is the first event on a stream: the full state the following events change.

type System

type System struct {
	SystemInfo
	Version     string          `json:"version"`
	StartedAt   time.Time       `json:"startedAt"`
	Port        int             `json:"port" doc:"The port peers connect to."`
	ListenAddrs []string        `json:"listenAddrs"`
	NATPMP      *natpmp.Mapping `json:"natpmp,omitempty" doc:"Present when NAT-PMP port forwarding is configured."`
}

System is GET /system.

type SystemInfo

type SystemInfo struct {
	DataDir      string   `json:"dataDir"`
	DownloadDir  string   `json:"downloadDir"`
	WatchDir     string   `json:"watchDir,omitempty"`
	AllowedRoots []string `json:"allowedRoots"`
}

SystemInfo is static information about the running instance.

type TagsEvent

type TagsEvent struct {
	Items []string `json:"items"`
}

TagsEvent is the new list of tags.

type TorrentList

type TorrentList struct {
	Items      []engine.Torrent `json:"items"`
	Total      int              `json:"total" doc:"Torrents matching the filters, across all pages."`
	NextCursor string           `json:"nextCursor,omitempty" doc:"Pass as cursor to get the next page; absent on the last page."`
}

TorrentList is a page of torrents.

type TorrentsEvent

type TorrentsEvent struct {
	Updated []engine.Torrent `json:"updated"`
	Removed []string         `json:"removed"`
}

TorrentsEvent carries torrents that were added or changed, and the hashes of removed ones, since the previous event.

type TransferEvent

type TransferEvent engine.TransferStatus

TransferEvent is the new transfer status.

type UpdateTorrentRequest

type UpdateTorrentRequest struct {
	Name                     *string   `json:"name,omitempty"`
	Category                 *string   `json:"category,omitempty" doc:"Empty removes the category."`
	Tags                     *[]string `json:"tags,omitempty" doc:"Replaces the torrent's tags."`
	Stopped                  *bool     `json:"stopped,omitempty"`
	Forced                   *bool     `json:"forced,omitempty"`
	Sequential               *bool     `json:"sequential,omitempty"`
	FirstLastPiece           *bool     `json:"firstLastPiece,omitempty"`
	RatioLimit               *float64  `json:"ratioLimit,omitempty" doc:"-2 follows the global setting, -1 is unlimited."`
	SeedingTimeLimit         *int64    `json:"seedingTimeLimit,omitempty" doc:"Minutes. -2 follows the global setting, -1 is unlimited."`
	InactiveSeedingTimeLimit *int64    `json:"inactiveSeedingTimeLimit,omitempty" doc:"Minutes. -2 follows the global setting, -1 is unlimited."`
	DownloadLimit            *int64    `json:"downloadLimit,omitempty" minimum:"0"`
	UploadLimit              *int64    `json:"uploadLimit,omitempty" minimum:"0"`
}

UpdateTorrentRequest changes a torrent. Absent fields are left as they are.

type User

type User struct {
	ID          int64      `json:"id"`
	Username    string     `json:"username"`
	DisplayName string     `json:"displayName"`
	Email       string     `json:"email"`
	IsAdmin     bool       `json:"isAdmin"`
	OIDC        bool       `json:"oidc" doc:"Signs in through OIDC."`
	CreatedAt   time.Time  `json:"createdAt"`
	LastLoginAt *time.Time `json:"lastLoginAt,omitempty"`
}

User is a user account.

Jump to

Keyboard shortcuts

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