-
Notifications
You must be signed in to change notification settings - Fork 6
Add API to create new FileIDs from the client #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep!