Skip to content
Closed
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
7 changes: 4 additions & 3 deletions jupyter_rtc_core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio

from traitlets import Instance, Type
from .handlers import RouteHandler, YRoomSessionHandler
from .handlers import RouteHandler, YRoomSessionHandler, FileIDIndexHandler
from .websockets import GlobalAwarenessWebsocket, YRoomWebsocket
from .rooms.yroom_manager import YRoomManager

Expand All @@ -21,9 +21,10 @@ class RtcExtensionApp(ExtensionApp):
# # ydoc websocket
(r"api/collaboration/room/(.*)", YRoomWebsocket),
# handler that just adds compatibility with Jupyter Collaboration's frontend
(r"api/collaboration/session/(.*)", YRoomSessionHandler)
(r"api/collaboration/session/(.*)", YRoomSessionHandler),
(r"api/fileid/index", FileIDIndexHandler)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this API be used by UI code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep!

]

yroom_manager_class = Type(
klass=YRoomManager,
help="""YRoom Manager Class.""",
Expand Down
29 changes: 29 additions & 0 deletions jupyter_rtc_core/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,35 @@
from jupyter_server.base.handlers import APIHandler
import tornado

from jupyter_server.auth.decorator import authorized
from jupyter_server.base.handlers import APIHandler
from tornado import web
from tornado.escape import json_encode

from jupyter_server_fileid.manager import BaseFileIdManager

# TODO: This handler belongs in Jupyter Server FileID.
# Putting it here for now so we don't have to wait for upstream releases.
class FileIDIndexHandler(APIHandler):
auth_resource = "contents"

@property
def file_id_manager(self) -> BaseFileIdManager:
return self.settings.get("file_id_manager")

@web.authenticated
@authorized
def post(self):
try:
path = self.get_argument("path")
Comment on lines +24 to +27
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, I did not follow full conversation. why is this a post request? is it because if file Id did not exist, it will be created?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's right.

id = self.file_id_manager.index(path)
self.write(json_encode({"id": id, "path": path}))
except web.MissingArgumentError:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other exceptions that file_id_manager.index can raise that we need to catch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no other specific errors that the file_id_manager raises.

sqlite3 could, in principle, raise an exception, but I don't think we should do anything special to handle that case—just let it raise a 500 and display the error to the user?

raise web.HTTPError(
400, log_message="'path' parameter was not provided in the request."
)


class RouteHandler(APIHandler):
# The following decorator should be present on all verb methods (head, get, post,
# patch, put, delete, options) to ensure only authorized user can request the
Expand Down
Loading