Files
cobble/src/functions/backend/db/access/grab-shared-picture-media.ts
T
tben b5c3b7d126 Share every picture with everyone signed in
A profile photo, a bot's picture and a workspace's picture all come from
one condition now (sharedPictureMediaSql), so a face is never blank just
because its owner isn't in the viewer's rail. Anything that isn't a
picture stays behind its own check.
2026-10-23 06:01:34 +01:00

33 lines
1.3 KiB
TypeScript

import BunSQLite from "@moduletrace/bun-sqlite";
import type { BUN_SQLITE_COBBLE_MEDIA } from "@/db/types/db";
import sharedPictureMediaSql from "./shared-picture-media-sql";
type Params = {
media_id: number | string;
};
/**
* A picture every signed-in user may see - a member's current profile photo,
* a bot's picture, a workspace's picture (`sharedPictureMediaSql`) - or
* null when this media is something else.
*
* Which crew the viewer reaches plays no part: bots and workspaces belong to
* the install, and people know each other by their photo, so a picture is
* shared with everyone signed in. Everything a picture must not expose (a
* bot's files, a task's deliverable, someone's chat upload) stays behind
* its own check, and a removed picture stops being shared as soon as no
* user, bot or workspace points at it.
*/
export default async function grabSharedPictureMedia({ media_id }: Params) {
if (!media_id) return null;
const condition = sharedPictureMediaSql({ alias: "m" });
const res = await BunSQLite.sql<BUN_SQLITE_COBBLE_MEDIA>({
sql: `SELECT m.* FROM media m WHERE m.id = ? AND COALESCE(m.archived, 0) <> 1 AND ${condition.sql} LIMIT 1`,
values: [media_id, ...condition.values],
});
return res.payload?.[0] || null;
}