mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-04-28 18:53:06 +02:00
Add UUID as a possible id type to content server ajax/book
This commit is contained in:
parent
810aa02b74
commit
653df51062
2 changed files with 15 additions and 4 deletions
|
|
@ -2564,6 +2564,11 @@ def set_uuid(self, id, uuid, notify=True, commit=True):
|
|||
if notify:
|
||||
self.notify('metadata', [id])
|
||||
|
||||
def get_id_from_uuid(self, uuid):
|
||||
if uuid:
|
||||
return self.conn.get('SELECT id FROM books WHERE uuid=?', (uuid,),
|
||||
all=False)
|
||||
|
||||
# Convenience methods for tags_list_editor
|
||||
# Note: we generally do not need to refresh_ids because library_view will
|
||||
# refresh everything.
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ def ajax_book_to_json(self, book_id, get_category_urls=True):
|
|||
return data, mi.last_modified
|
||||
|
||||
@Endpoint(set_last_modified=False)
|
||||
def ajax_book(self, book_id, category_urls='true'):
|
||||
def ajax_book(self, book_id, category_urls='true', id_is_uuid='false'):
|
||||
'''
|
||||
Return the metadata of the book as a JSON dictionary.
|
||||
|
||||
|
|
@ -192,7 +192,10 @@ def ajax_book(self, book_id, category_urls='true'):
|
|||
cherrypy.response.timeout = 3600
|
||||
|
||||
try:
|
||||
book_id = int(book_id)
|
||||
if id_is_uuid == 'true':
|
||||
book_id = self.db.get_id_from_uuid(book_id)
|
||||
else:
|
||||
book_id = int(book_id)
|
||||
data, last_modified = self.ajax_book_to_json(book_id,
|
||||
get_category_urls=category_urls.lower()=='true')
|
||||
except:
|
||||
|
|
@ -204,7 +207,7 @@ def ajax_book(self, book_id, category_urls='true'):
|
|||
return data
|
||||
|
||||
@Endpoint(set_last_modified=False)
|
||||
def ajax_books(self, ids=None, category_urls='true'):
|
||||
def ajax_books(self, ids=None, category_urls='true', id_is_uuid='false'):
|
||||
'''
|
||||
Return the metadata for a list of books specified as a comma separated
|
||||
list of ids. The metadata is returned as a dictionary mapping ids to
|
||||
|
|
@ -218,7 +221,10 @@ def ajax_books(self, ids=None, category_urls='true'):
|
|||
if ids is None:
|
||||
raise cherrypy.HTTPError(404, 'Must specify some ids')
|
||||
try:
|
||||
ids = set(int(x.strip()) for x in ids.split(','))
|
||||
if id_is_uuid == 'true':
|
||||
ids = set(self.db.get_id_from_uuid(x) for x in ids.split(','))
|
||||
else:
|
||||
ids = set(int(x.strip()) for x in ids.split(','))
|
||||
except:
|
||||
raise cherrypy.HTTPError(404, 'ids must be a comma separated list'
|
||||
' of integers')
|
||||
|
|
|
|||
Loading…
Reference in a new issue