diff --git a/server/app/routes/notebook.py b/server/app/routes/notebook.py index 56c1905..17fc054 100644 --- a/server/app/routes/notebook.py +++ b/server/app/routes/notebook.py @@ -15,6 +15,10 @@ def notebook(): def get_all_notebooks(): return Notebook.get_all_notebooks() +@notebook_blueprint.route('/notebook/', methods=['GET']) +def get_notebook_by_path(notebook_path): + return Notebook.get_notebook_by_path(notebook_path=notebook_path) + @notebook_blueprint.route('/notebook', methods=['POST']) def create_notebook(): data = request.get_json() diff --git a/server/app/services/notebook.py b/server/app/services/notebook.py index 2f5bf49..9ade117 100644 --- a/server/app/services/notebook.py +++ b/server/app/services/notebook.py @@ -19,6 +19,15 @@ def get_all_notebooks(): notebooks_json = json.dumps(notebooks_dict) return notebooks_json + + @staticmethod + def get_notebook_by_path(notebook_path: str = None): + jupyter_server_path = os.environ.get("JUPYTER_SERVER_PATH", "http://localhost:8888") + + path = f"{jupyter_server_path}/api/contents/{notebook_path}" + response = requests.get(path) + + return response.json() @staticmethod def create_notebook(notebook_name: str = None) -> None: diff --git a/webapp/src/App.js b/webapp/src/App.js index a822e23..d1d5287 100644 --- a/webapp/src/App.js +++ b/webapp/src/App.js @@ -76,7 +76,7 @@ const App = () => { const handleNewNotebookClick = () => { if (handleUnsavedChanges()) { NotebookModel.createNotebook(`${baseUrl}work`, '').then((data) => { - const notebookPath = `${baseUrl}${data.path}` + const notebookPath = `${data.path}` NotebookModel.fetchNotebook(notebookPath).then((data) => { setNotebook(data); setShowHistoryServer(false); @@ -93,7 +93,7 @@ const App = () => { const handleExistingNotebookClick = (path) => { if (handleUnsavedChanges()) { - NotebookModel.fetchNotebook(`${baseUrl}${path}`).then((data) => { + NotebookModel.fetchNotebook(`${path}`).then((data) => { console.log('Fetched notebook:', data); setNotebook(data); setShowHistoryServer(false); diff --git a/webapp/src/models/NotebookModel.js b/webapp/src/models/NotebookModel.js index 13662a3..b184d3f 100644 --- a/webapp/src/models/NotebookModel.js +++ b/webapp/src/models/NotebookModel.js @@ -114,16 +114,16 @@ class NotebookModel { }; static async fetchNotebook(path = '') { - const url = new URL(path); - url.searchParams.append('t', Date.now()); // Append current timestamp as query parameter - const response = await fetch(url, { + const response = await fetch("http://localhost:5002/notebook/" + path, { method: 'GET', - redirect: "follow", headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', } }); + if (!response.ok) { + throw new Error('Failed to fetch notebook'); + } const data = await response.json(); return data; }