From 2d2698598c4954015b8a733bb7cc82371453ec16 Mon Sep 17 00:00:00 2001 From: eric Date: Tue, 3 Sep 2019 15:11:38 -0400 Subject: [PATCH] use relative urls and stop using protocol relative urls --- BaseSearcher.py | 26 +++++--------------------- BibrecPage.py | 2 +- HTMLFormatter.py | 8 ++++++++ templates/bibrec.html | 4 ++-- templates/site-layout.html | 4 ++-- 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/BaseSearcher.py b/BaseSearcher.py index 8bc6f99..31c113d 100644 --- a/BaseSearcher.py +++ b/BaseSearcher.py @@ -464,13 +464,7 @@ class OpenSearch (object): if self.protocol not in VALID_PROTOCOLS: self.protocol = 'https' - self.urlgen = routes.URLGenerator ( - cherrypy.routes_mapper, - { - 'HTTP_HOST': self.host, - 'HTTPS': 1 , - } - ) + self.urlgen = routes.URLGenerator ( cherrypy.routes_mapper, {'HTTP_HOST': self.host}) self.set_format (k.get ('format')) @@ -617,13 +611,13 @@ class OpenSearch (object): self.mobile_search = self.url ('search', format = 'mobile') self.json_search = self.url ('suggest', format = None) - self.base_url = self.protocol_relative (self.url (host = self.host)) + self.base_url = self.url (host = self.file_host) # for google, fb etc. self.canonical_url = self.url_carry (host = self.file_host, format = None) - self.desktop_url = self.protocol_relative (self.url_carry (host = self.desktop_host, format = None)) - self.mobile_url = self.protocol_relative (self.url_carry (host = self.mobile_host, format = 'mobile')) + self.desktop_url = self.url_carry (host = self.desktop_host, format = None) + self.mobile_url = self.url_carry (host = self.mobile_host, format = 'mobile') self.osd_url = self.qualify ('/catalog/osd-books.xml') @@ -696,14 +690,6 @@ class OpenSearch (object): return urllib.parse.urljoin (self.base_url, url) - def protocol_relative (self, url): - """ Make absolute url protocol relative. """ - offset = url.find ('//') - if offset > -1: - return url[offset:] - return url - - def set_format (self, format_): """ Sanity check and set the parameter we got from the user. Calc format and mediatype to send to the client. """ @@ -939,9 +925,7 @@ class OpenSearch (object): def format_thumb_url (self, row): """ Generate the thumb url in results. """ if row.coverpages: - return urllib.parse.urljoin ('//' + self.file_host, row.coverpages[0]) - # return self.url ('bibrec', host = self.file_host, id = row.pk, - # format = 'cover.small') + return row.coverpages[0] return None def format_icon (self, dummy_row): diff --git a/BibrecPage.py b/BibrecPage.py index 1ed1a47..bbfc3c4 100644 --- a/BibrecPage.py +++ b/BibrecPage.py @@ -57,7 +57,7 @@ class BibrecPage (Page.Page): dc.icon = 'audiobook' os.title_icon = dc.icon os.twit = os.title - os.qrcode_url = '//%s/cache/epub/%d/pg%d.qrcode.png' % (os.file_host, os.id, os.id) + os.qrcode_url = '/cache/epub/%d/pg%d.qrcode.png' % (os.id, os.id) os.entries.append (dc) diff --git a/HTMLFormatter.py b/HTMLFormatter.py index 81bacef..7b4e240 100644 --- a/HTMLFormatter.py +++ b/HTMLFormatter.py @@ -58,6 +58,7 @@ class XMLishFormatter (BaseFormatter.BaseFormatter): super (XMLishFormatter, self).fix_dc (dc, os) + # generated_files always [] AFAICT -esh for file_ in dc.generated_files: file_.help_topic = file_.hr_filetype file_.compression = 'none' @@ -78,6 +79,13 @@ class XMLishFormatter (BaseFormatter.BaseFormatter): file_.url = file_.url + '?' + urllib.parse.urlencode ( { 'session_id': str (cherrypy.session.id) } ) + # these are used as relative links + if file_.generated and not file_.filetype.startswith ('cover.'): + file_.filename = "ebooks/%d.%s" % (file_.id, file_.filetype) + if m in HANDOVER_TYPES: + file_.filename = file_.filename + '?' + urllib.parse.urlencode ( + { 'session_id': str (cherrypy.session.id) } ) + for file_ in dc.files: file_.honeypot_url = os.url ( 'honeypot_send', id = dc.project_gutenberg_id, filetype = file_.filetype) diff --git a/templates/bibrec.html b/templates/bibrec.html index 8b2a4b9..7f167f2 100644 --- a/templates/bibrec.html +++ b/templates/bibrec.html @@ -320,7 +320,7 @@ Gutenberg metadata much faster than by scraping. ${file_.hr_filetype} ${file_.url} @@ -352,7 +352,7 @@ Gutenberg metadata much faster than by scraping. More Files… - https:${os.qualify (e.base_dir)} + e.base_dir diff --git a/templates/site-layout.html b/templates/site-layout.html index 4f155be..bedb5e8 100644 --- a/templates/site-layout.html +++ b/templates/site-layout.html @@ -118,7 +118,7 @@
@@ -244,7 +244,7 @@