api

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 25 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 exposes the core over HTTP/JSON. Every request needs the API token, so a web page opened in the user's browser cannot drive the client through localhost.

Index

Constants

View Source
const OpenToken = "open"

OpenToken is the key of a server in open mode (see SetOpen). It is no secret: the pages carry it so that they send the Authorization header every request needs, which a page of another site cannot do without a preflight request that this server never allows.

Variables

This section is empty.

Functions

func LoadToken

func LoadToken(path string) (string, error)

LoadToken returns the persistent API token stored at path, creating it if needed.

Types

type About added in v1.0.1

type About struct {
	Name    string `json:"name"`
	Version string `json:"version"`
	GoVer   string `json:"goVersion"`
	OS      string `json:"os"`     // "windows/amd64"
	Engine  string `json:"engine"` // e.g. "github.com/anacrolix/torrent v1.61.0", "" if unknown
}

About is the static "About" info of the running build, for the settings page.

type Desktop added in v1.1.1

type Desktop interface {
	AutostartEnabled() bool
	SetAutostart(on, hidden bool) error
	// MakeDefault makes the program the one that opens .torrent files and magnet links.
	MakeDefault() error
}

Desktop is what the page asks of the desktop program it is the window of, when that window is the user's own browser (Linux). A program with a window of its own (Windows) binds these to the page itself instead.

type Place added in v1.1.0

type Place struct {
	Name string `json:"name"`
	Path string `json:"path"`
}

Place is a folder the server is given by the system around it, under the name that system shows it by (see Server.SetPlaces).

type Server

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

Server is the HTTP handler.

func New

func New(m *core.Manager, cfg *config.Store, token string, ui http.Handler) *Server

New builds the handler. ui serves the web interface for non-API paths (may be nil).

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) SetBrowserApp added in v1.1.1

func (s *Server) SetBrowserApp(d Desktop)

SetBrowserApp says the page is the window of the desktop program, shown in the user's own browser (Linux): it then takes .torrent files and magnet links opened from outside, as the program's own window does on Windows, and has the system section of the settings, answered by d.

func (*Server) SetFixedPort added in v1.1.0

func (s *Server) SetFixedPort(port int)

SetFixedPort says the torrent port was given at start and is not the page's to change: a container publishes just that port, and a different one would get no incoming connections at all (found on Umbrel, where the button for a random port moved the program off the published one).

func (*Server) SetOpen added in v1.0.24

func (s *Server) SetOpen(extraHosts []string)

SetOpen puts the server in open mode, for running behind a proxy that signs the user in (Umbrel's app proxy does): nobody has to carry a personal key, every page gets OpenToken, and the host names of the requests need not be loopback ones. Because DNS rebinding needs a name, a request is still refused unless it comes by an IP address, a short or local name (see hostAllowed) or one of extraHosts.

func (*Server) SetPlaces added in v1.1.0

func (s *Server) SetPlaces(ps []Place)

SetPlaces gives the folders the server may use, by the names the system around it shows them under (Umbrel's Files: "Downloads" is /downloads in the container). The page then shows paths by those names, and the folder picker offers just these folders and does not go above them.

type UpdateStatus added in v1.0.6

type UpdateStatus struct {
	Available bool   `json:"available"`
	Version   string `json:"version,omitempty"`
	Notes     string `json:"notes,omitempty"`
	URL       string `json:"url,omitempty"` // the release's page, for a manual download
}

UpdateStatus is what the settings page shows about a newer release.

Jump to

Keyboard shortcuts

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