This makes it easier to make the od_data module be primary over od_api.
Signed-off-by: Steven Chan <steven3416@gmail.com>
.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
)
$.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 = {}
log: log
- proxy: proxy
-
# Map format id to format name using current session object
labels: (id) -> session.labels[id] or id
$.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
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) ->
# 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
@add()
.remove()
+ .proxy_urls()
.moments()
.count()
.sort()
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: ->
super x
@add()
+ .proxy_urls()
.moments()
.sort()
@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: ->
define [
'jquery'
'lodash'
- 'od_api'
'jquery-ui'
'od_action'
'od_pages_opac'
-], ($, _, od) ->
+], ($, _) ->
$.fn.extend
<a href="/eg/opac/results?query=#{meta.title};locg=10;qtype=title">#{meta.title}</a>
"""
$thumbnail = $ """
- <img src="#{od.proxy meta.images?.thumbnail?.href}" alt="#{meta.title}" />
+ <img src="#{meta.images?.thumbnail?.href}" alt="#{meta.title}" />
"""
$author = $ """
<a href="/eg/opac/results?query=#{meta.author};locg=10;qtype=author">#{meta.author}</a>
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: ''
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