url to download book with ok name

This commit is contained in:
j 2014-12-13 21:01:54 +01:00
parent bc065c7fda
commit 23aaf37740
2 changed files with 11 additions and 1 deletions

View File

@ -55,6 +55,9 @@ def serve_static(handler, path, mimetype, include_body=True, disposition=None):
class FileHandler(OMLHandler):
def initialize(self, attachment=False):
self._attachment = attachment
def head(self, id):
self.get(id, include_body=False)
@ -70,7 +73,11 @@ class FileHandler(OMLHandler):
'pdf': 'application/pdf',
'txt': 'text/plain',
}.get(path.split('.')[-1], None)
return serve_static(self, path, mimetype, include_body)
if self._attachment:
disposition = os.path.basename(path)
else:
disposition = None
return serve_static(self, path, mimetype, include_body, disposition=disposition)
class ReaderHandler(OMLHandler):

View File

@ -65,6 +65,9 @@ def run():
(r'/(.*?)/reader/', ReaderHandler),
(r'/(.*?)/pdf/', FileHandler),
(r'/(.*?)/txt/', FileHandler),
(r'/(.*?)/get/', FileHandler, {
'download': True
}),
(r'/(.*)/(cover|preview)(\d*).jpg', IconHandler),
(r'/api/', oxtornado.ApiHandler, dict(context=db.session)),
(r'/ws', websocket.Handler),