Stores playlists and the ordered dumps in them. The playlist routes call it, and so do the search, users and dumps routes to list playlists. Every write is broadcast over the WebSocket, and a viewer is only ever sent the dumps isMemberVisibleTo lets them see.

Functions

f
addDumpToPlaylist(
playlistId: string,
dumpId: string,
requestingUserId: string,
canModerate: boolean
): void

Puts a dump at the top of a playlist, for POST /api/playlists/:playlistId/dumps/:dumpId, and broadcasts playlist_dumps_updated. The followers of a public playlist are notified when the dump is public.

f
broadcastHoldersDumps(holders: PlaylistHolder[]): void

Sends each of holders its dumps again, after one of them was deleted or changed visibility, which changes what each viewer may see of them.

f
createPlaylist(
req: CreatePlaylistRequest,
userId: string
): Playlist

Creates a playlist owned by userId, for POST /api/playlists, filed under the playlist categories req names. If it is public, it notifies the users its description mentions. It links the attachments the description embeds and broadcasts playlist_created.

f
deletePlaylist(
playlistId: string,
requestingUserId: string,
canModerate: boolean
): void

Deletes a playlist for DELETE /api/playlists/:playlistId, and broadcasts playlist_deleted. canModerate lets someone other than the owner do it.

f
getEditablePlaylist(
playlistId: string,
requestingUserId: string,
canModerate: boolean
): Playlist

Returns the playlist if requestingUserId may edit it. The cover upload route checks this before it writes the file, then calls setPlaylistImage.

f
getPlaylist(
playlistId: string | Playlist,
requestingUserId: string | null
): PlaylistWithDumps

Returns a playlist with the dumps requestingUserId may see in it, in order, for GET /api/playlists/:playlistId, and for GET /api/users/:key/playlists/:slug once it has found the playlist by its path, for the same viewer. A null requestingUserId is a signed-out viewer. Its dumpCount is the number of those dumps.

f
getPlaylistById(
playlistId: string,
viewerId?: string | null
): Playlist

Returns playlist playlistId, private or not. A caller that shows it to someone must check isPublic first, as the OG middleware does. Its dumpCount and lastDumpAt are viewerId's, or a signed-out viewer's without one.

f
getPlaylistByPath(
userId: string,
slug: string,
viewerId?: string | null
): Playlist

Returns the playlist of userId's whose slug is or was slug, private or not, or throws a 404, as getPlaylistById does, counting its dumps for viewerId likewise. Reached by a former slug, it comes with its current one.

f
getPlaylistImageInfo(
playlistId: string,
requestingUserId: string | null
):
{ id: string; imageMime: string; isPublic: boolean; }
| undefined

Returns what GET /api/playlists/:playlistId/cover needs to serve a playlist's cover, or undefined when it has none. The route serves a private playlist's cover as private, so no shared cache keeps it.

f
getPlaylistMembershipsForDump(
dumpId: string,
userId: string
): PlaylistMembership[]

Returns each of userId's playlists, newest first, and whether it holds dump dumpId, for GET /api/me/playlists?contains=. The client's add-to-playlist modal shows it.

f
getPlaylistsForDump(
dumpId: string,
requestingUserId?: string
): Playlist[]

Returns up to 20 playlists that hold dump dumpId, newest first, for GET /api/dumps/:dumpId/playlists. Private playlists are left out, except requestingUserId's own. The route checks first that the caller may see the dump.

f
listNewPublicPlaylists(
from: Date,
to: Date
): Playlist[]

Returns the public playlists created from from to to, the fullest first and the newer on a tie. The community service gathers them for the /community page and the digests, which show every reader the same figures: only their public dumps are counted.

f
listPlaylistsByUser(
userId: string,
requestingUserId: string | null,
page: number,
limit: number,
sort: PlaylistSort,
categoryId?: string
): Page<Playlist>

Returns a page of userId's playlists, in the order sort names, for GET /api/users/:key/playlists, optionally only those in the playlist category categoryId. The private ones are listed only when requestingUserId is userId.

f
listPublicPlaylists(
requestingUserId: string | null,
page: number,
limit: number,
sort: PlaylistSort,
categoryId?: string
): Page<Playlist>

Returns a page of every public playlist, in the order sort names, for GET /api/playlists, optionally only those in the playlist category categoryId. The client's /playlists page lists them. Their dumps are counted, and so ordered, for requestingUserId, null being a signed-out viewer.

f
playlistsHolding(dumpId: string): PlaylistHolder[]

Returns the playlists holding dump dumpId. The dump service reads them before it deletes the dump or changes its visibility, and passes them to broadcastHoldersDumps after.

f
removeDumpFromPlaylist(
playlistId: string,
dumpId: string,
requestingUserId: string,
canModerate: boolean
): void

Takes a dump out of a playlist, for DELETE /api/playlists/:playlistId/dumps/:dumpId, and broadcasts playlist_dumps_updated. A dump that isn't in it is no error.

f
reorderPlaylist(
playlistId: string,
dumpIds: string[],
requestingUserId: string,
canModerate: boolean
): void

Puts the dumps of a playlist that the requester can see in the order of dumpIds, for PUT /api/playlists/:playlistId/order, and broadcasts playlist_dumps_updated.

f
searchPlaylists(
query: string,
limit: number,
requestingUserId?: string,
categoryId?: string
): Playlist[]

Returns up to limit playlists whose title or description contains query, newest first, for GET /api/search, optionally only those in the playlist category categoryId. Private playlists are left out, except requestingUserId's own. A blank query finds nothing.

f
setPlaylistImage(
playlistId: string,
imageMime: string,
requestingUserId: string,
canModerate: boolean
): Playlist

Records the type of a playlist's new cover and broadcasts playlist_updated. The route must have written the file already, since clients fetch the cover as soon as they get the broadcast.

f
updatePlaylist(
playlistId: string,
req: UpdatePlaylistRequest,
requestingUserId: string,
canModerate: boolean
): Playlist

Applies req to a playlist for PUT /api/playlists/:playlistId, and returns it as it now is. A new slug goes through changeSlug, first, and a moderator is exempt from its rate limit; a new title leaves the slug as it is. canModerate lets someone other than the owner edit it. If the playlist is public, it notifies, in the owner's name, the users the description mentions. When it goes public, its followers are notified of its public dumps they weren't yet told of. It links the description's attachments and tells clients of the change (broadcastPlaylistChange).

Type Aliases

T
PlaylistHolder = Pick<Playlist, "id" | "isPublic" | "userId">

A playlist holding a dump, as playlistsHolding returns it: what broadcastPlaylistDumpsUpdated needs to choose its audience.