From 508513a15aec3ddc2200428ad651225d40cb6293 Mon Sep 17 00:00:00 2001 From: Steven Chan Date: Tue, 2 Sep 2014 15:16:37 -0700 Subject: [PATCH] Proxy URLs soon rather than late This makes it easier to make the od_data module be primary over od_api. Signed-off-by: Steven Chan --- src/od_action.coffee | 2 +- src/od_api.coffee | 29 ++--------------------------- src/od_data.coffee | 32 ++++++++++++++++++++++++++++++++ src/od_pages_myopac.coffee | 5 ++--- src/od_session.coffee | 29 ++++++++++++++++++++++++----- 5 files changed, 61 insertions(+), 36 deletions(-) diff --git a/src/od_action.coffee b/src/od_action.coffee index 5f09245..89620fa 100644 --- a/src/od_action.coffee +++ b/src/od_action.coffee @@ -461,7 +461,7 @@ define [ .then( (x) -> window.open( - od.proxy x.links.contentlink.href # url + x.links.contentlink.href # url '_blank' #'Overdrive Read format' # title 'resizable, scrollbars, status, menubar, toolbar, personalbar' # features ) diff --git a/src/od_api.coffee b/src/od_api.coffee index 9e09cd9..d12c4ec 100644 --- a/src/od_api.coffee +++ b/src/od_api.coffee @@ -69,32 +69,12 @@ define [ $.ajax $.extend {}, # The Basic Authorization string is always added to the HTTP header. headers: Authorization: "Basic #{config.credentials}" - # The URL endpoint is converted to its reverse proxy version, - # because we are using the Evergreen server as a reverse proxy to - # the Overdrive server. - url: proxy url + url: url type: 'POST' # We expect data to be always given; the ajax method will convert # it to a query string. data: data - # Replace the host domain of a given URL with a proxy domain. If the input - # URL specifies a protocol, it is stripped out so that the output will - # default to the client's protocol. - proxy = (x) -> - return unless x - y = x - y = y.replace 'https://', '//' - y = y.replace 'http://' , '//' - y = y.replace '//oauth-patron.overdrive.com', '/od/oauth-patron' - y = y.replace '//oauth.overdrive.com', '/od/oauth' - y = y.replace '//patron.api.overdrive.com', '/od/api-patron' - y = y.replace '//api.overdrive.com', '/od/api' - y = y.replace '//images.contentreserve.com', '/od/images' - y = y.replace '//fulfill.contentreserve.com', '/od/fulfill' - #log "proxy #{x} -> #{y}" - y - # Convert a serialized array into a serialized object serializeObject = (a) -> o = {} @@ -144,8 +124,6 @@ define [ log: log - proxy: proxy - # Map format id to format name using current session object labels: (id) -> session.labels[id] or id @@ -168,10 +146,7 @@ define [ $.ajax $.extend {}, # The current Authorization string is always added to the HTTP header. headers: Authorization: "#{session.token.token_type} #{session.token.access_token}" - # The URL endpoint is converted to its reverse proxy version, because - # we are using the Evergreen server as a reverse proxy to the Overdrive - # server. - url: proxy url + url: url # Will default to 'get' if no method string is supplied type: method # A given data object is expected to be in JSON format diff --git a/src/od_data.coffee b/src/od_data.coffee index d4221f5..9b0a871 100644 --- a/src/od_data.coffee +++ b/src/od_data.coffee @@ -27,6 +27,26 @@ define [ if date then M().add date, unit else M() else M() + # The URL endpoint is converted to its reverse proxy version, + # because we are using the Evergreen server as a reverse proxy to + # the Overdrive server. + proxy: (x) -> + return unless x + y = x + y = y.replace 'https://', '//' + y = y.replace 'http://' , '//' + y = y.replace '//oauth-patron.overdrive.com', '/od/oauth-patron' + y = y.replace '//oauth.overdrive.com', '/od/oauth' + y = y.replace '//patron.api.overdrive.com', '/od/api-patron' + y = y.replace '//api.overdrive.com', '/od/api' + y = y.replace '//images.contentreserve.com', '/od/images' + y = y.replace '//fulfill.contentreserve.com', '/od/fulfill' + #log "proxy #{x} -> #{y}" + y + proxies: (x) -> + (v.href = @proxy l) for n, v of x when l = v.href + return x + class Metadata extends U constructor: (x) -> @@ -37,6 +57,8 @@ define [ # Provide a simplified notion of author: first name in creators # list having a role of author @author = (v.name for v in @creators when v.role is 'Author')[0] or '' + # Convert image links to use reverse proxy + @proxies @images return @@ -73,6 +95,7 @@ define [ @add() .remove() + .proxy_urls() .moments() .count() .sort() @@ -90,6 +113,10 @@ define [ delete x.actions.releaseSuspension for x in @holds when not x.holdSuspension return @ + proxy_urls: -> + (@proxies v.actions) for v, n in @holds + return @ + # For each hold, convert any ISO 8601 date strings into a # Moment object (at local time zone) moments: -> @@ -121,6 +148,7 @@ define [ super x @add() + .proxy_urls() .moments() .sort() @@ -131,6 +159,10 @@ define [ @checkouts = [] if @checkouts is undefined return @ + proxy_urls:-> + (@proxies v.actions) for v, n in @checkouts + return @ + # For each checkout, convert any ISO 8601 date strings into a # Moment object (at local time zone) moments: -> diff --git a/src/od_pages_myopac.coffee b/src/od_pages_myopac.coffee index 2cb59ae..9902911 100644 --- a/src/od_pages_myopac.coffee +++ b/src/od_pages_myopac.coffee @@ -4,11 +4,10 @@ define [ 'jquery' 'lodash' - 'od_api' 'jquery-ui' 'od_action' 'od_pages_opac' -], ($, _, od) -> +], ($, _) -> $.fn.extend @@ -289,7 +288,7 @@ define [ #{meta.title} """ $thumbnail = $ """ - #{meta.title} + #{meta.title} """ $author = $ """ #{meta.author} diff --git a/src/od_session.coffee b/src/od_session.coffee index 1334bd3..3812fbc 100644 --- a/src/od_session.coffee +++ b/src/od_session.coffee @@ -28,6 +28,26 @@ define [ catch undefined + # The URL endpoint is converted to its reverse proxy version, + # because we are using the Evergreen server as a reverse proxy to + # the Overdrive server. + proxy: (x) -> + return unless x + y = x + y = y.replace 'https://', '//' + y = y.replace 'http://' , '//' + y = y.replace '//oauth-patron.overdrive.com', '/od/oauth-patron' + y = y.replace '//oauth.overdrive.com', '/od/oauth' + y = y.replace '//patron.api.overdrive.com', '/od/api-patron' + y = y.replace '//api.overdrive.com', '/od/api' + y = y.replace '//images.contentreserve.com', '/od/images' + y = y.replace '//fulfill.contentreserve.com', '/od/fulfill' + #log "proxy #{x} -> #{y}" + y + proxies: (x) -> + (v.href = @proxy l) for n, v of x when l = v.href + return x + class Prefs extends U @default: barcode: '' @@ -83,16 +103,15 @@ define [ advantageAccounts: '' search: '' availability: '' + constructor: (x, logged_in) -> @update x @calibrate logged_in if x return update: (x) -> - if x is undefined - super Links.default - else - super x.links if x.links - super x.linkTemplates if x.linkTemplates + super @proxies Links.default unless x? + super @proxies x.links if x?.links + super @proxies x.linkTemplates if x?.linkTemplates return # Link templates should have empty values unless the current session is -- 2.11.0