diff --git a/src/pyflask/app.py b/src/pyflask/app.py index 3301c21a8..4c3bf1d14 100644 --- a/src/pyflask/app.py +++ b/src/pyflask/app.py @@ -32,6 +32,7 @@ data_namespace, neuroconv_namespace, neurosift_namespace, + nwb_inspector_namespace, startup_namespace, system_namespace, ) @@ -65,6 +66,7 @@ api.add_namespace(data_namespace) api.add_namespace(system_namespace) api.add_namespace(dandi_namespace) +api.add_namespace(nwb_inspector_namespace) # api.add_namespace(neurosift_namespace) # TODO: enable later api.init_app(flask_app) diff --git a/src/pyflask/namespaces/__init__.py b/src/pyflask/namespaces/__init__.py index 0f1edb274..fdaa73060 100644 --- a/src/pyflask/namespaces/__init__.py +++ b/src/pyflask/namespaces/__init__.py @@ -2,5 +2,6 @@ from .data import data_namespace from .neuroconv import neuroconv_namespace from .neurosift import neurosift_namespace +from .nwb_inspector import nwb_inspector_namespace from .startup import startup_namespace from .system import system_namespace diff --git a/src/pyflask/namespaces/neuroconv.py b/src/pyflask/namespaces/neuroconv.py index fc3fba981..960042f8b 100644 --- a/src/pyflask/namespaces/neuroconv.py +++ b/src/pyflask/namespaces/neuroconv.py @@ -180,7 +180,7 @@ def post(self): @neuroconv_namespace.route("/announce/progress") -class InspectNWBFolder(Resource): +class AnnounceProgress(Resource): @neuroconv_namespace.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"}) def post(self): data = neuroconv_namespace.payload diff --git a/src/pyflask/namespaces/nwb_inspector.py b/src/pyflask/namespaces/nwb_inspector.py new file mode 100644 index 000000000..a1c5832e7 --- /dev/null +++ b/src/pyflask/namespaces/nwb_inspector.py @@ -0,0 +1,47 @@ +"""An API for handling general system information.""" + +import os +from typing import Dict, Union + +import flask_restx + +nwb_inspector_namespace = flask_restx.Namespace( + name="nwb_inspector", description="Handles interactions with the NWB " "Inspector." +) + + +# TODO: reroute all frontend calls to the new namespace + + +@nwb_inspector_namespace.route("/inspect") +class InspectRouter(Resource): + @nwb_inspector_namespace.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"}) + def post(self): + progress_url = f"{request.url_root}neuroconv/announce/progress" + + paths = nwb_inspector_namespace.payload["paths"] + kwargs = {**nwb_inspector_namespace.payload} + del kwargs["paths"] + + if len(paths) == 1: + if os.path.isfile(paths[0]): + return inspect_nwb_file({"nwbfile_path": paths[0], **kwargs}) + else: + return inspect_nwb_folder(url, {"path": paths[0], **kwargs}) + else: + return inspect_multiple_filesystem_objects(progress_url, paths, **kwargs) + + +@nwb_inspector_namespace.route("/inspect_file") +class InspectNWBFile(Resource): + @nwb_inspector_namespace.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"}) + def post(self): + return inspect_nwb_file(neuroconv_namespace.payload) + + +@nwb_inspector_namespace.route("/inspect_folder") +class InspectNWBFolder(Resource): + @nwb_inspector_namespace.doc(responses={200: "Success", 400: "Bad Request", 500: "Internal server error"}) + def post(self): + url = f"{request.url_root}neuroconv/announce/progress" + return inspect_nwb_folder(url, neuroconv_namespace.payload)