mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-24 12:05:22 +08:00
fix clientside notebook manager and assume tree is dir by default
Assume tree url are dir by default instead of file, and if not do a redirect. Usefull for Clientside manager where the server does not know the content of the drive, and think that everythong exists.
This commit is contained in:
parent
e1f4a76ea1
commit
1b1d1f2325
@ -36,21 +36,8 @@ class TreeHandler(IPythonHandler):
|
||||
def get(self, path=''):
|
||||
path = path.strip('/')
|
||||
cm = self.contents_manager
|
||||
if cm.file_exists(path):
|
||||
# it's not a directory, we have redirecting to do
|
||||
model = cm.get(path, content=False)
|
||||
# redirect to /api/notebooks if it's a notebook, otherwise /api/files
|
||||
service = 'notebooks' if model['type'] == 'notebook' else 'files'
|
||||
url = url_escape(url_path_join(
|
||||
self.base_url, service, path,
|
||||
))
|
||||
self.log.debug("Redirecting %s to %s", self.request.path, url)
|
||||
self.redirect(url)
|
||||
else:
|
||||
if not cm.dir_exists(path=path):
|
||||
# Directory is hidden or does not exist.
|
||||
raise web.HTTPError(404)
|
||||
elif cm.is_hidden(path):
|
||||
if cm.dir_exists(path=path):
|
||||
if cm.is_hidden(path):
|
||||
self.log.info("Refusing to serve hidden directory, via 404 Error")
|
||||
raise web.HTTPError(404)
|
||||
breadcrumbs = self.generate_breadcrumbs(path)
|
||||
@ -61,6 +48,18 @@ class TreeHandler(IPythonHandler):
|
||||
breadcrumbs=breadcrumbs,
|
||||
terminals_available=self.settings['terminals_available'],
|
||||
))
|
||||
elif cm.file_exists(path):
|
||||
# it's not a directory, we have redirecting to do
|
||||
model = cm.get(path, content=False)
|
||||
# redirect to /api/notebooks if it's a notebook, otherwise /api/files
|
||||
service = 'notebooks' if model['type'] == 'notebook' else 'files'
|
||||
url = url_escape(url_path_join(
|
||||
self.base_url, service, path,
|
||||
))
|
||||
self.log.debug("Redirecting %s to %s", self.request.path, url)
|
||||
self.redirect(url)
|
||||
else:
|
||||
raise web.HTTPError(404)
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user