dydyamotya 3 weeks ago committed by GitHub
commit adc946f4f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -10,7 +10,8 @@ var reader;
reader = ePubReader(calibre.bookUrl, {
restore: true,
bookmarks: calibre.bookmark ? [calibre.bookmark] : []
bookmarks: calibre.bookmark ? [calibre.bookmark] : [],
previousLocationCfi: calibre.lastCFI || ""
});
reader.rendition.themes.register("lightTheme", "/static/css/epub_themes.css");
@ -18,6 +19,7 @@ var reader;
reader.rendition.themes.register("sepiaTheme", "/static/css/epub_themes.css");
reader.rendition.themes.register("blackTheme", "/static/css/epub_themes.css");
if (calibre.useBookmarks) {
reader.on("reader:bookmarked", updateBookmark.bind(reader, "add"));
reader.on("reader:unbookmarked", updateBookmark.bind(reader, "remove"));
@ -52,6 +54,8 @@ var reader;
// Swiped Left
}
});
reader.rendition.on("locationChanged", updateLastCFI);
/**
* @param {string} action - Add or remove bookmark
@ -78,6 +82,20 @@ var reader;
alert(error);
});
}
function updateLastCFI(location) {
var cfi = location.start;
var csrftoken = $("input[name='csrf_token']").val();
// Save to database
$.ajax(calibre.lastCFIUrl, {
method: "post",
data: { lastCFI: cfi || "" },
headers: { "X-CSRFToken": csrftoken }
}).fail(function (xhr, status, error) {
alert(error);
});
}
})();

@ -108,7 +108,9 @@
bookmarkUrl: "{{ url_for('web.set_bookmark', book_id=bookid, book_format='EPUB') }}",
bookUrl: "{{ url_for('web.serve_book', book_id=bookid, book_format='epub', anyname='file.epub') }}",
bookmark: "{{ bookmark.bookmark_key if bookmark != None }}",
useBookmarks: "{{ current_user.is_authenticated | tojson }}"
useBookmarks: "{{ current_user.is_authenticated | tojson }}",
lastCFIUrl: "{{ url_for('web.set_lastcfi', book_id=bookid, book_format='EPUB') }}",
lastCFI: "{{ lastCFI.cfi if lastCFI != None }}",
};
function selectTheme(id) {

@ -403,6 +403,15 @@ class Bookmark(Base):
bookmark_key = Column(String)
class LastCFI(Base):
__tablename__ = 'lastcfi'
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey('user.id'))
book_id = Column(Integer)
format = Column(String(collation='NOCASE'))
cfi = Column(String)
# Baseclass representing books that are archived on the user's Kobo device.
class ArchivedBook(Base):
__tablename__ = 'archived_book'
@ -542,6 +551,8 @@ def add_missing_tables(engine, _session):
ReadBook.__table__.create(bind=engine)
if not engine.dialect.has_table(engine.connect(), "bookmark"):
Bookmark.__table__.create(bind=engine)
if not engine.dialect.has_table(engine.connect(), "lastcfi"):
LastCFI.__table__.create(bind=engine)
if not engine.dialect.has_table(engine.connect(), "kobo_reading_state"):
KoboReadingState.__table__.create(bind=engine)
if not engine.dialect.has_table(engine.connect(), "kobo_bookmark"):

@ -168,6 +168,24 @@ def set_bookmark(book_id, book_format):
ub.session_commit("Bookmark for user {} in book {} created".format(current_user.id, book_id))
return "", 201
@web.route("/ajax/lastcfi/<int:book_id>/<book_format>", methods=['POST'])
@login_required
def set_lastcfi(book_id: int, book_format: str):
cfi = request.form["lastCFI"]
ub.session.query(ub.LastCFI).filter(and_(ub.LastCFI.user_id == int(current_user.id),
ub.LastCFI.book_id == book_id,
ub.LastCFI.format == book_format)).delete()
if not cfi:
ub.session_commit()
return "", 204
l_cfi = ub.LastCFI(user_id=current_user.id,
book_id=book_id,
format=book_format,
cfi=cfi)
ub.session.merge(l_cfi)
ub.session_commit("LastCFI for user {} in book {} created".format(current_user.id, book_id))
return "", 201
@web.route("/ajax/toggleread/<int:book_id>", methods=['POST'])
@login_required
@ -1571,9 +1589,12 @@ def read_book(book_id, book_format):
bookmark = ub.session.query(ub.Bookmark).filter(and_(ub.Bookmark.user_id == int(current_user.id),
ub.Bookmark.book_id == book_id,
ub.Bookmark.format == book_format.upper())).first()
lastcfi = ub.session.query(ub.LastCFI).filter(and_(ub.LastCFI.user_id == int(current_user.id),
ub.LastCFI.book_id == book_id,
ub.LastCFI.format == book_format.upper())).first()
if book_format.lower() == "epub":
log.debug("Start epub reader for %d", book_id)
return render_title_template('read.html', bookid=book_id, title=book.title, bookmark=bookmark)
return render_title_template('read.html', bookid=book_id, title=book.title, bookmark=bookmark, lastCFI=lastcfi)
elif book_format.lower() == "pdf":
log.debug("Start pdf reader for %d", book_id)
return render_title_template('readpdf.html', pdffile=book_id, title=book.title)

Loading…
Cancel
Save