Server: Fix error caused by libraries that have books with empty author fields (although this should be impossible). Fixes #1703064 [calibre-server 3.2.1 on FreeBSD: TypeError: Cannot read property 'join' of undefined](https://bugs.launchpad.net/calibre/+bug/1703064)

This commit is contained in:
Kovid Goyal 2017-07-08 09:24:56 +05:30
parent 42543e57ec
commit 21f37bde8c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 11 additions and 8 deletions

View File

@ -403,10 +403,11 @@ def render_book(container_id, book_id):
return return
metadata = book_metadata(book_id) metadata = book_metadata(book_id)
set_title(c, metadata.title) set_title(c, metadata.title)
alt = _('{} by {}').format(metadata.title, metadata.authors.join(' & ')) authors = metadata.authors.join(' & ') if metadata.authors else _('Unknown')
alt = _('{} by {}').format(metadata.title, authors)
imgdiv = E.div( imgdiv = E.div(
E.img( E.img(
alt=alt, title=alt, data_title=metadata.title, data_authors=metadata.authors.join(' & '), alt=alt, title=alt, data_title=metadata.title, data_authors=authors,
style='border-radius: 20px; max-width: calc(100vw - 2em); max-height: calc(100vh - 4ex - {}); display: block; width:auto; height:auto; border-radius: 20px'.format(get_font_size('title') style='border-radius: 20px; max-width: calc(100vw - 2em); max-height: calc(100vh - 4ex - {}); display: block; width:auto; height:auto; border-radius: 20px'.format(get_font_size('title')
)) ))
) )
@ -592,7 +593,7 @@ def search_internet(container_id):
container = document.getElementById(container_id) container = document.getElementById(container_id)
create_top_bar(container, title=_('Search the internet'), action=back, icon='close') create_top_bar(container, title=_('Search the internet'), action=back, icon='close')
mi = book_metadata(render_book.book_id) mi = book_metadata(render_book.book_id)
data = {'title':mi.title, 'author':mi.authors[0]} data = {'title':mi.title, 'author':mi.authors[0] if mi.authors else _('Unknown')}
def link_for(name, template): def link_for(name, template):
return E.a(name, class_='simple-link', href=url_for(template, data), target="_blank") return E.a(name, class_='simple-link', href=url_for(template, data), target="_blank")

View File

@ -60,7 +60,7 @@ def on_img_load(img, load_type):
set_css(div, border='dashed 1px currentColor', border_radius=BORDER_RADIUS+'px') set_css(div, border='dashed 1px currentColor', border_radius=BORDER_RADIUS+'px')
def create_item(book_id, metadata, create_image, show_book_details): def create_item(book_id, metadata, create_image, show_book_details):
authors = metadata.authors.join(' & ') authors = metadata.authors.join(' & ') if metadata.authors else _('Unknown')
img = create_image(book_id, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, on_img_load) img = create_image(book_id, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, on_img_load)
img.setAttribute('alt', _('{} by {}').format(metadata.title, authors)) img.setAttribute('alt', _('{} by {}').format(metadata.title, authors))
img.dataset.title, img.dataset.authors = metadata.title, authors img.dataset.title, img.dataset.authors = metadata.title, authors

View File

@ -63,7 +63,7 @@ def on_img_load(img, load_type):
def create_item(book_id, metadata, create_image, show_book_details): def create_item(book_id, metadata, create_image, show_book_details):
authors = metadata.authors.join(' & ') authors = metadata.authors.join(' & ') if metadata.authors else _('Unknown')
img = create_image(book_id, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, on_img_load) img = create_image(book_id, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, on_img_load)
img.setAttribute('alt', _('{} by {}').format(metadata.title, authors)) img.setAttribute('alt', _('{} by {}').format(metadata.title, authors))
img.dataset.title, img.dataset.authors = metadata.title, authors img.dataset.title, img.dataset.authors = metadata.title, authors
@ -90,7 +90,7 @@ def create_item(book_id, metadata, create_image, show_book_details):
class_='details-list-right', class_='details-list-right',
E.div(style='display:flex; justify-content: space-between; overflow: hidden', E.div(style='display:flex; justify-content: space-between; overflow: hidden',
E.div( E.div(
E.b(metadata.title or _('Unknown')), E.br(), metadata.authors.join(' & '), E.b(metadata.title or _('Unknown')), E.br(), authors,
), ),
extra_data extra_data
), ),

View File

@ -107,8 +107,9 @@ def show_recent_stage2(books):
if username and to_sync.length < 10: if username and to_sync.length < 10:
lr = book.last_read[username_key(username)] or new Date(0) # noqa: unused-local lr = book.last_read[username_key(username)] or new Date(0) # noqa: unused-local
to_sync.push(v'[book.key, lr]') to_sync.push(v'[book.key, lr]')
authors = book.metadata.authors.join(' & ') if book.metadata.authors else _('Unknown')
img = E.img( img = E.img(
alt=_('{} by {}').format(book.metadata.title, book.metadata.authors.join(' & ')) alt=_('{} by {}').format(book.metadata.title, authors)
) )
img_id = ensure_id(img) img_id = ensure_id(img)
images.appendChild(E.div(style='margin: 0 1em', images.appendChild(E.div(style='margin: 0 1em',

View File

@ -55,8 +55,9 @@ def create_image(book_idx, max_width, max_height, on_load):
on_load(this, 'load') on_load(this, 'load')
book = book_list_data.book_data[book_idx] book = book_list_data.book_data[book_idx]
if book?.metadata: if book?.metadata:
authors = book.metadata.authors.join(' & ') if book.metadata.authors else _('Unknown')
img.setAttribute('alt', _('{} by {}').format( img.setAttribute('alt', _('{} by {}').format(
book.metadata.title, book.metadata.authors.join(' & '))) book.metadata.title, authors))
if book?.cover_name: if book?.cover_name:
img_id = ensure_id(img, 'local-cover-') img_id = ensure_id(img, 'local-cover-')
get_db().get_file(book, book.cover_name, show_cover.bind(img_id)) get_db().get_file(book, book.cover_name, show_cover.bind(img_id))