From be471b309d415282942a2a3f3c536eae388f1e98 Mon Sep 17 00:00:00 2001 From: mrzengel Date: Sun, 20 Oct 2024 18:36:18 -0500 Subject: [PATCH] removed fetch in favor of requestAPI function for file retrieval --- src/components/FileBrowser.tsx | 17 ++++++++++------- zenodo_jupyterlab/server/handlers.py | 6 ++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/components/FileBrowser.tsx b/src/components/FileBrowser.tsx index 26e3a28..60efe6f 100644 --- a/src/components/FileBrowser.tsx +++ b/src/components/FileBrowser.tsx @@ -4,6 +4,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faFolder, faFile } from '@fortawesome/free-solid-svg-icons'; import { getServerRootDir } from '../API/API_functions'; import { FileEntry, OnSelectFile } from './type'; +import { requestAPI } from '../API/handler'; const useStyles = createUseStyles({ container: { @@ -134,16 +135,18 @@ const FileBrowser: React.FC = ({ onSelectFile }) => { try { if (!currentPath) return; console.log(currentPath, rootPath); - const response = await fetch(`/zenodo-jupyterlab/files?path=${encodeURIComponent('')}`); - if (response.ok) { - const data = await response.json(); - setEntries(data.entries || []); + const response = await requestAPI(`/zenodo-jupyterlab/files?path=${encodeURIComponent(currentPath)}`, { + method: 'GET' + }); + setEntries(response.entries || []); + /* if (response.ok) { + setEntries(response.entries || []); } else { setError('Failed to fetch file entries.'); - } - } catch (error) { + } */ + } catch { setError('Error fetching file entries.'); - console.error('Error fetching file entries:', error); + console.error('Error fetching file entries:'); } finally { setLoading(false); } diff --git a/zenodo_jupyterlab/server/handlers.py b/zenodo_jupyterlab/server/handlers.py index 7141b8f..d7ca0ab 100644 --- a/zenodo_jupyterlab/server/handlers.py +++ b/zenodo_jupyterlab/server/handlers.py @@ -68,11 +68,9 @@ class FileBrowserHandler(APIHandler): async def get(self): # Use the home directory as the root directory #root_dir = os.getenv("HOME") - """ relative_path = self.get_query_argument('path', '') + relative_path = self.get_query_argument('path', '') full_path = os.path.join(os.getcwd(), relative_path) - print(relative_path, full_path) """ - - full_path = '/home/jovyan' + print(relative_path, full_path) if '..' in full_path or not os.path.isdir(full_path): self.set_status(404)