Posts, edits and deletes dumps, and reads them as each viewer may see them.
routes/dumps.ts calls it, and so do the search, user, file and thumbnail
routes to read dumps. A dump's slug is made from its title when it is
posted, and changes only when an edit sends a new one (slug-service.ts). It broadcasts the changes to public dumps over the
WebSocket.
The functions that change a dump don't check who asks: the routes do first.
Posts an uploaded file as userId, for POST /api/dumps, and stores it in
DUMPS_DIR under the dump's id. It is announced and notified as
createUrlDump does.
Posts a link as userId, for POST /api/dumps, with its preview fetched
from the page. A public dump is broadcast as dump_created and notified to
the poster's followers. Anyone @mentioned in the note is notified even when
the dump is private.
Returns where dump dumpId's custom thumbnail is kept: the thumbnail route
writes and serves it, and this service deletes it with the thumbnail or the
dump.
Deletes a dump with its files and thumbnails, for
DELETE /api/dumps/:dumpId, and broadcasts dump_deleted and the new
dumps of the playlists that held it.
Returns the dumps requestingUserId may see that were posted with the same
link as url, newest first, for the create form's duplicate notice
(GET /api/dumps?url=). Links are compared in their canonical form, so
tracking parameters, the scheme, www. or a YouTube share format don't hide
a repost.
Returns dump dumpId as requestingUserId may see it. The routes resolve
every :dumpId with it before acting on the dump.
Returns the dump of userId's whose slug is or was slug, as
requestingUserId may see it, for GET /api/users/:key/dumps/:slug, which
reads a dump by its page's path. Reached by a former slug, it comes with
its current one, which the client puts in its URL.
Returns a page of userId's dumps, newest first, for
GET /api/users/:key/dumps, optionally only those in categoryId. The
route sets includePrivate when users ask for their own.
Returns a page of the dumps userId upvoted, latest vote first, for
GET /api/users/:key/upvoted, optionally only those in categoryId.
Their own private dumps are included only when they are the one asking.
Returns a page of the dumps requestingUserId may see, newest first, for the
index feed (GET /api/dumps).
Returns the limit most upvoted public dumps posted from from to to,
the newer first on a tie, leaving out those no one upvoted. The community
service gathers them for the /community page and the digests.
Fetches a URL dump's preview again, bypassing the cache, and replaces its
title and preview, for POST /api/dumps/:dumpId/metadata. The slug stays.
Removes a dump's custom thumbnail and its file, for
DELETE /api/dumps/:dumpId/thumbnail.
Replaces a file dump's upload and its comment, for
PUT /api/dumps/:dumpId/file. A title, slug, categoryIds or
isPrivate left out stays as it is. Visibility is taken here so that a new
file and a change of visibility land together. The slug changes as in
updateDump, before the file is written. The old file is put back if
the database update fails, and clients and followers are told as
updateDump tells them.
Returns a page of the dumps requestingUserId may see whose title, note, or
previewed title or description contains query, newest first, with how many
match in all, optionally only those in the dump category categoryId.
GET /api/search calls it.
Records that a dump has a custom thumbnail of type mime, for
PUT /api/dumps/:dumpId/thumbnail, once the route has written the file.
Applies request to a dump, for PUT /api/dumps/:dumpId. A new link has its
preview fetched and gives the dump its page's title, unless request sets
one. A file dump ignores url. A new slug goes through changeSlug,
which exempt (a moderator) frees from its rate limit; a new title leaves
the slug as it is. Clients get the dump as dump_updated, or a
dump_deleted when it turns private and a dump_created when it turns
public. Anyone @mentioned in the note is notified, and when it turns public,
its followers are as when it is posted (notifyIfWentPublic).
Usage
import * as mod from "api/services/dump-service.ts";