Interdevice page save
This commit is contained in:
parent
184ce23351
commit
5d7f43122b
|
@ -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");
|
||||
|
@ -53,6 +54,13 @@ var reader;
|
|||
}
|
||||
});
|
||||
|
||||
var $next = $('#next');
|
||||
var $prev = $('#prev');
|
||||
|
||||
$next.on("click", updateLastCFI.bind(reader));
|
||||
|
||||
$prev.on("click", updateLastCFI.bind(reader));
|
||||
|
||||
/**
|
||||
* @param {string} action - Add or remove bookmark
|
||||
* @param {string|int} location - Location or zero
|
||||
|
@ -78,6 +86,20 @@ var reader;
|
|||
alert(error);
|
||||
});
|
||||
}
|
||||
|
||||
function updateLastCFI(event) {
|
||||
var cfi = this.rendition.location.start.cfi;
|
||||
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) {
|
||||
|
|
11
cps/ub.py
11
cps/ub.py
|
@ -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"):
|
||||
|
|
23
cps/web.py
23
cps/web.py
|
@ -164,6 +164,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
|
||||
|
@ -1540,9 +1558,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…
Reference in New Issue