Documentation
¶
Overview ¶
Package sdk is the guest side of Streamline's extension contract, version 2. The types mirror internal/extension/contract.go field for field: the JSON tags are the wire.
Index ¶
- Constants
- func Dispatch(h func(Request) Response) int32
- func Log(level, msg string, kv ...any)
- func StartScan() error
- func WriteManifest(m Manifest) int32
- type AccountCard
- type Caller
- type CardField
- type FFmpegCall
- type FFmpegResult
- type FetchRequest
- type FetchResponse
- type Folder
- type LibraryChange
- type Manifest
- type Mount
- type Request
- type Response
- type SQLCall
- type SQLResult
- type ScanInfo
- type SendFile
- type ServeFile
- type ServePoster
- type StreamFFmpeg
Constants ¶
const ( CardCredential = "credential" CardSettings = "settings" FieldSwitch = "switch" FieldNumber = "number" )
const APIVersion = 2
APIVersion is the contract version this SDK speaks; a manifest's StreamlineAPI must name it.
const HookLibrary = "library"
HookLibrary is the hook name for library changes.
const HookSettings = "settings"
HookSettings is the hook a manifest lists to check what the config file gives it. POST /hooks/settings carries Settings, Secrets and Hosts, before the extension starts and whenever they change. Any answer but a 2xx keeps the extension from running, with the body as the reason shown to the admin.
Variables ¶
This section is empty.
Functions ¶
func Log ¶
Log writes one line to the host's log, tagged with the extension's name. kv is alternating keys and values.
func StartScan ¶
func StartScan() error
StartScan starts a library scan and returns at once; one already running is not an error. It needs the library_scan service.
func WriteManifest ¶
WriteManifest is the body of the guest's `manifest` export.
Types ¶
type AccountCard ¶
type AccountCard struct {
ID string `json:"id"`
Kind string `json:"kind"`
Title string `json:"title"`
Mount string `json:"mount"`
Username string `json:"username"`
Fields []CardField `json:"fields,omitempty"`
}
AccountCard.Mount is the address the account page shows for a credential card: what a user pastes into their app, relative to the extension's path like a Mount ("/" is /extensions/<name> itself). Name what the app expects to be given, never a path the app adds on its own: a Subsonic app appends /rest to its server address, so the Subsonic card is "/", and "/rest" would make it call /rest/rest.
type Caller ¶
type Caller struct {
ID uint32 `json:"id"`
Role string `json:"role"`
KeyID uint32 `json:"key_id,omitempty"`
KeyName string `json:"key_name,omitempty"`
}
Caller is the signed-in user. KeyID and KeyName are the API key the request came with, both zero for a browser session.
type CardField ¶
type CardField struct {
ID string `json:"id"`
Kind string `json:"kind"`
Label string `json:"label"`
Min int64 `json:"min"`
Max int64 `json:"max"`
}
CardField is one control of a settings card. Min and Max bound a number and mean nothing on a switch.
type FFmpegCall ¶
type FFmpegResult ¶
type FFmpegResult struct {
ExitCode int `json:"exit_code"`
Stdout []byte `json:"stdout"`
Stderr []byte `json:"stderr"`
Error string `json:"error"`
}
FFmpegResult is what a run left behind. Error is set, and the rest empty, when the host did not run the tool to completion.
func FFmpeg ¶
func FFmpeg(tool string, args ...string) (FFmpegResult, error)
FFmpeg runs ffmpeg or ffprobe (tool) with args as given, no shell, in the extension's cache folder. A run the host refused or cut short comes back in FFmpegResult.Error with a nil error; the error is for a failed host call.
type FetchRequest ¶
type FetchRequest struct {
Method string `json:"method"`
URL string `json:"url"`
Headers map[string][]string `json:"headers"`
Body []byte `json:"body"`
}
FetchRequest is one HTTP request the host makes for the extension.
type FetchResponse ¶
type FetchResponse struct {
Status int `json:"status"`
Headers map[string][]string `json:"headers"`
Body []byte `json:"body"`
Error string `json:"error,omitempty"`
}
func Fetch ¶
func Fetch(req FetchRequest) (FetchResponse, error)
Fetch sends req through the host and returns the answer as it came back: a redirect is not followed and a status of 400 or more is not an error. It needs the http service, and the URL's host:port must be in the hosts list the admin wrote for this extension. The answer is at most 16 MiB.
type Folder ¶
type Folder struct {
Name string `json:"name"`
HostPath string `json:"host_path"`
GuestPath string `json:"guest_path"`
// ReadOnly is set on the store folder once it holds as much as the
// config file allows: writes fail until the extension deletes something.
ReadOnly bool `json:"read_only,omitempty"`
}
Folder is a granted directory as the guest sees it: HostPath is what the views report, GuestPath is where this call has it mounted.
type LibraryChange ¶
type LibraryChange struct {
Full []string `json:"full,omitempty"`
Movies []uint32 `json:"movies,omitempty"`
Series []uint32 `json:"series,omitempty"`
Episodes []uint32 `json:"episodes,omitempty"`
}
LibraryChange is the body of the library hook: the folders to compare whole ("movies", "series"), and the ids of what changed. An id may be of a row that no longer exists.
type Manifest ¶
type Manifest struct {
Name string `json:"name"`
Version string `json:"version"`
StreamlineAPI int `json:"streamline_api"`
Mounts []Mount `json:"mounts"`
Views []string `json:"views"`
Folders []string `json:"folders"`
Services []string `json:"services"`
AccountCards []AccountCard `json:"account_cards"`
// Hooks are the calls the module wants from the host: POST /hooks/<name>
// with an empty Mount and no Caller, which no client can produce. "library"
// is sent when a movie, a series or an episode changed, with a
// LibraryChange as its body. "settings" is sent to check the settings the
// config file gives.
Hooks []string `json:"hooks,omitempty"`
}
type Mount ¶
Mount is a prefix the module answers, relative to the path the config serves it under: "/" is the whole of that path, "/rest" one segment below.
type Request ¶
type Request struct {
Method string `json:"method"`
Path string `json:"path"`
Query string `json:"query"`
Headers map[string][]string `json:"headers"`
Body []byte `json:"body"`
// Mount is the manifest mount the request arrived under and BasePath the
// path the config serves the extension under, so the client asked for
// BasePath+Mount+Path; both are empty for the extension's own /api and
// /cards subtrees. Origin is the scheme and host the client used, as
// Streamline works it out behind its trusted proxies: an absolute link
// back to the extension is Origin+BasePath+Mount+...
Mount string `json:"mount,omitempty"`
BasePath string `json:"base_path,omitempty"`
Origin string `json:"origin,omitempty"`
// ClientIP is the client's address as Streamline resolves it behind its
// trusted proxies; X-Forwarded-For in Headers is whatever the client sent.
ClientIP string `json:"client_ip,omitempty"`
Caller *Caller `json:"caller,omitempty"`
Folders []Folder `json:"folders,omitempty"`
// TargetUser is the account a settings card is read or written for: an
// admin editing another user, so it can differ from Caller.
TargetUser uint32 `json:"target_user,omitempty"`
// Settings are the entry's settings in Streamline's config file, as given
// there, and Secrets the contents of its secret_files, by name. Both are
// empty when the file sets none.
Settings map[string]json.RawMessage `json:"settings,omitempty"`
Secrets map[string]string `json:"secrets,omitempty"`
// Hosts is the entry's hosts list. Only the settings hook carries it.
Hosts []string `json:"hosts,omitempty"`
}
type Response ¶
type Response struct {
Status int `json:"status"`
Headers map[string][]string `json:"headers"`
Body []byte `json:"body"`
ServeFile *ServeFile `json:"serve_file,omitempty"`
ServePoster *ServePoster `json:"serve_poster,omitempty"`
SendFile *SendFile `json:"send_file,omitempty"`
StreamFFmpeg *StreamFFmpeg `json:"stream_ffmpeg,omitempty"`
}
type SQLResult ¶
type SQLResult struct {
Columns []string `json:"columns"`
Rows [][]any `json:"rows"`
RowsAffected int64 `json:"rows_affected"`
LastInsertID int64 `json:"last_insert_id"`
Error string `json:"error"`
}
type ScanInfo ¶
type ScanInfo struct {
Scanning bool `json:"scanning"`
Count int64 `json:"count"`
LastScan *time.Time `json:"last_scan"`
}
ScanInfo is the host's library scan as ScanStatus reports it; the host names the type ScanStatus.
func ScanStatus ¶
ScanStatus reports the library scan: whether one is running, how many tracks hold a file on disk and when the last one finished. It needs the library_scan service.
type SendFile ¶
type SendFile struct {
Path string `json:"path"`
Filename string `json:"filename"`
ContentType string `json:"content_type"`
}
SendFile asks the host to stream a file from a granted folder after the guest has returned. Path is a host path as the views and Folder.HostPath give it; the host finds the folder holding it.
type ServePoster ¶
type StreamFFmpeg ¶
type StreamFFmpeg struct {
Args []string `json:"args"`
ContentType string `json:"content_type"`
Headers map[string][]string `json:"headers"`
Fallback *SendFile `json:"fallback,omitempty"`
}
StreamFFmpeg asks the host to run ffmpeg after the guest has returned and stream its stdout as the response. Fallback is served instead when ffmpeg cannot start or fails before its first byte.