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.
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.
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.
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.
Deletes a playlist for DELETE /api/playlists/:playlistId, and broadcasts
playlist_deleted. canModerate lets someone other than the owner do it.
Returns the playlist if requestingUserId may edit it. The cover upload
route checks this before it writes the file, then calls
setPlaylistImage.
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.
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.
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.
| 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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
A playlist holding a dump, as playlistsHolding returns it: what
broadcastPlaylistDumpsUpdated needs to choose its audience.
Usage
import * as mod from "api/services/playlist-service.ts";