Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions apps/server/src/assets/AssetAccess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,49 @@ describe("AssetAccess", () => {
}).pipe(Effect.provide(testLayer)),
);

it.effect("previews workspace files with literal fragment characters in their paths", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const root = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-preview-literal-" });
const directory = path.join(root, "assets#archive");
yield* fileSystem.makeDirectory(directory);

for (const name of ["icon#v2.png", "report#draft.pdf"]) {
const filePath = path.join(directory, name);
yield* fileSystem.writeFileString(filePath, "preview fixture");
const canonicalFile = yield* fileSystem.realPath(filePath);
const result = yield* issueAssetUrl({
resource: {
_tag: "workspace-file",
threadId: ThreadId.make("thread-1"),
path: filePath,
},
workspaceRoot: root,
});
const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
const token = suffix.slice(0, suffix.indexOf("/"));

expect(yield* resolveAsset(token, name)).toEqual({ kind: "file", path: canonicalFile });
if (name.endsWith(".png")) {
expect(yield* resolveAsset(token, "other.png")).toBeNull();
}
}

const disguisedPath = path.join(root, "image.png#notes.txt");
yield* fileSystem.writeFileString(disguisedPath, "not an image");
const error = yield* issueAssetUrl({
resource: {
_tag: "workspace-file",
threadId: ThreadId.make("thread-1"),
path: disguisedPath,
},
workspaceRoot: root,
}).pipe(Effect.flip);
expect(error).toBeInstanceOf(AssetPreviewTypeValidationError);
}).pipe(Effect.provide(testLayer)),
);

it.effect("issues exact attachment capabilities by attachment id", () =>
Effect.gen(function* () {
const config = yield* ServerConfig.ServerConfig;
Expand Down
3 changes: 3 additions & 0 deletions docs/user/composer.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,5 +274,8 @@ On web and desktop, HTML and PDF files open as rendered pages. Switch an HTML
file to source view to read its markup; a link to a specific line opens source
automatically. HTML previews cannot access your T3 Code session.

The file viewer recognizes images, HTML, and PDF files by their filename extension,
including filenames or folders containing `#` or `?`.

On mobile, select a PDF attachment or link to open it. iOS uses the native viewer;
Android opens a compatible installed file viewer.
25 changes: 17 additions & 8 deletions packages/shared/src/filePreview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from "./filePreview.ts";

describe("workspace file previews", () => {
it.each(["report.html", "report.HTM", "document.pdf?download=1"])(
it.each(["report.html", "report.HTM", "document#draft.pdf", "reports?old/document.pdf"])(
"recognizes browser preview path %s",
(path) => {
expect(isWorkspaceBrowserPreviewPath(path)).toBe(true);
Expand All @@ -26,20 +26,29 @@ describe("workspace file previews", () => {
"icon.png",
"photo.JPEG",
"animation.gif",
"vector.svg#mark",
"vector#mark.svg",
"photo?edited.JPEG",
"images#archive/icon.png",
"texture.webp",
"image.avif",
])("recognizes image preview path %s", (path) => {
expect(isWorkspaceImagePreviewPath(path)).toBe(true);
expect(isWorkspacePreviewEntryPath(path)).toBe(true);
});

it.each(["README.md", "src/index.ts", "image.png.ts", "png"])(
"rejects non-preview path %s",
(path) => {
expect(isWorkspacePreviewEntryPath(path)).toBe(false);
},
);
it.each([
"README.md",
"src/index.ts",
"image.png.ts",
"png",
"image.png#notes.txt",
"image.svg?notes.txt",
"document.pdf?download=1",
"report.html#notes.txt",
"image%2Epng",
])("rejects non-preview path %s", (path) => {
expect(isWorkspacePreviewEntryPath(path)).toBe(false);
});

it("serves audio in place from the host like video and browser documents", () => {
expect(isWorkspaceAudioPreviewPath("notes/recording.WAV")).toBe(true);
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/filePreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ export function mediaKindFromPath(path: string): "image" | "video" | null {
}

function hasPreviewExtension(path: string, extensions: ReadonlyArray<string>): boolean {
const pathWithoutQuery = path.split(/[?#]/, 1)[0]?.toLowerCase() ?? "";
return extensions.some((extension) => pathWithoutQuery.endsWith(extension));
const literalPath = path.toLowerCase();
return extensions.some((extension) => literalPath.endsWith(extension));
}

export function isWorkspaceBrowserPreviewPath(path: string): boolean {
Expand Down
Loading