Builds the site's own URLs, for its pages and for the files, thumbnails and covers the API serves. Every link and media element of the frontend takes them from here, or from shared/paths.ts, whose page paths this wraps for dumps and playlists.

Functions

f
dumpFileUrl(
dump: VersionedDump,
token?: string | null
): string

Returns the URL of the uploaded file of dump. The caller passes the session's media token (useAuth's mediaToken) as token, which goes in the query string since a media element can't send a header. The server needs it for a private dump's file.

f
dumpThumbnailUrl(
dump: VersionedDump,
token?: string | null
): string

Returns the URL of the thumbnail of dump, with the media token as for dumpFileUrl. The server answers with the custom thumbnail if the dump has one, or else with one made from the file, a video still or a scaled-down image.

f
dumpUrl(
dump: OwnedItem,
view?: "edit"
): string

Returns the path of the page of dump, /@owner/dumps/<slug>, or of its editor (dumpPath). Its owner's name and its slug come with every dump the API sends.

f
dumpWaveformUrl(
dump: VersionedDump,
token?: string | null
): string

Returns the URL of the waveform of the audio file dump, which the server makes from the file, with the media token as for dumpFileUrl. The player draws it to seek on.

f
feedApiUrl(categorySlug?: string): string

Returns the URL of the feed's dumps, GET /api/dumps, every dump's or those of the category categorySlug; pageUrl adds the page to it. The index page loads it, and landingRequest names it to start it early.

f
imageProps(
url: string,
sizes: number | string
): { src: string; srcSet: string; sizes: string; }

Returns what an <img> needs to load url, one of the API's images, no larger than it is shown: a srcset of the copies the server makes (shared/image.ts), from which the browser takes the narrowest that fills sizes on its screen, and a src for whatever reads only that. sizes is the width the image is laid out at, in CSS pixels, or a sizes attribute when that width follows the viewport's. Avatar, Thumbnail and the playlists' covers spread it on their image.

f
isApiImageUrl(url: string): boolean

Checks whether url is an image the API serves, its own or one it proxies, which all take ?w= and answer a scaled-down copy. Another site's image, loaded from its own host, doesn't.

f
isAt(
item: OwnedItem | null | undefined,
username: string | undefined,
slug: string | undefined
): boolean

Checks whether item, a dump or a playlist, is the one a page's /@username/…/slug names, the name in any case. A page that already shows it needn't fetch it again when its URL changes to its current path.

f
normalizeUrl(input: string): string

Returns what a user typed as a link, trimmed, with https:// added when it has no http(s) scheme. The result is not checked to be a valid URL.

f
playlistImageUrl(
playlist: { id: string; updatedAt?: Date; isPublic?: boolean; },
token?: string | null
): string

Returns the URL of the cover of playlist, versioned on updatedAt, which a new cover bumps. A private playlist's URL carries the media token, as for dumpFileUrl. A public one doesn't, so that its URL is the same for everyone. A playlist without isPublic counts as public.

f
playlistUrl(
playlist: OwnedItem,
view?: "edit"
): string

Returns the path of the page of playlist, /@owner/playlists/<slug>, or of the page with its editor open (playlistPath).

f
userApiUrl(
user: { id: string; } | { username: string; },
...segments: string[]
): string

Returns the URL of /api/users/:key, or of what is under it, segments such as "dumps", slug, each encoded: every request about a user takes it from here. The key is user's id, or, when the caller has only the name a page's path gives, @ and that handle, which the API resolves as the page would, a former name or a remote user's included.

Type Aliases

T
VersionedDump = { id: string; fileSize?: number; createdAt?: Date; updatedAt?: Date; }

Passed to dumpFileUrl and dumpThumbnailUrl, usually as a whole Dump. Without the dates, the URL carries no current version and the browser revalidates it.