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>
This commit is contained in:
7418andClaude Opus 4.6 committed 2026-02-13 18:13:06 +08:00
1 parent c21d8e4e90
commit 8f963ed2a9
2 files changed
+6 -2

No files matched your search

+3 -1
View File
@@ -13,6 +13,7 @@ import { cjk } from "@streamdown/cjk";
import { code } from "@streamdown/code";
import { math } from "@streamdown/math";
import { mermaid } from "@streamdown/mermaid";
import { usePanel } from "@/hooks/usePanel";
import type { FilePreview as FilePreviewType } from "@/types";
const streamdownPlugins = { cjk, code, math, mermaid };
@@ -52,6 +53,7 @@ export function DocPreview({
width,
}: DocPreviewProps) {
const { resolvedTheme } = useTheme();
const { workingDirectory } = usePanel();
const isDark = resolvedTheme === "dark";
const [preview, setPreview] = useState<FilePreviewType | null>(null);
const [loading, setLoading] = useState(true);
@@ -66,7 +68,7 @@ export function DocPreview({
setError(null);
try {
const res = await fetch(
`/api/files/preview?path=${encodeURIComponent(filePath)}&maxLines=500`
`/api/files/preview?path=${encodeURIComponent(filePath)}&maxLines=500${workingDirectory ? `&baseDir=${encodeURIComponent(workingDirectory)}` : ''}`
);
if (!res.ok) {
const data = await res.json();
+3 -1
View File
@@ -8,6 +8,7 @@ import { Badge } from "@/components/ui/badge";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Light as SyntaxHighlighter } from "react-syntax-highlighter";
import { atomOneDark } from "react-syntax-highlighter/dist/esm/styles/hljs";
import { usePanel } from "@/hooks/usePanel";
import type { FilePreview as FilePreviewType } from "@/types";
interface FilePreviewProps {
@@ -16,6 +17,7 @@ interface FilePreviewProps {
}
export function FilePreview({ filePath, onBack }: FilePreviewProps) {
const { workingDirectory } = usePanel();
const [preview, setPreview] = useState<FilePreviewType | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
@@ -27,7 +29,7 @@ export function FilePreview({ filePath, onBack }: FilePreviewProps) {
setError(null);
try {
const res = await fetch(
`/api/files/preview?path=${encodeURIComponent(filePath)}`
`/api/files/preview?path=${encodeURIComponent(filePath)}${workingDirectory ? `&baseDir=${encodeURIComponent(workingDirectory)}` : ''}`
);
if (!res.ok) {
const data = await res.json();