Skip to content

Commit

Permalink
move mount-drive handler to /drives endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisaCG committed Dec 4, 2023
1 parent 028f378 commit de5c314
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions jupyter_drives/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,21 @@ def initialize(self, logger: logging.Logger, manager: JupyterDrivesManager):
async def get(self):
drives = await self._manager.list_drives()
self.finish(json.dumps(drives))

class MountJupyterDriveHandler(JupyterDrivesAPIHandler):
"""
Mounts a drive. Makes content accessible to user.
"""
def initialize(self, logger: logging.Logger, manager: JupyterDrivesManager):
return super().initialize(logger, manager)

@tornado.web.authenticated
async def post(self):
body = self.get_json_body()
drive_name = body["drive_name"]
mount_drive = body["mount_drive"]
local_path = self.url2localpath(path)

if mount_drive:
result = await self._manager.mount_drive(drive_name, local_path)
result = await self._manager.mount_drive(**body)

else:
result = await self._manager.unmount_drive(drive_name, local_path)
self.finish(json.dump(result))
result = await self._manager.unmount_drive(**body)
self.finish(json.dump(result))

default_handlers = [
("drives", ListJupyterDrivesHandler),
("mount-drive", MountJupyterDriveHandler)
("drives", ListJupyterDrivesHandler)
]

def setup_handlers(web_app: tornado.web.Application, config: traitlets.config.Config, log: Optional[logging.Logger] = None):
Expand Down

0 comments on commit de5c314

Please sign in to comment.