There is no public media any more. `/media/public/<id>` served a media row with no session at all, so anyone with the id could read a file. The public/private split is gone: the path is `/media/<id>` (and `/media/<id>/thumbnail`), every request is signed in first, and `grabUserMedia` decides whether the user may see it: their own upload, a bot's or workspace's picture or file they reach, or a file on a task they reach. Anything else is a 404 before a path is built. The `media.is_private` column and the two per-user directories went with it: uploads live in `media/<user_id>/` and there is nothing to pick between. The files browser's media volume is now the viewer's own folder whatever their role. Bots also say which of the two things they mean. A `[file:ID]` ref is a saved file and its chip opens the bytes; a folder is a new `[folder:volume:owner:path]` ref (`src/utils/folder-ref.ts`) whose chip opens the files browser there and downloads nothing. The old `[path:...]` ref and the extension sniffing that guessed file from folder are gone, so `import_file` names the folder holding a file it copied rather than the file itself. The prompts say what the Assistant got wrong: list before importing or saving, one copy per artifact, never split a file into parts unless asked, never claim the store is empty without a fresh list, and never invent a size cap. A re-import now says the path already existed instead of silently overwriting and reporting a fresh copy.
90 lines
3.4 KiB
TypeScript
90 lines
3.4 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import {
|
|
StorageBrowserPath,
|
|
isSameStorageSpec,
|
|
isStorageVolume,
|
|
parseStorageSpec,
|
|
storagePathName,
|
|
storageSpecHref,
|
|
storageVolumeFromRef,
|
|
storageVolumeLabel,
|
|
storageVolumeNeedsOwner,
|
|
} from "./storage-volumes";
|
|
|
|
describe("parseStorageSpec", () => {
|
|
test("reads a volume and its owner", () => {
|
|
expect(parseStorageSpec({ volume: "computers", owner_id: "3" })).toEqual({
|
|
volume: "computers",
|
|
owner_id: 3,
|
|
});
|
|
});
|
|
|
|
test("gives the database no owner", () => {
|
|
expect(parseStorageSpec({ volume: "db", owner_id: "999" })).toEqual({
|
|
volume: "db",
|
|
owner_id: 0,
|
|
});
|
|
});
|
|
|
|
test("refuses an unknown volume", () => {
|
|
expect(parseStorageSpec({ volume: "secrets", owner_id: 1 })).toBeNull();
|
|
expect(parseStorageSpec({ volume: "", owner_id: 1 })).toBeNull();
|
|
expect(parseStorageSpec({ volume: null, owner_id: 1 })).toBeNull();
|
|
});
|
|
|
|
test("refuses a missing or bad owner", () => {
|
|
expect(parseStorageSpec({ volume: "bots" })).toBeNull();
|
|
expect(parseStorageSpec({ volume: "bots", owner_id: 0 })).toBeNull();
|
|
expect(parseStorageSpec({ volume: "bots", owner_id: -2 })).toBeNull();
|
|
expect(parseStorageSpec({ volume: "bots", owner_id: "abc" })).toBeNull();
|
|
expect(parseStorageSpec({ volume: "bots", owner_id: "../../etc" })).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("storageSpecHref", () => {
|
|
test("builds the browser's address", () => {
|
|
expect(storageSpecHref({ spec: { volume: "bots", owner_id: 3 } })).toBe(
|
|
`${StorageBrowserPath}?volume=bots&owner=3`,
|
|
);
|
|
});
|
|
|
|
test("adds and encodes a path", () => {
|
|
expect(
|
|
storageSpecHref({ spec: { volume: "computers", owner_id: 1 }, path: "/seo/raw mes/" }),
|
|
).toBe(`${StorageBrowserPath}?volume=computers&owner=1&path=seo%2Fraw+mes`);
|
|
});
|
|
});
|
|
|
|
describe("volume names", () => {
|
|
test("maps a folder ref's name to its volume", () => {
|
|
expect(storageVolumeFromRef({ name: "computer" })).toBe("computers");
|
|
expect(storageVolumeFromRef({ name: "bot" })).toBe("bots");
|
|
expect(storageVolumeFromRef({ name: "nope" })).toBeNull();
|
|
expect(storageVolumeFromRef({ name: null })).toBeNull();
|
|
});
|
|
|
|
test("knows which volumes need an owner", () => {
|
|
expect(storageVolumeNeedsOwner({ volume: "db" })).toBe(false);
|
|
expect(storageVolumeNeedsOwner({ volume: "media" })).toBe(true);
|
|
expect(isStorageVolume("mcp")).toBe(true);
|
|
expect(isStorageVolume("Media")).toBe(false);
|
|
});
|
|
|
|
test("labels a volume and a path", () => {
|
|
expect(storageVolumeLabel({ volume: "mcp" })).toBe("MCP servers");
|
|
expect(storagePathName({ volume: "computers", path: "seo/coderank/raw" })).toBe("raw");
|
|
expect(storagePathName({ volume: "computers", path: "" })).toBe("Computers");
|
|
});
|
|
});
|
|
|
|
describe("isSameStorageSpec", () => {
|
|
test("compares volume and owner", () => {
|
|
const a = { volume: "bots", owner_id: 1 } as const;
|
|
|
|
expect(isSameStorageSpec({ a, b: { volume: "bots", owner_id: 1 } })).toBe(true);
|
|
expect(isSameStorageSpec({ a, b: { volume: "bots", owner_id: 2 } })).toBe(false);
|
|
expect(isSameStorageSpec({ a, b: { volume: "workspaces", owner_id: 1 } })).toBe(false);
|
|
expect(isSameStorageSpec({ a, b: null })).toBe(false);
|
|
});
|
|
});
|