From 9da22f10c57cbb4f691a431bd9a8469ebadf8278 Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 5 Jun 2019 11:51:56 -0400 Subject: [PATCH 1/2] fix pdf pattern --- CloudStorage.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/CloudStorage.py b/CloudStorage.py index 375b48e..3033dde 100644 --- a/CloudStorage.py +++ b/CloudStorage.py @@ -301,6 +301,11 @@ class EbookMetaData (object): # test filename return urllib.parse.urljoin ( protocol + str(cherrypy.config['file_host']) , 'test.pdf') - return urllib.parse.urljoin ( - protocol + cherrypy.config['file_host'], - 'ebooks/%d.%s' % (self.id, self.filetype)) + if self.filetype == 'pdf': + return urllib.parse.urljoin ( + protocol + cherrypy.config['file_host'], + 'files/%d/%d-pdf.pdf' % (self.id, self.id)) + else: + return urllib.parse.urljoin ( + protocol + cherrypy.config['file_host'], + 'ebooks/%d.%s' % (self.id, self.filetype)) From 50cc46edfb751c5b6d42b3a3fe6bfa5fb9af161a Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 5 Jun 2019 11:52:47 -0400 Subject: [PATCH 2/2] don't offer cloudstorage for nonstd pdf --- HTMLFormatter.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/HTMLFormatter.py b/HTMLFormatter.py index 53889cb..cbb8ab4 100644 --- a/HTMLFormatter.py +++ b/HTMLFormatter.py @@ -18,6 +18,7 @@ import operator import cherrypy import genshi.output +import re import six from six.moves import urllib @@ -37,6 +38,7 @@ HANDOVER_TYPES = (mt.epub, mt.plucker, mt.mobi, mt.pdf, mt.qioo) # self-contained files we can send to dropbox CLOUD_TYPES = (mt.epub, mt.mobi, mt.pdf) +STD_PDF_MATCH = re.compile (r'files/\d+/\d+-pdf.pdf$') class XMLishFormatter (BaseFormatter.BaseFormatter): """ Produce XMLish output. """ @@ -47,6 +49,10 @@ class XMLishFormatter (BaseFormatter.BaseFormatter): def fix_dc (self, dc, os): """ Tweak dc. """ + def has_std_path (file_obj): + if file_obj.filetype == 'pdf': + return STD_PDF_MATCH.search (file_obj.url) + return True super (XMLishFormatter, self).fix_dc (dc, os) @@ -58,7 +64,7 @@ class XMLishFormatter (BaseFormatter.BaseFormatter): for file_ in dc.files + dc.generated_files: type_ = six.text_type (file_.mediatypes[0]) m = type_.partition (';')[0] - if m in CLOUD_TYPES: + if m in CLOUD_TYPES and has_std_path (file_): file_.dropbox_url = os.url ( 'dropbox_send', id = dc.project_gutenberg_id, filetype = file_.filetype) file_.gdrive_url = os.url (