diff --git a/server/app/routes/directory.py b/server/app/routes/directory.py index a0110fa..9ba8138 100644 --- a/server/app/routes/directory.py +++ b/server/app/routes/directory.py @@ -6,6 +6,10 @@ logging.basicConfig(level=logging.INFO) +@directory_blueprint.route('/directory/', methods=['GET']) +def get_directory_content(directory_path): + return Directory.get_content_by_path(path=directory_path) + @directory_blueprint.route('/directory', methods=['POST']) def create_directory(): data = request.get_json() diff --git a/webapp/src/App.js b/webapp/src/App.js index 8730874..6a371a4 100644 --- a/webapp/src/App.js +++ b/webapp/src/App.js @@ -48,7 +48,7 @@ const App = () => { // Workspace useEffect(() => { if (openWorkspaceDrawer) { - DirectoryModel.getFiles(baseUrl + currentPath) // Fetch files from the root or specify a path + DirectoryModel.getChildren(currentPath) // Fetch files from the root or specify a path .then(setWorkspaceFiles) .catch(error => console.error('Failed to fetch files:', error)); console.log('Fetched workspace files:', workspaceFiles); diff --git a/webapp/src/components/notebook/header/move/MoveDialog.js b/webapp/src/components/notebook/header/move/MoveDialog.js index bf8dbe0..8a5babc 100644 --- a/webapp/src/components/notebook/header/move/MoveDialog.js +++ b/webapp/src/components/notebook/header/move/MoveDialog.js @@ -22,7 +22,7 @@ const MoveDialog = ({ useEffect(() => { const fetchDirectories = async () => { - const items = await DirectoryModel.getAllItems(directoryUrl); + const items = await DirectoryModel.getSubDirectories(directoryUrl); setDirectories(items); }; diff --git a/webapp/src/models/DirectoryModel.js b/webapp/src/models/DirectoryModel.js index 964ffa6..89cc097 100644 --- a/webapp/src/models/DirectoryModel.js +++ b/webapp/src/models/DirectoryModel.js @@ -26,25 +26,21 @@ class DirectoryModel { return this.getDirectories().every(directory => directory.name !== name); } - static async getFiles(path = '') { - const url = new URL(path); - url.searchParams.append('t', Date.now()); // Append current timestamp as query parameter - const response = await fetch(url, { - method: 'GET', - redirect: "follow" - }); + static async getChildren(path = '') { + const response = await fetch("http://localhost:5002/directory/" + path); if (!response.ok) { throw new Error('Failed to fetch files'); + } else { + const data = await response.json(); + return data.content; } - const data = await response.json(); - return data.content; // Assuming the API returns a 'content' array } - static async getAllItems(path = '') { - const items = await this.getFiles(path); + static async getSubDirectories(path = '') { + const items = await this.getChildren(path); const promises = items.map(async (item) => { if (item.type === 'directory') { - item.children = await this.getAllItems(`${path}/${item.name}`); + item.children = await this.getSubDirectories(`${path}/${item.name}`); } return item; }); @@ -90,7 +86,7 @@ class DirectoryModel { NotebookModel.deleteNotebook(item.path); } else { let folderItems = []; - await DirectoryModel.getFiles(itemPath) + await DirectoryModel.getChildren(itemPath) .then((data) => { folderItems = data; })