Files
cobble/src/functions/backend/db/bot-files/grab-bot-file-scope.ts
T
tbenandClaude Opus 5.5 184407d76b Keep file refs working in answers passed on from chatrooms
A ref quoted alone in a code span now links like any ref, and refs
inside longer code stay literal instead of turning into broken link
text. A file chip opens a file from another bot's folder for a user
who reaches that folder, by the same rule as its bytes, so the
asked bot's files open from the asking bot's conversation. Bots are
told to keep refs out of backticks, and the coordinator to pass them
on as given.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 19:02:19 +01:00

25 lines
847 B
TypeScript

import BunSQLite from "@moduletrace/bun-sqlite";
import type { BUN_SQLITE_COBBLE_BOT_FILES } from "@/db/types/db";
import type { StorageScope } from "@/src/utils/storage-access";
type Params = {
file_id: number | string;
};
/**
* The directory a bot file is in, unchecked: callers check the user
* reaches it (`userReachesFileScope`) before showing the file.
*/
export default async function grabBotFileScope({ file_id }: Params): Promise<StorageScope | null> {
const row = (
await BunSQLite.sql<BUN_SQLITE_COBBLE_BOT_FILES>({
sql: `SELECT scope, owner_id FROM bot_files WHERE id = ? LIMIT 1`,
values: [file_id],
})
).payload?.[0];
if (!row?.owner_id || (row.scope != "bot" && row.scope != "workspace")) return null;
return { scope: row.scope, owner_id: Number(row.owner_id) };
}