mirror of
https://github.com/JonathanHerrewijnen/calibre-web.git
synced 2024-11-14 07:03:50 +00:00
Fixed empty return on getcomic
Python 3 compability (the easy way)
This commit is contained in:
commit
d76f812310
@ -21,9 +21,9 @@
|
|||||||
{{_('Download')}} :
|
{{_('Download')}} :
|
||||||
</button>
|
</button>
|
||||||
{% for format in entry.data %}
|
{% for format in entry.data %}
|
||||||
<a href="{{ url_for('get_download_link_ext', book_id=entry.id, book_format=format.format|lower, anyname=entry.id|string+'.'+format.format) }}" id="btnGroupDrop1{{format.format|lower}}" class="btn btn-primary" role="button">
|
<a href="{{ url_for('get_download_link_ext', book_id=entry.id, book_format=format.format|lower, anyname=entry.id|string+'.'+format.format) }}" id="btnGroupDrop1{{format.format|lower}}" class="btn btn-primary" role="button">
|
||||||
<span class="glyphicon glyphicon-download"></span>{{format.format}} ({{ format.uncompressed_size|filesizeformat }})
|
<span class="glyphicon glyphicon-download"></span>{{format.format}} ({{ format.uncompressed_size|filesizeformat }})
|
||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<button id="btnGroupDrop1" type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
<button id="btnGroupDrop1" type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
@ -32,7 +32,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu" aria-labelledby="btnGroupDrop1">
|
<ul class="dropdown-menu" aria-labelledby="btnGroupDrop1">
|
||||||
{% for format in entry.data %}
|
{% for format in entry.data %}
|
||||||
<li><a href="{{ url_for('get_download_link_ext', book_id=entry.id, book_format=format.format|lower, anyname=entry.id|string+'.'+format.format) }}">{{format.format}} ({{ format.uncompressed_size|filesizeformat }})</a></li>
|
<li><a href="{{ url_for('get_download_link_ext', book_id=entry.id, book_format=format.format|lower, anyname=entry.id|string+'.'+format.format) }}">{{format.format}} ({{ format.uncompressed_size|filesizeformat }})</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -50,9 +50,9 @@
|
|||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu" aria-labelledby="read-in-browser">
|
<ul class="dropdown-menu" aria-labelledby="read-in-browser">
|
||||||
{% for format in entry.data %}
|
{% for format in entry.data %}
|
||||||
{%if format.format|lower == 'epub' or format.format|lower == 'txt' or format.format|lower == 'pdf' or format.format|lower == 'cbr' or format.format|lower == 'cbt' or format.format|lower == 'cbz' %}
|
{%if format.format|lower == 'epub' or format.format|lower == 'txt' or format.format|lower == 'pdf' or ( format.format|lower == 'cbr' and rarsupport ) or format.format|lower == 'cbt' or format.format|lower == 'cbz' %}
|
||||||
<li><a target="_blank" href="{{ url_for('read_book', book_id=entry.id, book_format=format.format|lower) }}">{{format.format}}</a></li>
|
<li><a target="_blank" href="{{ url_for('read_book', book_id=entry.id, book_format=format.format|lower) }}">{{format.format}}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{%endfor%}
|
{%endfor%}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
22
cps/web.py
22
cps/web.py
@ -99,6 +99,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from flask_login.__about__ import __version__ as flask_loginVersion
|
from flask_login.__about__ import __version__ as flask_loginVersion
|
||||||
|
|
||||||
|
import codecs
|
||||||
import time
|
import time
|
||||||
|
|
||||||
current_milli_time = lambda: int(round(time.time() * 1000))
|
current_milli_time = lambda: int(round(time.time() * 1000))
|
||||||
@ -931,7 +932,8 @@ def get_comic_book(book_id, book_format, page):
|
|||||||
try:
|
try:
|
||||||
rf = rarfile.RarFile(cbr_file)
|
rf = rarfile.RarFile(cbr_file)
|
||||||
rarNames = rf.namelist()
|
rarNames = rf.namelist()
|
||||||
extractedfile="data:image/png;base64," + (rf.read(rarNames[page])).encode('base64')
|
b64 = codecs.encode(rf.read(rarNames[page]), 'base64').decode()
|
||||||
|
extractedfile="data:image/png;base64," + b64
|
||||||
fileData={"name": rarNames[page],"page":page, "last":rarNames.__len__()-1, "content": extractedfile}
|
fileData={"name": rarNames[page],"page":page, "last":rarNames.__len__()-1, "content": extractedfile}
|
||||||
except:
|
except:
|
||||||
# rarfile not valid
|
# rarfile not valid
|
||||||
@ -944,15 +946,24 @@ def get_comic_book(book_id, book_format, page):
|
|||||||
if book_format == "cbz":
|
if book_format == "cbz":
|
||||||
zf = zipfile.ZipFile(cbr_file)
|
zf = zipfile.ZipFile(cbr_file)
|
||||||
zipNames=zf.namelist()
|
zipNames=zf.namelist()
|
||||||
extractedfile="data:image/png;base64," + (zf.read(zipNames[page])).encode('base64')
|
if sys.version_info.major >= 3:
|
||||||
|
b64 = codecs.encode(zf.read(zipNames[page]), 'base64').decode()
|
||||||
|
else:
|
||||||
|
b64 = zf.read(zipNames[page]).encode('base64')
|
||||||
|
extractedfile="data:image/png;base64," + b64
|
||||||
fileData={"name": zipNames[page],"page":page, "last":zipNames.__len__()-1, "content": extractedfile}
|
fileData={"name": zipNames[page],"page":page, "last":zipNames.__len__()-1, "content": extractedfile}
|
||||||
|
|
||||||
if book_format == "cbt":
|
if book_format == "cbt":
|
||||||
tf = tarfile.TarFile(u'D:\\zip\\test.cbt')
|
tf = tarfile.TarFile(u'D:\\zip\\test.cbt')
|
||||||
tarNames=tf.getnames()
|
tarNames=tf.getnames()
|
||||||
extractedfile="data:image/png;base64," + (tf.extractfile(tarNames[page]).read()).encode('base64')
|
if sys.version_info.major >= 3:
|
||||||
|
b64 = codecs.encode(tf.extractfile(tarNames[page]).read(), 'base64').decode()
|
||||||
|
else:
|
||||||
|
b64 = (tf.extractfile(tarNames[page]).read()).encode('base64')
|
||||||
|
extractedfile="data:image/png;base64," + bs
|
||||||
fileData={"name": tarNames[page],"page":page, "last":tarNames.__len__()-1, "content": extractedfile}
|
fileData={"name": tarNames[page],"page":page, "last":tarNames.__len__()-1, "content": extractedfile}
|
||||||
return make_response(json.dumps(fileData))
|
return make_response(json.dumps(fileData))
|
||||||
|
return "", 204
|
||||||
|
|
||||||
@app.route("/ajax/toggleread/<int:book_id>", methods=['POST'])
|
@app.route("/ajax/toggleread/<int:book_id>", methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
@ -1458,7 +1469,8 @@ def show_book(book_id):
|
|||||||
have_read = None
|
have_read = None
|
||||||
|
|
||||||
return render_title_template('detail.html', entry=entries, cc=cc, is_xhr=request.is_xhr,
|
return render_title_template('detail.html', entry=entries, cc=cc, is_xhr=request.is_xhr,
|
||||||
title=entries.title, books_shelfs=book_in_shelfs, have_read=have_read)
|
title=entries.title, books_shelfs=book_in_shelfs, have_read=have_read,
|
||||||
|
rarsupport=rar_support)
|
||||||
else:
|
else:
|
||||||
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"))
|
||||||
@ -3231,7 +3243,7 @@ def upload():
|
|||||||
title=_(u"edit metadata"))
|
title=_(u"edit metadata"))
|
||||||
book_in_shelfs = []
|
book_in_shelfs = []
|
||||||
return render_title_template('detail.html', entry=db_book, cc=cc, title=db_book.title,
|
return render_title_template('detail.html', entry=db_book, cc=cc, title=db_book.title,
|
||||||
books_shelfs=book_in_shelfs, )
|
books_shelfs=book_in_shelfs, rarsupport=rar_support )
|
||||||
else:
|
else:
|
||||||
return redirect(url_for("index"))
|
return redirect(url_for("index"))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user