Skip to content

Commit 8f963ed

Browse files
7418claude
andcommitted
fix: pass baseDir to file preview API to fix Windows cross-drive 403
FilePreview and DocPreview components were not passing baseDir to the preview API, causing 403 "File is outside the allowed scope" on Windows when the project is on a different drive than home. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c21d8e4 commit 8f963ed

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/components/layout/DocPreview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { cjk } from "@streamdown/cjk";
1313
import { code } from "@streamdown/code";
1414
import { math } from "@streamdown/math";
1515
import { mermaid } from "@streamdown/mermaid";
16+
import { usePanel } from "@/hooks/usePanel";
1617
import type { FilePreview as FilePreviewType } from "@/types";
1718

1819
const streamdownPlugins = { cjk, code, math, mermaid };
@@ -52,6 +53,7 @@ export function DocPreview({
5253
width,
5354
}: DocPreviewProps) {
5455
const { resolvedTheme } = useTheme();
56+
const { workingDirectory } = usePanel();
5557
const isDark = resolvedTheme === "dark";
5658
const [preview, setPreview] = useState<FilePreviewType | null>(null);
5759
const [loading, setLoading] = useState(true);
@@ -66,7 +68,7 @@ export function DocPreview({
6668
setError(null);
6769
try {
6870
const res = await fetch(
69-
`/api/files/preview?path=${encodeURIComponent(filePath)}&maxLines=500`
71+
`/api/files/preview?path=${encodeURIComponent(filePath)}&maxLines=500${workingDirectory ? `&baseDir=${encodeURIComponent(workingDirectory)}` : ''}`
7072
);
7173
if (!res.ok) {
7274
const data = await res.json();

src/components/project/FilePreview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Badge } from "@/components/ui/badge";
88
import { ScrollArea } from "@/components/ui/scroll-area";
99
import { Light as SyntaxHighlighter } from "react-syntax-highlighter";
1010
import { atomOneDark } from "react-syntax-highlighter/dist/esm/styles/hljs";
11+
import { usePanel } from "@/hooks/usePanel";
1112
import type { FilePreview as FilePreviewType } from "@/types";
1213

1314
interface FilePreviewProps {
@@ -16,6 +17,7 @@ interface FilePreviewProps {
1617
}
1718

1819
export function FilePreview({ filePath, onBack }: FilePreviewProps) {
20+
const { workingDirectory } = usePanel();
1921
const [preview, setPreview] = useState<FilePreviewType | null>(null);
2022
const [loading, setLoading] = useState(true);
2123
const [error, setError] = useState<string | null>(null);
@@ -27,7 +29,7 @@ export function FilePreview({ filePath, onBack }: FilePreviewProps) {
2729
setError(null);
2830
try {
2931
const res = await fetch(
30-
`/api/files/preview?path=${encodeURIComponent(filePath)}`
32+
`/api/files/preview?path=${encodeURIComponent(filePath)}${workingDirectory ? `&baseDir=${encodeURIComponent(workingDirectory)}` : ''}`
3133
);
3234
if (!res.ok) {
3335
const data = await res.json();

0 commit comments

Comments
 (0)