Ties each image pasted into a Markdown body to the dump, comment, playlist or message that links it, so the image is served only to those who may see that, and purged at startup once it is gone. routes/attachments.ts stores and serves the files; the services that save a body call linkAttachments.

Functions

f
createAttachment(
id: string,
mime: string
): void

Records attachment id once POST /api/attachments has written its file. Until a saved body links it, the startup purge deletes it after ORPHANED_ATTACHMENTS_RETENTION_HOURS.

f
getAttachmentAccess(attachmentId: string): AttachmentAccess

Returns attachment attachmentId's type and who may see it. An attachment nothing links yet is public, so the editor can show it before the text is saved; its id is unguessable. One linked by a private dump or playlist, or by a comment on a private dump, is its owner's.

f
linkAttachments(
text: string,
resourceType: AttachmentResourceType,
resourceId: string
): void

Binds the attachments whose URLs appear in text to the resource that saved it, so the startup purge keeps them as long as that resource exists, and they are seen by whoever may see it. It is called whenever a dump, comment, chat message, playlist or profile description is saved. An attachment already bound stays with its resource, so pasting another's URL claims nothing, and removing the link from a body never unbinds it.

Interfaces

I
AttachmentAccess

Returned to GET /api/attachments/:attachmentId by getAttachmentAccess. ownerId is set when only that user may see the image, because the resource linking it is private.

Type Aliases

T
AttachmentResourceType = "dump" | "comment" | "playlist" | "chat" | "user"

Stored in attachments.resource_type by bindAttachments, it names the kind of resource whose saved text links the attachment.