|
|
|
|
@ -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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|