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.
33 lines
1.3 KiB
TypeScript
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;
|
|
}
|