Skip to content

Commit 27805ef

Browse files
fix(web): preview images outside the workspace (#24627)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 95ffbc9 commit 27805ef

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

‎apps/web/src/components/files/FilePreviewPanel.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,26 @@ describe("workspaceAssetResource", () => {
110110
absolutePath: "/repo/docs/index.html",
111111
};
112112

113+
// regression: #21067 images outside the workspace load through the host media resource
114+
it("serves a file outside the workspace as host media and keeps workspace files on workspace access", () => {
115+
expect(
116+
workspaceAssetResource({ ...input, absolutePath: "/tmp/screenshots/shot.png", draft: false }),
117+
).toEqual({ _tag: "media-file", threadId: "thread-1", path: "/tmp/screenshots/shot.png" });
118+
expect(workspaceAssetResource({ ...input, draft: false })).toEqual({
119+
_tag: "workspace-file",
120+
threadId: "thread-1",
121+
path: "/repo/docs/index.html",
122+
});
123+
});
124+
113125
it("names the workspace root for a draft, which the server cannot resolve from a thread", () => {
114126
expect(workspaceAssetResource({ ...input, draft: true })).toEqual({
115127
_tag: "draft-workspace-file",
116128
cwd: "/repo",
117129
path: "/repo/docs/index.html",
118130
});
131+
expect(
132+
workspaceAssetResource({ ...input, absolutePath: "/tmp/screenshots/shot.png", draft: true }),
133+
).toEqual({ _tag: "draft-workspace-file", cwd: "/repo", path: "/tmp/screenshots/shot.png" });
119134
});
120135
});

‎apps/web/src/components/files/FilePreviewPanel.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,8 @@ function WorkspaceBrowserPreview(props: {
225225
readonly title: string;
226226
readonly workspaceMutationId: string | null;
227227
}) {
228-
const insideWorkspace =
229-
mediaFileReference(props.absolutePath, props.workspaceRoot).relativePath !== undefined;
230228
const resource = workspaceAssetResource({
231-
kind: insideWorkspace ? "workspace-file" : "media-file",
229+
kind: "workspace-file",
232230
threadRef: props.threadRef,
233231
draft: props.draft,
234232
workspaceRoot: props.workspaceRoot,

‎apps/web/src/components/files/filePreviewMode.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { AssetResource, ProjectReadFileError, ScopedThreadRef } from "@t3tools/contracts";
2+
import { mediaFileReference } from "@t3tools/client-runtime/media-reference";
23
import { isHostPath, workspaceRelativeFilePath } from "@t3tools/shared/path";
34

45
export function resolveFilePreviewPath(path: string | null, cwd: string): string | null {
@@ -55,6 +56,11 @@ export function setMarkdownTaskChecked(
5556
return `${markdown.slice(0, markerOffset + 1)}${checked ? "x" : " "}${markdown.slice(markerOffset + 2)}`;
5657
}
5758

59+
/**
60+
* The server only signs `workspace-file` assets below the workspace root, so a
61+
* file opened from outside it, such as an absolute link in the thread, goes
62+
* through the host `media-file` resource the direct media viewer uses.
63+
*/
5864
export function workspaceAssetResource(input: {
5965
readonly kind: "workspace-file" | "media-file";
6066
readonly threadRef: ScopedThreadRef;
@@ -65,5 +71,11 @@ export function workspaceAssetResource(input: {
6571
if (input.draft) {
6672
return { _tag: "draft-workspace-file", cwd: input.workspaceRoot, path: input.absolutePath };
6773
}
68-
return { _tag: input.kind, threadId: input.threadRef.threadId, path: input.absolutePath };
74+
const insideWorkspace =
75+
mediaFileReference(input.absolutePath, input.workspaceRoot).relativePath !== undefined;
76+
return {
77+
_tag: insideWorkspace ? input.kind : "media-file",
78+
threadId: input.threadRef.threadId,
79+
path: input.absolutePath,
80+
};
6981
}

0 commit comments

Comments
 (0)