1
0
mirror of https://github.com/janeczku/calibre-web synced 2025-11-01 15:53:01 +00:00

Changed backend for comic reader, now supports rar5

This commit is contained in:
Ozzie Isaacs
2021-05-16 08:35:20 +02:00
parent d95838309e
commit 3e5c944365
16 changed files with 10137 additions and 5543 deletions

View File

@@ -102,9 +102,8 @@ kthoom.setSettings = function() {
};
var createURLFromArray = function(array, mimeType) {
var offset = array.byteOffset;
var offset = 0; // array.byteOffset;
var len = array.byteLength;
// var url;
var blob;
if (mimeType === "image/xml+svg") {
@@ -164,11 +163,9 @@ kthoom.ImageFile = function(file) {
}
if ( this.mimeType !== undefined) {
this.dataURI = createURLFromArray(file.fileData, this.mimeType);
this.data = file;
}
};
function initProgressClick() {
$("#progress").click(function(e) {
var offset = $(this).offset();
@@ -185,72 +182,46 @@ function loadFromArrayBuffer(ab) {
var h = new Uint8Array(ab, 0, 10);
var pathToBitJS = "../../static/js/archive/";
var lastCompletion = 0;
if (h[0] === 0x52 && h[1] === 0x61 && h[2] === 0x72 && h[3] === 0x21) { //Rar!
unarchiver = new bitjs.archive.Unrarrer(ab, pathToBitJS);
} else if (h[0] === 80 && h[1] === 75) { //PK (Zip)
unarchiver = new bitjs.archive.Unzipper(ab, pathToBitJS);
} else if (h[0] === 255 && h[1] === 216) { // JPEG
// ToDo: check
updateProgress(100);
lastCompletion = 100;
return;
} else { // Try with tar
unarchiver = new bitjs.archive.Untarrer(ab, pathToBitJS);
}
// Listen for UnarchiveEvents.
if (unarchiver) {
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS,
function(e) {
var percentage = e.currentBytesUnarchived / e.totalUncompressedBytesInArchive;
if (totalImages === 0) {
totalImages = e.totalFilesInArchive;
}
updateProgress(percentage * 100);
lastCompletion = percentage * 100;
});
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.INFO,
function(e) {
// console.log(e.msg); // Enable debug output here
});
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.EXTRACT,
function(e) {
// convert DecompressedFile into a bunch of ImageFiles
if (e.unarchivedFile) {
var f = e.unarchivedFile;
// add any new pages based on the filename
if (imageFilenames.indexOf(f.filename) === -1) {
var test = new kthoom.ImageFile(f);
if ( test.mimeType !== undefined) {
imageFilenames.push(f.filename);
imageFiles.push(test);
// add thumbnails to the TOC list
$("#thumbnails").append(
"<li>" +
"<a data-page='" + imageFiles.length + "'>" +
loadArchiveFormats(['rar', 'zip', 'tar'], function() {
// Open the file as an archive
archiveOpenFile(ab, function (archive, err) {
if (archive) {
totalImages = archive.entries.length
console.info('Uncompressing ' + archive.archive_type + ' ...');
archive.entries.forEach(function(e, i) {
updateProgress( (i + 1)/ totalImages * 100);
if (e.is_file) {
var f = e.readData(function(d) {
// add any new pages based on the filename
if (imageFilenames.indexOf(e.name) === -1) {
let data = {filename: e.name, fileData: d};
var test = new kthoom.ImageFile(data);
if (test.mimeType !== undefined) {
imageFilenames.push(e.name);
imageFiles.push(test);
// 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>"
);
// display first page if we haven't yet
if (imageFiles.length === currentImage + 1) {
updatePage(lastCompletion);
"</a>" +
"</li>"
);
// display first page if we haven't yet
if (imageFiles.length === currentImage + 1) {
updatePage(lastCompletion);
}
} else {
totalImages--;
}
}
} else {
totalImages--;
}
});
}
}
});
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.FINISH,
function() {
var diff = ((new Date).getTime() - start) / 1000;
console.log("Unarchiving done in " + diff + "s");
});
unarchiver.start();
} else {
alert("Some error");
}
});
}
});
});
}
function scrollTocToActive() {
@@ -314,7 +285,6 @@ function updateProgress(loadPercentage) {
.find(".load").text("");
}
}
// Set page progress bar
$("#progress .bar-read").css({ width: totalImages === 0 ? 0 : Math.round((currentImage + 1) / totalImages * 100) + "%"});
}
@@ -564,26 +534,6 @@ function keyHandler(evt) {
}
}
/*function ImageLoadCallback() {
var jso = this.response;
// Unable to decompress file, or no response from server
if (jso === null) {
setImage("error");
} else {
// IE 11 sometimes sees the response as a string
if (typeof jso !== "object") {
jso = JSON.parse(jso);
}
if (jso.page !== jso.last) {
this.open("GET", this.fileid + "/" + (jso.page + 1));
this.addEventListener("load", ImageLoadCallback);
this.send();
}
loadFromArrayBuffer(jso);
}
}*/
function init(filename) {
var request = new XMLHttpRequest();
request.open("GET", filename);