From b2c16002e49056a154ff6c67ac342d686705f870 Mon Sep 17 00:00:00 2001 From: Sayo Date: Mon, 3 Nov 2025 03:17:54 +0800 Subject: [PATCH 1/2] fix: fix image viewer return 401 error --- src/components/ImageViewer.jsx | 92 +++++++++++++++++++++++++++------- 1 file changed, 74 insertions(+), 18 deletions(-) diff --git a/src/components/ImageViewer.jsx b/src/components/ImageViewer.jsx index b5077ae..15401a0 100644 --- a/src/components/ImageViewer.jsx +++ b/src/components/ImageViewer.jsx @@ -1,9 +1,63 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { Button } from './ui/button'; import { X } from 'lucide-react'; function ImageViewer({ file, onClose }) { const imagePath = `/api/projects/${file.projectName}/files/content?path=${encodeURIComponent(file.path)}`; + const [imageUrl, setImageUrl] = useState(null); + const [error, setError] = useState(null); + const [loading, setLoading] = useState(true); + + useEffect(() => { + let objectUrl; + const controller = new AbortController(); + + const loadImage = async () => { + try { + setLoading(true); + setError(null); + setImageUrl(null); + + const token = localStorage.getItem('auth-token'); + if (!token) { + setError('Missing authentication token'); + return; + } + + const response = await fetch(imagePath, { + headers: { + 'Authorization': `Bearer ${token}` + }, + signal: controller.signal + }); + + if (!response.ok) { + throw new Error(`Request failed with status ${response.status}`); + } + + const blob = await response.blob(); + objectUrl = URL.createObjectURL(blob); + setImageUrl(objectUrl); + } catch (err) { + if (err.name === 'AbortError') { + return; + } + console.error('Error loading image:', err); + setError('Unable to load image'); + } finally { + setLoading(false); + } + }; + + loadImage(); + + return () => { + controller.abort(); + if (objectUrl) { + URL.revokeObjectURL(objectUrl); + } + }; + }, [imagePath]); return (
@@ -23,22 +77,24 @@ function ImageViewer({ file, onClose }) {
- {file.name} { - e.target.style.display = 'none'; - e.target.nextSibling.style.display = 'block'; - }} - /> -
-

Unable to load image

-

{file.path}

-
+ {loading && ( +
+

Loading image…

+
+ )} + {!loading && imageUrl && ( + {file.name} + )} + {!loading && !imageUrl && ( +
+

{error || 'Unable to load image'}

+

{file.path}

+
+ )}
@@ -51,4 +107,4 @@ function ImageViewer({ file, onClose }) { ); } -export default ImageViewer; \ No newline at end of file +export default ImageViewer; From c875907f55b1382061841bacab009658c5ac57f5 Mon Sep 17 00:00:00 2001 From: LeoZheng1738 Date: Tue, 4 Nov 2025 11:33:58 +0800 Subject: [PATCH 2/2] fix(Sidebar): The undefined setShowSuggestions method has been removed. --- src/components/Sidebar.jsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/Sidebar.jsx b/src/components/Sidebar.jsx index cda6c5a..f5c3e06 100644 --- a/src/components/Sidebar.jsx +++ b/src/components/Sidebar.jsx @@ -484,7 +484,6 @@ function Sidebar({ setShowNewProject(false); setNewProjectPath(''); - setShowSuggestions(false); // Refresh projects to show the new one if (window.refreshProjects) { @@ -507,7 +506,6 @@ function Sidebar({ const cancelNewProject = () => { setShowNewProject(false); setNewProjectPath(''); - setShowSuggestions(false); }; const loadMoreSessions = async (project) => {