1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-24 18:47:23 +00:00
This commit is contained in:
Ozzieisaacs 2019-03-05 21:28:55 +01:00
parent 466af21548
commit 6f0b3bbda0
4 changed files with 67 additions and 32 deletions

View File

@ -24,21 +24,34 @@ import uploader
def extractCover(tmp_file_name, original_file_extension): def extractCover(tmp_file_name, original_file_extension):
cover_data = None
if original_file_extension.upper() == '.CBZ': if original_file_extension.upper() == '.CBZ':
cf = zipfile.ZipFile(tmp_file_name) cf = zipfile.ZipFile(tmp_file_name)
compressed_name = cf.namelist()[0] for name in cf.namelist():
cover_data = cf.read(compressed_name) ext = os.path.splitext(name)
if len(ext) > 1:
extension = ext[1].lower()
if extension == '.jpg':
cover_data = cf.read(name)
break
elif original_file_extension.upper() == '.CBT': elif original_file_extension.upper() == '.CBT':
cf = tarfile.TarFile(tmp_file_name) cf = tarfile.TarFile(tmp_file_name)
compressed_name = cf.getnames()[0] for name in cf.getnames():
cover_data = cf.extractfile(compressed_name).read() ext = os.path.splitext(name)
if len(ext) > 1:
extension = ext[1].lower()
if extension == '.jpg':
cover_data = cf.extractfile(name).read()
break
prefix = os.path.dirname(tmp_file_name) prefix = os.path.dirname(tmp_file_name)
if cover_data:
tmp_cover_name = prefix + '/cover' + os.path.splitext(compressed_name)[1] tmp_cover_name = prefix + '/cover' + extension
image = open(tmp_cover_name, 'wb') image = open(tmp_cover_name, 'wb')
image.write(cover_data) image.write(cover_data)
image.close() image.close()
else:
tmp_cover_name = None
return tmp_cover_name return tmp_cover_name

View File

@ -99,7 +99,8 @@ kthoom.setSettings = function() {
}; };
var createURLFromArray = function(array, mimeType) { var createURLFromArray = function(array, mimeType) {
var offset = array.byteOffset, len = array.byteLength; var offset = array.byteOffset;
var len = array.byteLength;
var url; var url;
var blob; var blob;
@ -137,11 +138,13 @@ var createURLFromArray = function(array, mimeType) {
kthoom.ImageFile = function(file) { kthoom.ImageFile = function(file) {
this.filename = file.filename; this.filename = file.filename;
var fileExtension = file.filename.split(".").pop().toLowerCase(); var fileExtension = file.filename.split(".").pop().toLowerCase();
var mimeType = fileExtension === "png" ? "image/png" : this.mimeType = fileExtension === "png" ? "image/png" :
(fileExtension === "jpg" || fileExtension === "jpeg") ? "image/jpeg" : (fileExtension === "jpg" || fileExtension === "jpeg") ? "image/jpeg" :
fileExtension === "gif" ? "image/gif" : fileExtension == 'svg' ? 'image/xml+svg' : undefined; fileExtension === "gif" ? "image/gif" : fileExtension == 'svg' ? 'image/xml+svg' : undefined;
this.dataURI = createURLFromArray(file.fileData, mimeType); if ( this.mimeType !== undefined) {
this.dataURI = createURLFromArray(file.fileData, this.mimeType);
this.data = file; this.data = file;
}
}; };
@ -169,7 +172,9 @@ function loadFromArrayBuffer(ab) {
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS, unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.PROGRESS,
function(e) { function(e) {
var percentage = e.currentBytesUnarchived / e.totalUncompressedBytesInArchive; var percentage = e.currentBytesUnarchived / e.totalUncompressedBytesInArchive;
if (totalImages === 0) {
totalImages = e.totalFilesInArchive; totalImages = e.totalFilesInArchive;
}
updateProgress(percentage *100); updateProgress(percentage *100);
lastCompletion = percentage * 100; lastCompletion = percentage * 100;
}); });
@ -180,8 +185,10 @@ function loadFromArrayBuffer(ab) {
var f = e.unarchivedFile; var f = e.unarchivedFile;
// add any new pages based on the filename // add any new pages based on the filename
if (imageFilenames.indexOf(f.filename) === -1) { if (imageFilenames.indexOf(f.filename) === -1) {
var test = new kthoom.ImageFile(f);
if ( test.mimeType !== undefined) {
imageFilenames.push(f.filename); imageFilenames.push(f.filename);
imageFiles.push(new kthoom.ImageFile(f)); imageFiles.push(test);
// add thumbnails to the TOC list // add thumbnails to the TOC list
$("#thumbnails").append( $("#thumbnails").append(
"<li>" + "<li>" +
@ -191,12 +198,16 @@ function loadFromArrayBuffer(ab) {
"</a>" + "</a>" +
"</li>" "</li>"
); );
}
}
// display first page if we haven't yet // display first page if we haven't yet
if (imageFiles.length === currentImage + 1) { if (imageFiles.length === currentImage + 1) {
updatePage(lastCompletion); updatePage(lastCompletion);
} }
}
else {
totalImages--;
}
}
}
}); });
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.FINISH, unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.FINISH,
function() { function() {

View File

@ -113,6 +113,7 @@ ZipLocalFile.prototype.unzip = function() {
info("ZIP v" + this.version + ", store only: " + this.filename + " (" + this.compressedSize + " bytes)"); info("ZIP v" + this.version + ", store only: " + this.filename + " (" + this.compressedSize + " bytes)");
currentBytesUnarchivedInFile = this.compressedSize; currentBytesUnarchivedInFile = this.compressedSize;
currentBytesUnarchived += this.compressedSize; currentBytesUnarchived += this.compressedSize;
this.fileData = zeroCompression(this.fileData, this.uncompressedSize);
} }
// version == 20, compression method == 8 (DEFLATE) // version == 20, compression method == 8 (DEFLATE)
else if (this.compressionMethod == 8) { else if (this.compressionMethod == 8) {
@ -493,6 +494,16 @@ function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) {
return blockSize; return blockSize;
} }
function zeroCompression(compressedData, numDecompressedBytes) {
var bstream = new bitjs.io.BitStream(compressedData.buffer,
false /* rtl */,
compressedData.byteOffset,
compressedData.byteLength);
var buffer = new bitjs.io.ByteBuffer(numDecompressedBytes);
buffer.insertBytes(bstream.readBytes(numDecompressedBytes));
return buffer.data;
}
// {Uint8Array} compressedData A Uint8Array of the compressed file data. // {Uint8Array} compressedData A Uint8Array of the compressed file data.
// compression method 8 // compression method 8
// deflate: http://tools.ietf.org/html/rfc1951 // deflate: http://tools.ietf.org/html/rfc1951

View File

@ -170,7 +170,7 @@
replaceForm: function(html) { replaceForm: function(html) {
var newForm; var newForm;
var formId = this.$form.attr("id"); var formId = this.$form.attr("id");
if ( typeof(formId) !== "undefined") { if ( typeof formId !== "undefined") {
newForm = $(html).find("#" + formId); newForm = $(html).find("#" + formId);
} else { } else {
newForm = $(html).find("form"); newForm = $(html).find("form");