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]>
This commit is contained in:
@@ -3,9 +3,7 @@ import type {
|
||||
BUN_SQLITE_COBBLE_BOT_FILES,
|
||||
BUN_SQLITE_COBBLE_MEDIA,
|
||||
} from "@/db/types/db";
|
||||
import grabCrewRole from "../access/grab-crew-role";
|
||||
import grabUserBot from "../bots/grab-user-bot";
|
||||
import grabUserWorkspace from "../workspaces/grab-user-workspace";
|
||||
import userReachesFileScope from "./user-reaches-file-scope";
|
||||
|
||||
type Params = {
|
||||
media_id: number | string;
|
||||
@@ -32,20 +30,7 @@ export default async function grabBotFileMedia({
|
||||
|
||||
if (!file?.id) return null;
|
||||
|
||||
const role = await grabCrewRole({ user_id });
|
||||
const reaches =
|
||||
file.scope == "workspace"
|
||||
? Boolean(
|
||||
await grabUserWorkspace({
|
||||
workspace_id: file.owner_id!,
|
||||
user_id,
|
||||
}),
|
||||
)
|
||||
: role == "super_admin"
|
||||
? true
|
||||
: Boolean(await grabUserBot({ bot_id: file.owner_id!, user_id }));
|
||||
|
||||
if (!reaches) return null;
|
||||
if (!(await userReachesFileScope({ scope: file.scope, owner_id: file.owner_id, user_id }))) return null;
|
||||
|
||||
const media = await BunSQLite.sql<BUN_SQLITE_COBBLE_MEDIA>({
|
||||
sql: `SELECT * FROM media WHERE id = ? LIMIT 1`,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
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) };
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import grabCrewRole from "../access/grab-crew-role";
|
||||
import grabUserBot from "../bots/grab-user-bot";
|
||||
import grabUserWorkspace from "../workspaces/grab-user-workspace";
|
||||
|
||||
type Params = {
|
||||
scope?: string | null;
|
||||
owner_id?: number | string | null;
|
||||
user_id: number | string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether a user reaches a bot file's directory: the workspace it's shared
|
||||
* in, or the bot's own (any bot for the super admin, else the bots the user
|
||||
* reaches). Files belong to the install, like the crew, so whoever sees the
|
||||
* bot sees what it saved.
|
||||
*/
|
||||
export default async function userReachesFileScope({ scope, owner_id, user_id }: Params) {
|
||||
if (!owner_id) return false;
|
||||
|
||||
if (scope == "workspace") {
|
||||
return Boolean(await grabUserWorkspace({ workspace_id: owner_id, user_id }));
|
||||
}
|
||||
|
||||
if ((await grabCrewRole({ user_id })) == "super_admin") return true;
|
||||
|
||||
return Boolean(await grabUserBot({ bot_id: owner_id, user_id }));
|
||||
}
|
||||
Reference in New Issue
Block a user