Skip to content

Update directory routes and services to include get_directory_content… #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions server/app/routes/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

logging.basicConfig(level=logging.INFO)

@directory_blueprint.route('/directory/<path:directory_path>', 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()
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/notebook/header/move/MoveDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const MoveDialog = ({

useEffect(() => {
const fetchDirectories = async () => {
const items = await DirectoryModel.getAllItems(directoryUrl);
const items = await DirectoryModel.getSubDirectories(directoryUrl);
setDirectories(items);
};

Expand Down
22 changes: 9 additions & 13 deletions webapp/src/models/DirectoryModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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;
})
Expand Down
Loading