|
2 | 2 |
|
3 | 3 | from jupyter_server.base.handlers import APIHandler |
4 | 4 | from jupyter_server.utils import url_path_join |
| 5 | +from jupyter_core.utils import ensure_async |
5 | 6 | import tornado |
6 | 7 |
|
| 8 | + |
7 | 9 | class RouteHandler(APIHandler): |
8 | 10 | # The following decorator should be present on all verb methods (head, get, post, |
9 | 11 | # patch, put, delete, options) to ensure only authorized user can request the |
10 | 12 | # Jupyter server |
11 | 13 | @tornado.web.authenticated |
12 | | - def get(self): |
13 | | - self.finish(json.dumps({ |
14 | | - "data": "This is /jupyterlab-deepnote/get-example endpoint!" |
15 | | - })) |
| 14 | + async def get(self): |
| 15 | + print("🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 YOOOOO") |
| 16 | + path = self.get_query_argument("path") |
| 17 | + # Use Jupyter Server’s contents_manager, not direct filesystem access. |
| 18 | + model = await ensure_async( |
| 19 | + self.contents_manager.get(path, type="file", format="text", content=True) |
| 20 | + ) |
| 21 | + result = {"data": model, "path": path} |
| 22 | + self.finish(json.dumps(result)) |
16 | 23 |
|
17 | 24 |
|
18 | 25 | def setup_handlers(web_app): |
19 | 26 | host_pattern = ".*$" |
20 | 27 |
|
21 | 28 | base_url = web_app.settings["base_url"] |
22 | | - route_pattern = url_path_join(base_url, "jupyterlab-deepnote", "get-example") |
| 29 | + route_pattern = url_path_join(base_url, "api", "contents", "resolve") |
23 | 30 | handlers = [(route_pattern, RouteHandler)] |
24 | 31 | web_app.add_handlers(host_pattern, handlers) |
0 commit comments