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.

Functions

f
createFileDump(
file: File,
comment: string | undefined,
userId: string,
isPrivate?: boolean,
title?: string,
categoryIds?: string[]
): Promise<Dump>

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.

f
createUrlDump(
request: CreateUrlDumpRequest,
userId: string
): Promise<Dump>

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.

f
customThumbnailPath(dumpId: string): string

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.

f
deleteDump(dumpId: string): Promise<void>

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.

f
findDumpsByUrl(
url: string,
requestingUserId?: string,
limit?: number
): DumpUrlMatch[]

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.

f
getDump(
dumpId: string,
requestingUserId?: string
): Dump

Returns dump dumpId as requestingUserId may see it. The routes resolve every :dumpId with it before acting on the dump.

f
getDumpByPath(
userId: string,
slug: string,
requestingUserId?: string
): 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.

f
getDumpsByUser(
userId: string,
page: number,
limit: number,
includePrivate: boolean,
categoryId?: string
): Page<Dump>

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.

f
getVotedDumpsByUser(
userId: string,
page: number,
limit: number,
requestingUserId: string | null,
categoryId?: string
): Page<Dump>

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.

f
listDumps(
page: number,
limit: number,
requestingUserId?: string
): Page<Dump>

Returns a page of the dumps requestingUserId may see, newest first, for the index feed (GET /api/dumps).

f
listTopDumps(
from: Date,
to: Date,
limit: number
): Dump[]

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.

f
refreshDumpMetadata(dumpId: string): Promise<Dump>

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.

f
removeDumpThumbnail(dumpId: string): Promise<Dump>

Removes a dump's custom thumbnail and its file, for DELETE /api/dumps/:dumpId/thumbnail.

f
replaceFileDump(
dumpId: string,
file: File,
comment: string | undefined,
title?: string,
categoryIds?: string[],
isPrivate?: boolean,
slug?: string,
exempt?: boolean
): Promise<Dump>

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.

f
searchDumps(
query: string,
page: number,
limit: number,
requestingUserId?: string,
categoryId?: string
): { items: Dump[]; total: number; }

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.

f
setDumpThumbnail(
dumpId: string,
mime: string
): Dump

Records that a dump has a custom thumbnail of type mime, for PUT /api/dumps/:dumpId/thumbnail, once the route has written the file.

f
updateDump(
dumpId: string,
request: UpdateDumpRequest,
exempt?: boolean
): Promise<Dump>

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).