Skip to content

Commit f294530

Browse files
committed
Add API to create new FileIDs from the client
1 parent f584002 commit f294530

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

jupyter_rtc_core/app.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44

55
from traitlets import Instance, Type
6-
from .handlers import RouteHandler, YRoomSessionHandler
6+
from .handlers import RouteHandler, YRoomSessionHandler, FileIDIndexHandler
77
from .websockets import GlobalAwarenessWebsocket, YRoomWebsocket
88
from .rooms.yroom_manager import YRoomManager
99

@@ -21,9 +21,10 @@ class RtcExtensionApp(ExtensionApp):
2121
# # ydoc websocket
2222
(r"api/collaboration/room/(.*)", YRoomWebsocket),
2323
# handler that just adds compatibility with Jupyter Collaboration's frontend
24-
(r"api/collaboration/session/(.*)", YRoomSessionHandler)
24+
(r"api/collaboration/session/(.*)", YRoomSessionHandler),
25+
(r"api/fileid/index", FileIDIndexHandler)
2526
]
26-
27+
2728
yroom_manager_class = Type(
2829
klass=YRoomManager,
2930
help="""YRoom Manager Class.""",

jupyter_rtc_core/handlers.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,35 @@
44
from jupyter_server.base.handlers import APIHandler
55
import tornado
66

7+
from jupyter_server.auth.decorator import authorized
8+
from jupyter_server.base.handlers import APIHandler
9+
from tornado import web
10+
from tornado.escape import json_encode
11+
12+
from jupyter_server_fileid.manager import BaseFileIdManager
13+
14+
# TODO: This handler belongs in Jupyter Server FileID.
15+
# Putting it here for now so we don't have to wait for upstream releases.
16+
class FileIDIndexHandler(APIHandler):
17+
auth_resource = "contents"
18+
19+
@property
20+
def file_id_manager(self) -> BaseFileIdManager:
21+
return self.settings.get("file_id_manager")
22+
23+
@web.authenticated
24+
@authorized
25+
def post(self):
26+
try:
27+
path = self.get_argument("path")
28+
id = self.file_id_manager.index(path)
29+
self.write(json_encode({"id": id, "path": path}))
30+
except web.MissingArgumentError:
31+
raise web.HTTPError(
32+
400, log_message="'path' parameter was not provided in the request."
33+
)
34+
35+
736
class RouteHandler(APIHandler):
837
# The following decorator should be present on all verb methods (head, get, post,
938
# patch, put, delete, options) to ensure only authorized user can request the

0 commit comments

Comments
 (0)