mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-28 12:30:00 +00:00
Error handling rarfiles
This commit is contained in:
parent
9f8cbe8c1f
commit
5756785073
@ -508,3 +508,22 @@ class Updater(threading.Thread):
|
||||
logging.getLogger('cps.web').debug("Could not remove:" + item_path)
|
||||
shutil.rmtree(source, ignore_errors=True)
|
||||
|
||||
def check_unrar(unrarLocation):
|
||||
error = False
|
||||
if os.path.exists(unrarLocation):
|
||||
try:
|
||||
p = subprocess.Popen(unrarLocation, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
p.wait()
|
||||
for lines in p.stdout.readlines():
|
||||
if isinstance(lines, bytes):
|
||||
lines = lines.decode('utf-8')
|
||||
value=re.search('UNRAR (.*) freeware', lines)
|
||||
if value:
|
||||
version = value.group(1)
|
||||
except Exception:
|
||||
error = True
|
||||
version=_(u'Excecution permissions missing')
|
||||
else:
|
||||
version = _(u'Unrar binary file not found')
|
||||
error=True
|
||||
return (error, version)
|
||||
|
@ -289,16 +289,15 @@ function loadFromArrayBuffer(ab) {
|
||||
imageFilenames.push(f.filename);
|
||||
imageFiles.push(new kthoom.ImageFile(f));
|
||||
|
||||
// add thumbnails to the TOC list
|
||||
$('#thumbnails').append(
|
||||
"<li> \
|
||||
<a data-page='"+ imageFiles.length +"'> \
|
||||
<img src='"+ imageFiles[imageFiles.length - 1].dataURI +"' /> \
|
||||
<span>"+ imageFiles.length +"</span> \
|
||||
</a> \
|
||||
</li>"
|
||||
);
|
||||
//}
|
||||
// add thumbnails to the TOC list
|
||||
$('#thumbnails').append(
|
||||
"<li> \
|
||||
<a data-page='"+ imageFiles.length +"'> \
|
||||
<img src='"+ imageFiles[imageFiles.length - 1].dataURI +"' /> \
|
||||
<span>"+ imageFiles.length +"</span> \
|
||||
</a> \
|
||||
</li>"
|
||||
);
|
||||
}
|
||||
var percentage = (ab.page+1) / (ab.last+1);
|
||||
totalImages = ab.last+1;
|
||||
@ -339,81 +338,93 @@ function setImage(url) {
|
||||
updateScale(true);
|
||||
canvas.width = innerWidth - 100;
|
||||
canvas.height = 200;
|
||||
x.fillStyle = "red";
|
||||
x.font = "50px sans-serif";
|
||||
x.fillStyle = "black";
|
||||
x.textAlign="center";
|
||||
x.font = "24px sans-serif";
|
||||
x.strokeStyle = "black";
|
||||
x.fillText("Loading Page #" + (currentImage + 1), 100, 100);
|
||||
x.fillText("Loading Page #" + (currentImage + 1), innerWidth/2, 100);
|
||||
} else {
|
||||
if ($("body").css("scrollHeight") / innerHeight > 1) {
|
||||
$("body").css("overflowY", "scroll");
|
||||
}
|
||||
|
||||
var img = new Image();
|
||||
img.onerror = function() {
|
||||
canvas.width = innerWidth - 100;
|
||||
canvas.height = 300;
|
||||
if (url === "error") {
|
||||
updateScale(true);
|
||||
x.fillStyle = "orange";
|
||||
x.font = "50px sans-serif";
|
||||
canvas.width = innerWidth - 100;
|
||||
canvas.height = 200;
|
||||
x.fillStyle = "black";
|
||||
x.textAlign="center";
|
||||
x.font = "24px sans-serif";
|
||||
x.strokeStyle = "black";
|
||||
x.fillText("Page #" + (currentImage + 1) + " (" +
|
||||
imageFiles[currentImage].filename + ")", 100, 100);
|
||||
x.fillStyle = "red";
|
||||
x.fillText("Is corrupt or not an image", 100, 200);
|
||||
x.fillText("Unable to decompress image #" + (currentImage + 1), innerWidth/2, 100);
|
||||
} else {
|
||||
if ($("body").css("scrollHeight") / innerHeight > 1) {
|
||||
$("body").css("overflowY", "scroll");
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
if (/(html|htm)$/.test(imageFiles[currentImage].filename)) {
|
||||
xhr.open("GET", url, true);
|
||||
xhr.onload = function() {
|
||||
//document.getElementById('mainText').style.display = '';
|
||||
$("#mainText").css("display", "");
|
||||
$("#mainText").innerHTML("<iframe style=\"width:100%;height:700px;border:0\" src=\"data:text/html," + escape(xhr.responseText) + "\"></iframe>");
|
||||
var img = new Image();
|
||||
img.onerror = function() {
|
||||
canvas.width = innerWidth - 100;
|
||||
canvas.height = 300;
|
||||
updateScale(true);
|
||||
x.fillStyle = "black";
|
||||
x.font = "50px sans-serif";
|
||||
x.strokeStyle = "black";
|
||||
x.fillText("Page #" + (currentImage + 1) + " (" +
|
||||
imageFiles[currentImage].filename + ")", innerWidth/2, 100);
|
||||
x.fillStyle = "black";
|
||||
x.fillText("Is corrupt or not an image", innerWidth/2, 200);
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
if (/(html|htm)$/.test(imageFiles[currentImage].filename)) {
|
||||
xhr.open("GET", url, true);
|
||||
xhr.onload = function() {
|
||||
//document.getElementById('mainText').style.display = '';
|
||||
$("#mainText").css("display", "");
|
||||
$("#mainText").innerHTML("<iframe style=\"width:100%;height:700px;border:0\" src=\"data:text/html," + escape(xhr.responseText) + "\"></iframe>");
|
||||
}
|
||||
xhr.send(null);
|
||||
} else if (!/(jpg|jpeg|png|gif)$/.test(imageFiles[currentImage].filename) && imageFiles[currentImage].data.uncompressedSize < 10 * 1024) {
|
||||
xhr.open("GET", url, true);
|
||||
xhr.onload = function() {
|
||||
$("#mainText").css("display", "");
|
||||
$("#mainText").innerText(xhr.responseText);
|
||||
};
|
||||
xhr.send(null);
|
||||
}
|
||||
xhr.send(null);
|
||||
} else if (!/(jpg|jpeg|png|gif)$/.test(imageFiles[currentImage].filename) && imageFiles[currentImage].data.uncompressedSize < 10 * 1024) {
|
||||
xhr.open("GET", url, true);
|
||||
xhr.onload = function() {
|
||||
$("#mainText").css("display", "");
|
||||
$("#mainText").innerText(xhr.responseText);
|
||||
};
|
||||
xhr.send(null);
|
||||
}
|
||||
};
|
||||
img.onload = function() {
|
||||
var h = img.height,
|
||||
w = img.width,
|
||||
sw = w,
|
||||
sh = h;
|
||||
settings.rotateTimes = (4 + settings.rotateTimes) % 4;
|
||||
x.save();
|
||||
if (settings.rotateTimes % 2 === 1) {
|
||||
sh = w;
|
||||
sw = h;
|
||||
}
|
||||
canvas.height = sh;
|
||||
canvas.width = sw;
|
||||
x.translate(sw / 2, sh / 2);
|
||||
x.rotate(Math.PI / 2 * settings.rotateTimes);
|
||||
x.translate(-w / 2, -h / 2);
|
||||
if (settings.vflip) {
|
||||
x.scale(1, -1);
|
||||
x.translate(0, -h);
|
||||
}
|
||||
if (settings.hflip) {
|
||||
x.scale(-1, 1);
|
||||
x.translate(-w, 0);
|
||||
}
|
||||
canvas.style.display = "none";
|
||||
scrollTo(0, 0);
|
||||
x.drawImage(img, 0, 0);
|
||||
};
|
||||
img.onload = function() {
|
||||
var h = img.height,
|
||||
w = img.width,
|
||||
sw = w,
|
||||
sh = h;
|
||||
settings.rotateTimes = (4 + settings.rotateTimes) % 4;
|
||||
x.save();
|
||||
if (settings.rotateTimes % 2 === 1) {
|
||||
sh = w;
|
||||
sw = h;
|
||||
}
|
||||
canvas.height = sh;
|
||||
canvas.width = sw;
|
||||
x.translate(sw / 2, sh / 2);
|
||||
x.rotate(Math.PI / 2 * settings.rotateTimes);
|
||||
x.translate(-w / 2, -h / 2);
|
||||
if (settings.vflip) {
|
||||
x.scale(1, -1);
|
||||
x.translate(0, -h);
|
||||
}
|
||||
if (settings.hflip) {
|
||||
x.scale(-1, 1);
|
||||
x.translate(-w, 0);
|
||||
}
|
||||
canvas.style.display = "none";
|
||||
scrollTo(0, 0);
|
||||
x.drawImage(img, 0, 0);
|
||||
|
||||
updateScale();
|
||||
updateScale();
|
||||
|
||||
canvas.style.display = "";
|
||||
$("body").css("overflowY", "");
|
||||
x.restore();
|
||||
};
|
||||
img.src = url;
|
||||
canvas.style.display = "";
|
||||
$("body").css("overflowY", "");
|
||||
x.restore();
|
||||
};
|
||||
img.src = url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -528,19 +539,26 @@ function keyHandler(evt) {
|
||||
|
||||
function ImageLoadCallback(event) {
|
||||
var jso=this.response;
|
||||
if (jso.page !== jso.last)
|
||||
{
|
||||
// var secRequest = new XMLHttpRequest();
|
||||
this.open("GET", this.fileid + "/"+(jso.page+1));
|
||||
this.addEventListener("load",ImageLoadCallback);
|
||||
this.send();
|
||||
// Unable to decompress file, or no response from server
|
||||
if (jso === null){
|
||||
setImage("error");
|
||||
}
|
||||
else
|
||||
{
|
||||
var diff = ((new Date).getTime() - start)/1000;
|
||||
console.log('Transfer done in ' + diff + 's');
|
||||
if (jso.page !== jso.last)
|
||||
{
|
||||
// var secRequest = new XMLHttpRequest();
|
||||
this.open("GET", this.fileid + "/"+(jso.page+1));
|
||||
this.addEventListener("load",ImageLoadCallback);
|
||||
this.send();
|
||||
}
|
||||
else
|
||||
{
|
||||
var diff = ((new Date).getTime() - start)/1000;
|
||||
console.log('Transfer done in ' + diff + 's');
|
||||
}
|
||||
loadFromArrayBuffer(jso);
|
||||
}
|
||||
loadFromArrayBuffer(jso);
|
||||
}
|
||||
function init(fileid) {
|
||||
start = (new Date).getTime();
|
||||
|
@ -42,6 +42,10 @@
|
||||
<th>Kindlegen</th>
|
||||
<td>{{versions['KindlegenVersion']}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Unrar</th>
|
||||
<td>{{versions['unrarVersion']}}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>ImageMagick</th>
|
||||
<td>{{versions['ImageVersion']}}</td>
|
||||
|
23
cps/web.py
23
cps/web.py
@ -934,10 +934,11 @@ def get_comic_book(book_id, book_format, page):
|
||||
extractedfile="data:image/png;base64," + (rf.read(rarNames[page])).encode('base64')
|
||||
fileData={"name": rarNames[page],"page":page, "last":rarNames.__len__()-1, "content": extractedfile}
|
||||
except:
|
||||
return ""
|
||||
# rarfile not valid
|
||||
# ToDo: error handling
|
||||
app.logger.error('Unrar binary not found unable to decompress file ' + cbr_file)
|
||||
return ""
|
||||
else:
|
||||
app.logger.info('Unrar is not supported please install python rarfile extension')
|
||||
# no support means return nothing
|
||||
return ""
|
||||
if book_format == "cbz":
|
||||
@ -1507,7 +1508,13 @@ def stats():
|
||||
versions['requests'] = requests.__version__
|
||||
versions['pysqlite'] = db.engine.dialect.dbapi.version
|
||||
versions['sqlite'] = db.engine.dialect.dbapi.sqlite_version
|
||||
|
||||
if rar_support:
|
||||
rarVersion = helper.check_unrar(config.config_rarfile_location)
|
||||
if not rarVersion[0]:
|
||||
versions['unrarVersion'] = rarVersion[1]
|
||||
else:
|
||||
versions['unrarVersion'] = _('not installed')
|
||||
app.logger.info(rarVersion[1])
|
||||
return render_title_template('stats.html', bookcounter=counter, authorcounter=authors, versions=versions,
|
||||
categorycounter=categorys, seriecounter=series, title=_(u"Statistics"))
|
||||
|
||||
@ -2535,8 +2542,14 @@ def configuration_helper(origin):
|
||||
# Rarfile Content configuration
|
||||
# ToDo check: location valid
|
||||
if "config_rarfile_location" in to_save:
|
||||
content.config_rarfile_location = to_save["config_rarfile_location"].strip()
|
||||
|
||||
check = helper.check_unrar(to_save["config_rarfile_location"].strip())
|
||||
if not check[0] :
|
||||
content.config_rarfile_location = to_save["config_rarfile_location"].strip()
|
||||
else:
|
||||
flash(check[1], category="error")
|
||||
return render_title_template("config_edit.html", content=config, origin=origin, gdrive=gdrive_support,
|
||||
goodreads=goodreads_support, rarfile_support=rar_support,
|
||||
title=_(u"Basic Configuration"))
|
||||
|
||||
content.config_default_role = 0
|
||||
if "admin_role" in to_save:
|
||||
|
Loading…
Reference in New Issue
Block a user