mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Re-render the book on the server when reloading
This commit is contained in:
parent
cc6101a62f
commit
ed1d51bf6b
@ -117,6 +117,7 @@ def job_done(job):
|
|||||||
@endpoint('/book-manifest/{book_id}/{fmt}', postprocess=json, types={'book_id':int})
|
@endpoint('/book-manifest/{book_id}/{fmt}', postprocess=json, types={'book_id':int})
|
||||||
def book_manifest(ctx, rd, book_id, fmt):
|
def book_manifest(ctx, rd, book_id, fmt):
|
||||||
db, library_id = get_library_data(ctx, rd)[:2]
|
db, library_id = get_library_data(ctx, rd)[:2]
|
||||||
|
force_reload = rd.query.get('force_reload') == '1'
|
||||||
if plugin_for_input_format(fmt) is None:
|
if plugin_for_input_format(fmt) is None:
|
||||||
raise HTTPNotFound('The format %s cannot be viewed' % fmt.upper())
|
raise HTTPNotFound('The format %s cannot be viewed' % fmt.upper())
|
||||||
if book_id not in ctx.allowed_book_ids(rd, db):
|
if book_id not in ctx.allowed_book_ids(rd, db):
|
||||||
@ -129,6 +130,8 @@ def book_manifest(ctx, rd, book_id, fmt):
|
|||||||
bhash = book_hash(db.library_id, book_id, fmt, size, mtime)
|
bhash = book_hash(db.library_id, book_id, fmt, size, mtime)
|
||||||
with cache_lock:
|
with cache_lock:
|
||||||
mpath = abspath(os.path.join(books_cache_dir(), 'f', bhash, 'calibre-book-manifest.json'))
|
mpath = abspath(os.path.join(books_cache_dir(), 'f', bhash, 'calibre-book-manifest.json'))
|
||||||
|
if force_reload:
|
||||||
|
safe_remove(mpath, True)
|
||||||
try:
|
try:
|
||||||
os.utime(mpath, None)
|
os.utime(mpath, None)
|
||||||
with lopen(mpath, 'rb') as f:
|
with lopen(mpath, 'rb') as f:
|
||||||
|
@ -5,8 +5,6 @@ from __python__ import hash_literals
|
|||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
from encodings import base64encode, base64decode
|
from encodings import base64encode, base64decode
|
||||||
|
|
||||||
FORCE_BOOK_RELOAD = False # set to True to force book reloading
|
|
||||||
|
|
||||||
def upgrade_schema(idb, old_version, new_version):
|
def upgrade_schema(idb, old_version, new_version):
|
||||||
print('upgrade_schema:', old_version, new_version)
|
print('upgrade_schema:', old_version, new_version)
|
||||||
if not idb.objectStoreNames.contains('books'):
|
if not idb.objectStoreNames.contains('books'):
|
||||||
@ -82,8 +80,6 @@ class DB:
|
|||||||
# refer to non-serializable objects like functions.
|
# refer to non-serializable objects like functions.
|
||||||
key = v'[self.interface_data.library_id, book_id, fmt]'
|
key = v'[self.interface_data.library_id, book_id, fmt]'
|
||||||
self.do_op(['books'], key, _('Failed to read from the books database'), def(result):
|
self.do_op(['books'], key, _('Failed to read from the books database'), def(result):
|
||||||
if FORCE_BOOK_RELOAD:
|
|
||||||
result = None
|
|
||||||
proceed(result or {
|
proceed(result or {
|
||||||
'key':key,
|
'key':key,
|
||||||
'is_complete':False,
|
'is_complete':False,
|
||||||
|
@ -95,17 +95,17 @@ class ReadUI:
|
|||||||
div = document.getElementById(self.progress_id)
|
div = document.getElementById(self.progress_id)
|
||||||
div.lastChild.textContent = msg or ''
|
div.lastChild.textContent = msg or ''
|
||||||
|
|
||||||
def load_book(self, book_id, fmt, metadata):
|
def load_book(self, book_id, fmt, metadata, force_reload):
|
||||||
self.base_url_data = {'book_id':book_id, 'fmt':fmt}
|
self.base_url_data = {'book_id':book_id, 'fmt':fmt}
|
||||||
if self.db is None:
|
if self.db is None:
|
||||||
self.pending_load = [book_id, fmt, metadata]
|
self.pending_load = [book_id, fmt, metadata, force_reload]
|
||||||
return
|
return
|
||||||
self.start_load(book_id, fmt, metadata)
|
self.start_load(book_id, fmt, metadata, force_reload)
|
||||||
|
|
||||||
def reload_book(self):
|
def reload_book(self):
|
||||||
book_id = self.base_url_data.book_id
|
book_id = self.base_url_data.book_id
|
||||||
metadata = self.metadata or self.interface_data.metadata[book_id]
|
metadata = self.metadata or self.interface_data.metadata[book_id]
|
||||||
self.load_book(book_id, self.base_url_data.fmt, metadata)
|
self.load_book(book_id, self.base_url_data.fmt, metadata, True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url_data(self):
|
def url_data(self):
|
||||||
@ -121,7 +121,7 @@ class ReadUI:
|
|||||||
pl, self.pending_load = self.pending_load, None
|
pl, self.pending_load = self.pending_load, None
|
||||||
self.start_load(*pl)
|
self.start_load(*pl)
|
||||||
|
|
||||||
def start_load(self, book_id, fmt, metadata):
|
def start_load(self, book_id, fmt, metadata, force_reload):
|
||||||
self.current_book_id = book_id
|
self.current_book_id = book_id
|
||||||
metadata = metadata or self.interface_data.metadata[book_id]
|
metadata = metadata or self.interface_data.metadata[book_id]
|
||||||
self.current_metadata = metadata or {'title':_('Book id #') + book_id}
|
self.current_metadata = metadata or {'title':_('Book id #') + book_id}
|
||||||
@ -130,21 +130,23 @@ class ReadUI:
|
|||||||
if type(self.db) is 'string':
|
if type(self.db) is 'string':
|
||||||
self.show_error(_('Cannot read book'), self.db)
|
self.show_error(_('Cannot read book'), self.db)
|
||||||
return
|
return
|
||||||
self.db.get_book(book_id, fmt, metadata, self.got_book.bind(self))
|
self.db.get_book(book_id, fmt, metadata, self.got_book.bind(self, force_reload))
|
||||||
|
|
||||||
def got_book(self, book):
|
def got_book(self, force_reload, book):
|
||||||
if not book.manifest or book.manifest.version is not RENDER_VERSION or not book.is_complete:
|
if not book.manifest or book.manifest.version is not RENDER_VERSION or not book.is_complete:
|
||||||
# We re-download the manifest when the book is not complete to ensure we have the
|
# We re-download the manifest when the book is not complete to ensure we have the
|
||||||
# correct manifest, even though doing so is not strictly necessary
|
# correct manifest, even though doing so is not strictly necessary
|
||||||
self.get_manifest(book)
|
self.get_manifest(book, force_reload)
|
||||||
else:
|
else:
|
||||||
self.display_book(book)
|
self.display_book(book)
|
||||||
|
|
||||||
def get_manifest(self, book):
|
def get_manifest(self, book, force_reload):
|
||||||
library_id, book_id, fmt = book.key
|
library_id, book_id, fmt = book.key
|
||||||
if self.manifest_xhr:
|
if self.manifest_xhr:
|
||||||
self.manifest_xhr.abort()
|
self.manifest_xhr.abort()
|
||||||
query = {'library_id': library_id}
|
query = {'library_id': library_id}
|
||||||
|
if force_reload:
|
||||||
|
query.force_reload = '1'
|
||||||
self.manifest_xhr = ajax(('book-manifest/' + encodeURIComponent(book_id) + '/' + encodeURIComponent(fmt)),
|
self.manifest_xhr = ajax(('book-manifest/' + encodeURIComponent(book_id) + '/' + encodeURIComponent(fmt)),
|
||||||
self.got_manifest.bind(self, book), query=query)
|
self.got_manifest.bind(self, book), query=query)
|
||||||
self.manifest_xhr.send()
|
self.manifest_xhr.send()
|
||||||
|
@ -157,6 +157,7 @@ class View:
|
|||||||
def display_book(self, book):
|
def display_book(self, book):
|
||||||
self.book = book
|
self.book = book
|
||||||
self.ui.db.update_last_read_time(book)
|
self.ui.db.update_last_read_time(book)
|
||||||
|
self.loaded_resources = {}
|
||||||
pos = {'replace_history':True}
|
pos = {'replace_history':True}
|
||||||
unkey = username_key(self.ui.interface_data.username)
|
unkey = username_key(self.ui.interface_data.username)
|
||||||
name = book.manifest.spine[0]
|
name = book.manifest.spine[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user