Logging of details for gdrive integration only on debug level
fix generic cover path browser reading for cbx and epub files no longer creates temp files on server browser reading for cbx and epub files working (#502, #520)
This commit is contained in:
parent
55a56725ed
commit
76d8cbdf57
|
@ -348,7 +348,7 @@ def getChangeById (drive, change_id):
|
||||||
try:
|
try:
|
||||||
change = drive.auth.service.changes().get(changeId=change_id).execute()
|
change = drive.auth.service.changes().get(changeId=change_id).execute()
|
||||||
return change
|
return change
|
||||||
except (errors.HttpError, error):
|
except (errors.HttpError) as error:
|
||||||
web.app.logger.exception(error)
|
web.app.logger.exception(error)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
14
cps/static/js/libs/jszip.min.js
vendored
Normal file
14
cps/static/js/libs/jszip.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -81,13 +81,14 @@
|
||||||
window.calibre = {
|
window.calibre = {
|
||||||
filePath: "{{ url_for('static', filename='js/libs/') }}",
|
filePath: "{{ url_for('static', filename='js/libs/') }}",
|
||||||
cssPath: "{{ url_for('static', filename='css/') }}",
|
cssPath: "{{ url_for('static', filename='css/') }}",
|
||||||
bookUrl: "{{ url_for('static', filename=bookid) }}/",
|
|
||||||
bookmarkUrl: "{{ url_for('bookmark', book_id=bookid, book_format='EPUB') }}",
|
bookmarkUrl: "{{ url_for('bookmark', book_id=bookid, book_format='EPUB') }}",
|
||||||
|
bookUrl: "{{ url_for('get_download_link_ext', book_id=bookid, book_format="epub", anyname='file.epub') }}",
|
||||||
bookmark: "{{ bookmark.bookmark_key if bookmark != None }}",
|
bookmark: "{{ bookmark.bookmark_key if bookmark != None }}",
|
||||||
useBookmarks: {{ g.user.is_authenticated | tojson }}
|
useBookmarks: {{ g.user.is_authenticated | tojson }}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<script src="{{ url_for('static', filename='js/libs/jquery.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/jquery.min.js') }}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/libs/jszip.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/libs/zip.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/zip.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/libs/screenfull.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/screenfull.min.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/libs/epub.min.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/libs/epub.min.js') }}"></script>
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<script>
|
<script>
|
||||||
document.onreadystatechange = function () {
|
document.onreadystatechange = function () {
|
||||||
if (document.readyState == "complete") {
|
if (document.readyState == "complete") {
|
||||||
init("{{ url_for('static', filename=comicfile) }}");
|
init("{{ url_for('serve_book', book_id=comicfile, book_format=extension) }}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
51
cps/web.py
51
cps/web.py
|
@ -1602,7 +1602,7 @@ def revoke_watch_gdrive():
|
||||||
|
|
||||||
@app.route("/gdrive/watch/callback", methods=['GET', 'POST'])
|
@app.route("/gdrive/watch/callback", methods=['GET', 'POST'])
|
||||||
def on_received_watch_confirmation():
|
def on_received_watch_confirmation():
|
||||||
app.logger.info(request.headers)
|
app.logger.debug(request.headers)
|
||||||
if request.headers.get('X-Goog-Channel-Token') == gdrive_watch_callback_token \
|
if request.headers.get('X-Goog-Channel-Token') == gdrive_watch_callback_token \
|
||||||
and request.headers.get('X-Goog-Resource-State') == 'change' \
|
and request.headers.get('X-Goog-Resource-State') == 'change' \
|
||||||
and request.data:
|
and request.data:
|
||||||
|
@ -1611,12 +1611,12 @@ def on_received_watch_confirmation():
|
||||||
|
|
||||||
def updateMetaData():
|
def updateMetaData():
|
||||||
app.logger.info('Change received from gdrive')
|
app.logger.info('Change received from gdrive')
|
||||||
app.logger.info(data)
|
app.logger.debug(data)
|
||||||
try:
|
try:
|
||||||
j = json.loads(data)
|
j = json.loads(data)
|
||||||
app.logger.info('Getting change details')
|
app.logger.info('Getting change details')
|
||||||
response = gdriveutils.getChangeById(Gdrive.Instance().drive, j['id'])
|
response = gdriveutils.getChangeById(Gdrive.Instance().drive, j['id'])
|
||||||
app.logger.info(response)
|
app.logger.debug(response)
|
||||||
if response:
|
if response:
|
||||||
dbpath = os.path.join(config.config_calibre_dir, "metadata.db")
|
dbpath = os.path.join(config.config_calibre_dir, "metadata.db")
|
||||||
if not response['deleted'] and response['file']['title'] == 'metadata.db' and response['file']['md5Checksum'] != md5(dbpath):
|
if not response['deleted'] and response['file']['title'] == 'metadata.db' and response['file']['md5Checksum'] != md5(dbpath):
|
||||||
|
@ -1818,7 +1818,7 @@ def get_cover(cover_path):
|
||||||
try:
|
try:
|
||||||
return redirect(get_cover_via_gdrive(cover_path))
|
return redirect(get_cover_via_gdrive(cover_path))
|
||||||
except:
|
except:
|
||||||
app.logger.error(cover_path + '/cover.jpg ' + _('not found on GDrive'))
|
app.logger.error(cover_path + '/cover.jpg ' + 'not found on GDrive')
|
||||||
return send_from_directory(os.path.join(os.path.dirname(__file__), "static"),"generic_cover.jpg")
|
return send_from_directory(os.path.join(os.path.dirname(__file__), "static"),"generic_cover.jpg")
|
||||||
else:
|
else:
|
||||||
return send_from_directory(os.path.join(config.config_calibre_dir, cover_path), "cover.jpg")
|
return send_from_directory(os.path.join(config.config_calibre_dir, cover_path), "cover.jpg")
|
||||||
|
@ -1922,50 +1922,31 @@ def read_book(book_id, book_format):
|
||||||
flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error")
|
flash(_(u"Error opening eBook. File does not exist or file is not accessible:"), category="error")
|
||||||
return redirect(url_for("index"))
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
book_dir = os.path.join(config.get_main_dir, "cps", "static", str(book_id))
|
# check if book was downloaded before
|
||||||
if not os.path.exists(book_dir):
|
|
||||||
os.mkdir(book_dir)
|
|
||||||
bookmark = None
|
bookmark = None
|
||||||
if current_user.is_authenticated:
|
if current_user.is_authenticated:
|
||||||
bookmark = ub.session.query(ub.Bookmark).filter(ub.and_(ub.Bookmark.user_id == int(current_user.id),
|
bookmark = ub.session.query(ub.Bookmark).filter(ub.and_(ub.Bookmark.user_id == int(current_user.id),
|
||||||
ub.Bookmark.book_id == book_id,
|
ub.Bookmark.book_id == book_id,
|
||||||
ub.Bookmark.format == book_format.upper())).first()
|
ub.Bookmark.format == book_format.upper())).first()
|
||||||
if book_format.lower() == "epub":
|
if book_format.lower() == "epub":
|
||||||
# check if mimetype file is exists
|
|
||||||
mime_file = str(book_id) + "/mimetype"
|
|
||||||
if not os.path.exists(mime_file):
|
|
||||||
epub_file = os.path.join(config.config_calibre_dir, book.path, book.data[0].name) + ".epub"
|
|
||||||
if not os.path.isfile(epub_file):
|
|
||||||
raise ValueError('Error opening eBook. File does not exist: ', epub_file)
|
|
||||||
zfile = zipfile.ZipFile(epub_file)
|
|
||||||
for name in zfile.namelist():
|
|
||||||
(dirName, fileName) = os.path.split(name)
|
|
||||||
newDir = os.path.join(book_dir, dirName)
|
|
||||||
if not os.path.exists(newDir):
|
|
||||||
try:
|
|
||||||
os.makedirs(newDir)
|
|
||||||
except OSError as exception:
|
|
||||||
if not exception.errno == errno.EEXIST:
|
|
||||||
raise
|
|
||||||
if fileName:
|
|
||||||
fd = open(os.path.join(newDir, fileName), "wb")
|
|
||||||
fd.write(zfile.read(name))
|
|
||||||
fd.close()
|
|
||||||
zfile.close()
|
|
||||||
return render_title_template('read.html', bookid=book_id, title=_(u"Read a Book"), bookmark=bookmark)
|
return render_title_template('read.html', bookid=book_id, title=_(u"Read a Book"), bookmark=bookmark)
|
||||||
elif book_format.lower() == "pdf":
|
elif book_format.lower() == "pdf":
|
||||||
return render_title_template('readpdf.html', pdffile=book_id, title=_(u"Read a Book"))
|
return render_title_template('readpdf.html', pdffile=book_id, title=_(u"Read a Book"))
|
||||||
elif book_format.lower() == "txt":
|
elif book_format.lower() == "txt":
|
||||||
return render_title_template('readtxt.html', txtfile=book_id, title=_(u"Read a Book"))
|
return render_title_template('readtxt.html', txtfile=book_id, title=_(u"Read a Book"))
|
||||||
else:
|
else:
|
||||||
|
book_dir = os.path.join(config.get_main_dir, "cps", "static", str(book_id))
|
||||||
|
if not os.path.exists(book_dir):
|
||||||
|
os.mkdir(book_dir)
|
||||||
for fileext in ["cbr", "cbt", "cbz"]:
|
for fileext in ["cbr", "cbt", "cbz"]:
|
||||||
if book_format.lower() == fileext:
|
if book_format.lower() == fileext:
|
||||||
all_name = str(book_id) + "/" + book.data[0].name + "." + fileext
|
all_name = str(book_id) # + "/" + book.data[0].name + "." + fileext
|
||||||
tmp_file = os.path.join(book_dir, book.data[0].name) + "." + fileext
|
#tmp_file = os.path.join(book_dir, book.data[0].name) + "." + fileext
|
||||||
if not os.path.exists(all_name):
|
#if not os.path.exists(all_name):
|
||||||
cbr_file = os.path.join(config.config_calibre_dir, book.path, book.data[0].name) + "." + fileext
|
# cbr_file = os.path.join(config.config_calibre_dir, book.path, book.data[0].name) + "." + fileext
|
||||||
copyfile(cbr_file, tmp_file)
|
# copyfile(cbr_file, tmp_file)
|
||||||
return render_title_template('readcbr.html', comicfile=all_name, title=_(u"Read a Book"))
|
return render_title_template('readcbr.html', comicfile=all_name, title=_(u"Read a Book"),
|
||||||
|
extension=fileext)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/download/<int:book_id>/<book_format>")
|
@app.route("/download/<int:book_id>/<book_format>")
|
||||||
|
@ -3317,7 +3298,7 @@ def upload():
|
||||||
if meta.cover is None:
|
if meta.cover is None:
|
||||||
has_cover = 0
|
has_cover = 0
|
||||||
basedir = config.get_main_dir # os.path.dirname(__file__)
|
basedir = config.get_main_dir # os.path.dirname(__file__)
|
||||||
copyfile(os.path.join(basedir, "static/generic_cover.jpg"), os.path.join(filepath, "cover.jpg"))
|
copyfile(os.path.join(basedir, "cps/static/generic_cover.jpg"), os.path.join(filepath, "cover.jpg"))
|
||||||
else:
|
else:
|
||||||
has_cover = 1
|
has_cover = 1
|
||||||
move(meta.cover, os.path.join(filepath, "cover.jpg"))
|
move(meta.cover, os.path.join(filepath, "cover.jpg"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user