GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): preview images outside the workspace (#24627) · Pipyakas/t3code@27805ef

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/components/files
    • FilePreviewPanel.test.ts
    • FilePreviewPanel.tsx
    • filePreviewMode.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: apps/web/src/components/files/FilePreviewPanel.test.ts
+15Lines 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
});
Collapse file

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

Copy file name to clipboardExpand all lines: apps/web/src/components/files/FilePreviewPanel.tsx
+1-3Lines 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,
Collapse file

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

Copy file name to clipboardExpand all lines: apps/web/src/components/files/filePreviewMode.ts
+13-1Lines 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 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.