mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
/opds: Support for --url-prefix
This commit is contained in:
parent
5efad88b63
commit
a348655fbd
@ -60,14 +60,15 @@ class DispatchController(object): # {{{
|
|||||||
|
|
||||||
class BonJour(SimplePlugin): # {{{
|
class BonJour(SimplePlugin): # {{{
|
||||||
|
|
||||||
def __init__(self, engine, port=8080):
|
def __init__(self, engine, port=8080, prefix=''):
|
||||||
SimplePlugin.__init__(self, engine)
|
SimplePlugin.__init__(self, engine)
|
||||||
self.port = port
|
self.port = port
|
||||||
|
self.prefix = prefix
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
try:
|
try:
|
||||||
publish_zeroconf('Books in calibre', '_stanza._tcp',
|
publish_zeroconf('Books in calibre', '_stanza._tcp',
|
||||||
self.port, {'path':'/stanza'})
|
self.port, {'path':self.prefix+'/stanza'})
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
cherrypy.log.error('Failed to start BonJour:')
|
cherrypy.log.error('Failed to start BonJour:')
|
||||||
@ -106,6 +107,7 @@ class LibraryServer(ContentServer, MobileServer, XMLServer, OPDSServer, Cache,
|
|||||||
self.default_cover = open(P('content_server/default_cover.jpg'), 'rb').read()
|
self.default_cover = open(P('content_server/default_cover.jpg'), 'rb').read()
|
||||||
|
|
||||||
cherrypy.engine.bonjour.port = opts.port
|
cherrypy.engine.bonjour.port = opts.port
|
||||||
|
cherrypy.engine.bonjour.prefix = opts.url_prefix
|
||||||
|
|
||||||
Cache.__init__(self)
|
Cache.__init__(self)
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ def CATALOG_GROUP_ENTRY(item, category, base_href, version, updated):
|
|||||||
link
|
link
|
||||||
)
|
)
|
||||||
|
|
||||||
def ACQUISITION_ENTRY(item, version, db, updated, CFM, CKEYS):
|
def ACQUISITION_ENTRY(item, version, db, updated, CFM, CKEYS, prefix):
|
||||||
FM = db.FIELD_MAP
|
FM = db.FIELD_MAP
|
||||||
title = item[FM['title']]
|
title = item[FM['title']]
|
||||||
if not title:
|
if not title:
|
||||||
@ -185,16 +185,16 @@ def ACQUISITION_ENTRY(item, version, db, updated, CFM, CKEYS):
|
|||||||
for fmt in formats.split(','):
|
for fmt in formats.split(','):
|
||||||
fmt = fmt.lower()
|
fmt = fmt.lower()
|
||||||
mt = guess_type('a.'+fmt)[0]
|
mt = guess_type('a.'+fmt)[0]
|
||||||
href = '/get/%s/%s'%(fmt, item[FM['id']])
|
href = prefix + '/get/%s/%s'%(fmt, item[FM['id']])
|
||||||
if mt:
|
if mt:
|
||||||
link = E.link(type=mt, href=href)
|
link = E.link(type=mt, href=href)
|
||||||
if version > 0:
|
if version > 0:
|
||||||
link.set('rel', "http://opds-spec.org/acquisition")
|
link.set('rel', "http://opds-spec.org/acquisition")
|
||||||
ans.append(link)
|
ans.append(link)
|
||||||
ans.append(E.link(type='image/jpeg', href='/get/cover/%s'%item[FM['id']],
|
ans.append(E.link(type='image/jpeg', href=prefix+'/get/cover/%s'%item[FM['id']],
|
||||||
rel="x-stanza-cover-image" if version == 0 else
|
rel="x-stanza-cover-image" if version == 0 else
|
||||||
"http://opds-spec.org/cover"))
|
"http://opds-spec.org/cover"))
|
||||||
ans.append(E.link(type='image/jpeg', href='/get/thumb/%s'%item[FM['id']],
|
ans.append(E.link(type='image/jpeg', href=prefix+'/get/thumb/%s'%item[FM['id']],
|
||||||
rel="x-stanza-cover-image-thumbnail" if version == 0 else
|
rel="x-stanza-cover-image-thumbnail" if version == 0 else
|
||||||
"http://opds-spec.org/thumbnail"))
|
"http://opds-spec.org/thumbnail"))
|
||||||
|
|
||||||
@ -275,7 +275,7 @@ class NavFeed(Feed):
|
|||||||
class AcquisitionFeed(NavFeed):
|
class AcquisitionFeed(NavFeed):
|
||||||
|
|
||||||
def __init__(self, updated, id_, items, offsets, page_url, up_url, version,
|
def __init__(self, updated, id_, items, offsets, page_url, up_url, version,
|
||||||
db):
|
db, prefix):
|
||||||
NavFeed.__init__(self, id_, updated, version, offsets, page_url, up_url)
|
NavFeed.__init__(self, id_, updated, version, offsets, page_url, up_url)
|
||||||
CFM = db.field_metadata
|
CFM = db.field_metadata
|
||||||
CKEYS = [key for key in sorted(custom_fields_to_display(db),
|
CKEYS = [key for key in sorted(custom_fields_to_display(db),
|
||||||
@ -283,7 +283,7 @@ class AcquisitionFeed(NavFeed):
|
|||||||
CFM[y]['name'].lower()))]
|
CFM[y]['name'].lower()))]
|
||||||
for item in items:
|
for item in items:
|
||||||
self.root.append(ACQUISITION_ENTRY(item, version, db, updated,
|
self.root.append(ACQUISITION_ENTRY(item, version, db, updated,
|
||||||
CFM, CKEYS))
|
CFM, CKEYS, prefix))
|
||||||
|
|
||||||
class CategoryFeed(NavFeed):
|
class CategoryFeed(NavFeed):
|
||||||
|
|
||||||
@ -360,7 +360,8 @@ class OPDSServer(object):
|
|||||||
cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
|
cherrypy.response.headers['Last-Modified'] = self.last_modified(updated)
|
||||||
cherrypy.response.headers['Content-Type'] = 'application/atom+xml;profile=opds-catalog'
|
cherrypy.response.headers['Content-Type'] = 'application/atom+xml;profile=opds-catalog'
|
||||||
return str(AcquisitionFeed(updated, id_, items, offsets,
|
return str(AcquisitionFeed(updated, id_, items, offsets,
|
||||||
page_url, up_url, version, self.db))
|
page_url, up_url, version, self.db,
|
||||||
|
self.opts.url_prefix))
|
||||||
|
|
||||||
def opds_search(self, query=None, version=0, offset=0):
|
def opds_search(self, query=None, version=0, offset=0):
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user