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
- func MatchesFilter(t engine.Torrent, filter string) bool
- func Principal(ctx context.Context) *auth.Principal
- func SortTorrents(items []engine.Torrent, field string, reverse bool)
- type API
- type AddTorrentRequest
- type AuthConfig
- type BulkAction
- type CategoriesEvent
- type CreateAPIKeyRequest
- type CreatedAPIKey
- type Deps
- type LoginRequest
- type SetFilePriority
- type SettingsEvent
- type SettingsPatch
- type SettingsResponse
- type SnapshotEvent
- type System
- type SystemInfo
- type TagsEvent
- type TorrentList
- type TorrentsEvent
- type TransferEvent
- type UpdateTorrentRequest
- type User
Constants ¶
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.
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.
const Prefix = "/api/piecemeal/v1"
Prefix is where the API is served.
Variables ¶
This section is empty.
Functions ¶
func MatchesFilter ¶
MatchesFilter reports whether a torrent matches a list filter.
Types ¶
type API ¶
type API struct {
Deps
// contains filtered or unexported fields
}
API is the native API.
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 ¶
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 ¶
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 ¶
SettingsEvent is the new settings.
type SettingsPatch ¶
SettingsPatch is a partial settings object; absent settings are left as they are.
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.