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): class FileHandler(OMLHandler):
def initialize(self, attachment=False):
self._attachment = attachment
def head(self, id): def head(self, id):
self.get(id, include_body=False) self.get(id, include_body=False)
@ -70,7 +73,11 @@ class FileHandler(OMLHandler):
'pdf': 'application/pdf', 'pdf': 'application/pdf',
'txt': 'text/plain', 'txt': 'text/plain',
}.get(path.split('.')[-1], None) }.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): class ReaderHandler(OMLHandler):

View file

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