Skip to content

Commit

Permalink
removed fetch in favor of requestAPI function for file retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
mrzengel committed Oct 20, 2024
1 parent 5815067 commit be471b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
17 changes: 10 additions & 7 deletions src/components/FileBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -134,16 +135,18 @@ const FileBrowser: React.FC<FileBrowserProps> = ({ 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);
}
Expand Down
6 changes: 2 additions & 4 deletions zenodo_jupyterlab/server/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit be471b3

Please sign in to comment.