Merge pull request #727 from kubet/fix/share-page-file-load

fix: share page file load
This commit is contained in:
kubet 2025-06-13 19:52:16 +02:00 committed by GitHub
commit c2461bdb92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 13 deletions

View File

@ -117,10 +117,13 @@ export async function fetchFileContent(
console.log(`[FILE QUERY] Fetching ${contentType} content for: ${normalizedPath}`);
const headers: Record<string, string> = {};
if (token) {
headers['Authorization'] = `Bearer ${token}`;
}
const response = await fetch(url.toString(), {
headers: {
'Authorization': `Bearer ${token}`,
},
headers,
});
if (!response.ok) {
@ -218,13 +221,13 @@ export function useFileContentQuery(
queryKey: sandboxId && normalizedPath ?
fileQueryKeys.content(sandboxId, normalizedPath, effectiveContentType) : [],
queryFn: async () => {
if (!sandboxId || !normalizedPath || !session?.access_token) {
if (!sandboxId || !normalizedPath) {
throw new Error('Missing required parameters');
}
return fetchFileContent(sandboxId, normalizedPath, effectiveContentType, session.access_token);
return fetchFileContent(sandboxId, normalizedPath, effectiveContentType, session?.access_token || '');
},
enabled: Boolean(sandboxId && normalizedPath && session?.access_token && (options.enabled !== false)),
enabled: Boolean(sandboxId && normalizedPath && (options.enabled !== false)),
staleTime: options.staleTime || (effectiveContentType === 'blob' ? 5 * 60 * 1000 : 2 * 60 * 1000), // 5min for blobs, 2min for text
gcTime: options.gcTime || 10 * 60 * 1000, // 10 minutes
retry: (failureCount, error: any) => {
@ -279,14 +282,14 @@ export function useDirectoryQuery(
queryKey: sandboxId && normalizedPath ?
fileQueryKeys.directory(sandboxId, normalizedPath) : [],
queryFn: async (): Promise<FileInfo[]> => {
if (!sandboxId || !normalizedPath || !session?.access_token) {
if (!sandboxId || !normalizedPath) {
throw new Error('Missing required parameters');
}
console.log(`[FILE QUERY] Fetching directory listing for: ${normalizedPath}`);
return await listSandboxFiles(sandboxId, normalizedPath);
},
enabled: Boolean(sandboxId && normalizedPath && session?.access_token && (options.enabled !== false)),
enabled: Boolean(sandboxId && normalizedPath && (options.enabled !== false)),
staleTime: options.staleTime || 30 * 1000, // 30 seconds for directory listings
gcTime: 5 * 60 * 1000, // 5 minutes
retry: 2,

View File

@ -129,10 +129,13 @@ export function useCachedFile<T = string>(
// Fetch with authentication
const attemptFetch = async (isRetry: boolean = false): Promise<Response> => {
const headers: Record<string, string> = {};
if (session?.access_token) {
headers['Authorization'] = `Bearer ${session.access_token}`;
}
const response = await fetch(url.toString(), {
headers: {
'Authorization': `Bearer ${session?.access_token}`
}
headers
});
if (!response.ok) {

View File

@ -21,7 +21,7 @@ export function useFileContent(sandboxId?: string, filePath?: string) {
const { session } = useAuth();
useEffect(() => {
if (!sandboxId || !filePath || !session?.access_token) {
if (!sandboxId || !filePath) {
setContent(null);
return;
}
@ -38,7 +38,7 @@ export function useFileContent(sandboxId?: string, filePath?: string) {
// Otherwise, load and cache the file content
setIsLoading(true);
getCachedFile(sandboxId, filePath, {
token: session.access_token,
token: session?.access_token || '',
contentType: 'text'
})
.then(fileContent => {