GeezerVison is showing github.com — fix(web): preview images outside the workspace (#24627) · Pipyakas/t3code@27805ef
File treeExpand file treeCollapse file tree Open diff view settings apps/web/src/components/files
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/files/FilePreviewPanel.test.ts +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -110,11 +110,26 @@ describe("workspaceAssetResource", () => { | 110 | 110 | absolutePath: "/repo/docs/index.html", | 111 | 111 | }; | 112 | 112 |
| | 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 | + | 113 | 125 | it("names the workspace root for a draft, which the server cannot resolve from a thread", () => { | 114 | 126 | expect(workspaceAssetResource({ ...input, draft: true })).toEqual({ | 115 | 127 | _tag: "draft-workspace-file", | 116 | 128 | cwd: "/repo", | 117 | 129 | path: "/repo/docs/index.html", | 118 | 130 | }); | | 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" }); | 119 | 134 | }); | 120 | 135 | }); |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/files/FilePreviewPanel.tsx +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -225,10 +225,8 @@ function WorkspaceBrowserPreview(props: { | 225 | 225 | readonly title: string; | 226 | 226 | readonly workspaceMutationId: string | null; | 227 | 227 | }) { | 228 | | - const insideWorkspace = | 229 | | - mediaFileReference(props.absolutePath, props.workspaceRoot).relativePath !== undefined; | 230 | 228 | const resource = workspaceAssetResource({ | 231 | | - kind: insideWorkspace ? "workspace-file" : "media-file", | | 229 | + kind: "workspace-file", | 232 | 230 | threadRef: props.threadRef, | 233 | 231 | draft: props.draft, | 234 | 232 | workspaceRoot: props.workspaceRoot, | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/files/filePreviewMode.ts +13-1Lines changed: 13 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import type { AssetResource, ProjectReadFileError, ScopedThreadRef } from "@t3tools/contracts"; | | 2 | +import { mediaFileReference } from "@t3tools/client-runtime/media-reference"; | 2 | 3 | import { isHostPath, workspaceRelativeFilePath } from "@t3tools/shared/path"; | 3 | 4 |
| 4 | 5 | export function resolveFilePreviewPath(path: string | null, cwd: string): string | null { | @@ -55,6 +56,11 @@ export function setMarkdownTaskChecked( | 55 | 56 | return `${markdown.slice(0, markerOffset + 1)}${checked ? "x" : " "}${markdown.slice(markerOffset + 2)}`; | 56 | 57 | } | 57 | 58 |
| | 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 | + */ | 58 | 64 | export function workspaceAssetResource(input: { | 59 | 65 | readonly kind: "workspace-file" | "media-file"; | 60 | 66 | readonly threadRef: ScopedThreadRef; | @@ -65,5 +71,11 @@ export function workspaceAssetResource(input: { | 65 | 71 | if (input.draft) { | 66 | 72 | return { _tag: "draft-workspace-file", cwd: input.workspaceRoot, path: input.absolutePath }; | 67 | 73 | } | 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 | + }; | 69 | 81 | } |
|