Documentation
¶
Overview ¶
Package romm reads a self-hosted RomM server: its platforms and ROMs become indexed media, and a ROM is downloaded onto the device when launched.
Index ¶
- Constants
- Variables
- func Install(ctx context.Context, cfg *config.Instance, pl platforms.Platform, ...) (localPath, systemID string, err error)
- func IsRomPath(p string) bool
- func IsUnreachable(err error) bool
- func LaunchExtensions(cfg *config.Instance, pl platforms.Platform, systemID string) []string
- func LocalNames(rom *Rom, l Layout) []string
- func MatchNames(rom *Rom) []string
- func NewLauncher(pl platforms.Platform) platforms.Launcher
- func NormalizeServerURL(raw string) (string, error)
- func ParseRomPath(p string) (int, error)
- func RomPath(id int, name string) string
- func Scan(ctx context.Context, cfg *config.Instance, pl platforms.Platform, ...) ([]platforms.ScanResult, error)
- func ServerSystems(ctx context.Context, c *Client) ([]string, error)
- func ServerURL(cfg *config.Instance) string
- func SystemForPlatform(slug, fsSlug string) (string, bool)
- func Title(l Layout) string
- type Client
- func (c *Client) AssetURL(assetPath string) (string, bool)
- func (c *Client) BaseURL() string
- func (c *Client) ContentURL(id int, fileName string) string
- func (c *Client) Fetch(ctx context.Context, rawURL string, limit int64) ([]byte, error)
- func (c *Client) Platforms(ctx context.Context) ([]Platform, error)
- func (c *Client) PollDeviceToken(ctx context.Context, deviceCode string) (string, error)
- func (c *Client) Rom(ctx context.Context, id int) (*Rom, error)
- func (c *Client) Roms(ctx context.Context, platformID int) ([]Rom, error)
- func (c *Client) StartDeviceLink(ctx context.Context, req DeviceLinkRequest) (*DeviceLink, error)
- type DeviceLink
- type DeviceLinkRequest
- type Layout
- type Metadatum
- type Platform
- type Rom
- type RomFile
Constants ¶
const LauncherID = "RomM"
LauncherID names the RomM launcher, and is the launcher a [[launchers.default]] entry names to set the server_url.
Variables ¶
var ( // ErrNotConfigured is returned when no RomM server URL is set. ErrNotConfigured = errors.New("romm server is not configured") ErrUnauthorized = errors.New("romm server refused the credentials") // ErrNotFound is returned for a ROM the server does not have. ErrNotFound = errors.New("romm rom not found") )
var ( // ErrLinkPending means the user has not approved the request yet. ErrLinkPending = errors.New("romm link approval pending") // ErrLinkSlowDown means the device polled faster than the server allows. ErrLinkSlowDown = errors.New("romm link polled too fast") // ErrLinkDenied means the user turned the request down. ErrLinkDenied = errors.New("romm link request denied") // ErrLinkExpired means the request expired or was already used. ErrLinkExpired = errors.New("romm link request expired") )
Errors a device-token poll ends with, by RomM's OAuth device-flow codes.
var DeviceScopes = []string{"platforms.read", "roms.read", "assets.read"}
DeviceScopes are the permissions a linked device asks for: enough to list platforms and ROMs, download them and fetch their artwork.
var ErrInvalidPath = errors.New("invalid romm path")
ErrInvalidPath is returned for a romm:// path without a usable ROM ID.
Functions ¶
func Install ¶
func Install( ctx context.Context, cfg *config.Instance, pl platforms.Platform, ui *uievents.Service, p string, ) (localPath, systemID string, err error)
Install downloads the ROM a romm:// path names into its system's game folder, unless it is there already, and returns the local file to launch and the system it belongs to.
func IsUnreachable ¶
IsUnreachable reports whether err means the server could not be reached or failed on its side, rather than refusing or answering badly.
func LaunchExtensions ¶
LaunchExtensions are the lowercase extensions the platform's file launchers for a system open. RomM ROMs a system cannot open are not listed for it, and an extracted multi-file game is started from a file of one of these.
func LocalNames ¶
LocalNames are the lowercase file names that mean a ROM is already on the device: any of its files, and the playlist a multi-file ROM is launched by.
func MatchNames ¶
MatchNames are the lowercase file names a ROM is stored under on a device once downloaded, or under which a user's own copy of it would be indexed. It answers nil for a ROM whose files cannot be stored safely.
func NewLauncher ¶
NewLauncher builds the RomM launcher. It has no system of its own: its scanner runs for each system and lists the server's ROMs for it. Launching one downloads it into the system's game folder, where the system's own launcher starts it.
func NormalizeServerURL ¶
NormalizeServerURL turns a user-entered server address into the base URL requests are built from: an http or https URL with no query, fragment, credentials or trailing slash. An address without a scheme is taken as http, the way a RomM server on a home network is usually reached.
func ParseRomPath ¶
ParseRomPath returns the ROM ID a romm:// path names.
func Scan ¶
func Scan( ctx context.Context, cfg *config.Instance, pl platforms.Platform, systemID string, results []platforms.ScanResult, ) ([]platforms.ScanResult, error)
Scan returns results with the server's ROMs for systemID added. ROMs the device already has a file of, by name, are left out, as are ROMs none of the system's launchers could open once downloaded.
func ServerSystems ¶
ServerSystems lists the Zaparoo systems the server has a platform for.
func SystemForPlatform ¶
SystemForPlatform returns the Zaparoo system a RomM platform's ROMs index under. The universal slug decides; the folder slug is a fallback for a custom platform RomM could not identify, matched against Zaparoo's own system IDs and aliases the way a folder name would be.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one RomM server.
func ClientFromConfig ¶
ClientFromConfig returns a client for the configured server, or ErrNotConfigured when there is none.
func (*Client) AssetURL ¶
AssetURL resolves a cover or screenshot path from the API against the server. Only server-relative paths are accepted: an absolute URL points at some other host, which Core does not fetch from.
func (*Client) ContentURL ¶
ContentURL is where the ROM's files download from. fileName names the download: a multi-file ROM arrives as <fileName>.zip with a generated <fileName>.m3u inside when the server builds a playlist.
func (*Client) PollDeviceToken ¶
PollDeviceToken asks once whether a link was approved, and returns the access token when it was. A request still waiting answers ErrLinkPending or ErrLinkSlowDown; ErrLinkDenied and ErrLinkExpired end the flow.
func (*Client) StartDeviceLink ¶
func (c *Client) StartDeviceLink(ctx context.Context, req DeviceLinkRequest) (*DeviceLink, error)
StartDeviceLink asks the server to start a device link. The user approves it in RomM's web interface, after which PollDeviceToken returns the token.
type DeviceLink ¶
type DeviceLink struct {
DeviceCode string
UserCode string
VerificationURL string
VerificationURLComplete string
ExpiresIn int
Interval int
}
DeviceLink is a started link request. VerificationURL and VerificationURLComplete are absolute, under the server's URL.
type DeviceLinkRequest ¶
DeviceLinkRequest describes the device asking to be linked.
type Layout ¶
type Layout struct {
// Name is the file a single-file ROM is saved as, or the folder a
// multi-file ROM is unpacked into.
Name string
// Archive marks a multi-file ROM, which RomM serves as one zip.
Archive bool
}
Layout is how a ROM is stored on the device.
func LayoutFor ¶
LayoutFor works out where a ROM goes on the device. A single-file ROM keeps its file's own name: for a ROM nested in a folder on the server, fs_name is that folder, not the file. A multi-file ROM is named after the ROM without its extension, which is also the name RomM gives a generated .m3u.
type Metadatum ¶
type Metadatum struct {
AverageRating *float64 `json:"average_rating"`
FirstReleaseDate *int64 `json:"first_release_date"`
PlayerCount string `json:"player_count"`
Genres []string `json:"genres"`
Franchises []string `json:"franchises"`
Companies []string `json:"companies"`
Publishers []string `json:"publishers"`
Developers []string `json:"developers"`
GameModes []string `json:"game_modes"`
AgeRatings []string `json:"age_ratings"`
}
Metadatum is RomM's merged metadata for a ROM, drawn from whichever metadata providers the server has enabled.
type Platform ¶
type Platform struct {
Slug string `json:"slug"`
FSSlug string `json:"fs_slug"`
Name string `json:"name"`
UpdatedAt string `json:"updated_at"`
ID int `json:"id"`
ROMCount int `json:"rom_count"`
}
Platform is one entry of GET /api/platforms.
type Rom ¶
type Rom struct {
Metadatum Metadatum `json:"metadatum"`
HasFileOnDisk *bool `json:"has_file_on_disk"`
PlatformSlug string `json:"platform_slug"`
PlatformFSSlug string `json:"platform_fs_slug"`
FSName string `json:"fs_name"`
FSNameNoTags string `json:"fs_name_no_tags"`
FSNameNoExt string `json:"fs_name_no_ext"`
FSExtension string `json:"fs_extension"`
Name string `json:"name"`
Summary string `json:"summary"`
PathCoverLarge string `json:"path_cover_large"`
PathCoverSmall string `json:"path_cover_small"`
UpdatedAt string `json:"updated_at"`
Regions []string `json:"regions"`
Languages []string `json:"languages"`
MergedScreenshots []string `json:"merged_screenshots"`
Files []RomFile `json:"files"`
ID int `json:"id"`
PlatformID int `json:"platform_id"`
FSSizeBytes int64 `json:"fs_size_bytes"`
HasMultipleFiles bool `json:"has_multiple_files"`
MissingFromFS bool `json:"missing_from_fs"`
}
Rom is one ROM as returned by the ROM list and detail endpoints. Only the fields Core uses are decoded.
func SystemRoms ¶
SystemRoms lists every ROM the server files under platforms that map to systemID. A system no platform maps to has none, and is not an error.
func (*Rom) Downloadable ¶
Downloadable reports whether the server has the ROM's files to serve.