Merge branch 'master' of git://github.com/janeczku/calibre-web
This commit is contained in:
commit
b4bd7507b6
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -28,5 +28,3 @@ settings.yaml
|
||||||
gdrive_credentials
|
gdrive_credentials
|
||||||
|
|
||||||
vendor
|
vendor
|
||||||
|
|
||||||
metadata.db
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
cps zexit()
|
|
|
@ -8,6 +8,8 @@
|
||||||
* Copyright(c) 2011 Google Inc.
|
* Copyright(c) 2011 Google Inc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* global bitjs */
|
||||||
|
|
||||||
var bitjs = bitjs || {};
|
var bitjs = bitjs || {};
|
||||||
bitjs.archive = bitjs.archive || {};
|
bitjs.archive = bitjs.archive || {};
|
||||||
|
|
||||||
|
@ -15,7 +17,7 @@ bitjs.archive = bitjs.archive || {};
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
// Stolen from Closure because it's the best way to do Java-like inheritance.
|
// Stolen from Closure because it's the best way to do Java-like inheritance.
|
||||||
bitjs.base = function(me, optMethodName, var_args) {
|
bitjs.base = function(me, optMethodName, varArgs) {
|
||||||
var caller = arguments.callee.caller;
|
var caller = arguments.callee.caller;
|
||||||
if (caller.superClass_) {
|
if (caller.superClass_) {
|
||||||
// This is a constructor. Call the superclass constructor.
|
// This is a constructor. Call the superclass constructor.
|
||||||
|
@ -48,10 +50,10 @@ bitjs.archive = bitjs.archive || {};
|
||||||
};
|
};
|
||||||
bitjs.inherits = function(childCtor, parentCtor) {
|
bitjs.inherits = function(childCtor, parentCtor) {
|
||||||
/** @constructor */
|
/** @constructor */
|
||||||
function tempCtor() {};
|
function TempCtor() {}
|
||||||
tempCtor.prototype = parentCtor.prototype;
|
TempCtor.prototype = parentCtor.prototype;
|
||||||
childCtor.superClass_ = parentCtor.prototype;
|
childCtor.superClass_ = parentCtor.prototype;
|
||||||
childCtor.prototype = new tempCtor();
|
childCtor.prototype = new TempCtor();
|
||||||
childCtor.prototype.constructor = childCtor;
|
childCtor.prototype.constructor = childCtor;
|
||||||
};
|
};
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
|
@ -141,12 +143,12 @@ bitjs.archive = bitjs.archive || {};
|
||||||
* Progress event.
|
* Progress event.
|
||||||
*/
|
*/
|
||||||
bitjs.archive.UnarchiveProgressEvent = function(
|
bitjs.archive.UnarchiveProgressEvent = function(
|
||||||
currentFilename,
|
currentFilename,
|
||||||
currentFileNumber,
|
currentFileNumber,
|
||||||
currentBytesUnarchivedInFile,
|
currentBytesUnarchivedInFile,
|
||||||
currentBytesUnarchived,
|
currentBytesUnarchived,
|
||||||
totalUncompressedBytesInArchive,
|
totalUncompressedBytesInArchive,
|
||||||
totalFilesInArchive)
|
totalFilesInArchive)
|
||||||
{
|
{
|
||||||
bitjs.base(this, bitjs.archive.UnarchiveEvent.Type.PROGRESS);
|
bitjs.base(this, bitjs.archive.UnarchiveEvent.Type.PROGRESS);
|
||||||
|
|
||||||
|
@ -296,7 +298,7 @@ bitjs.archive = bitjs.archive || {};
|
||||||
};
|
};
|
||||||
|
|
||||||
this.worker_.onmessage = function(e) {
|
this.worker_.onmessage = function(e) {
|
||||||
if (typeof e.data == "string") {
|
if (typeof e.data === "string") {
|
||||||
// Just log any strings the workers pump our way.
|
// Just log any strings the workers pump our way.
|
||||||
console.log(e.data);
|
console.log(e.data);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
* Copyright(c) 2011 antimatter15
|
* Copyright(c) 2011 antimatter15
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* global bitjs, Uint8Array */
|
||||||
|
|
||||||
var bitjs = bitjs || {};
|
var bitjs = bitjs || {};
|
||||||
bitjs.io = bitjs.io || {};
|
bitjs.io = bitjs.io || {};
|
||||||
|
|
||||||
|
@ -58,16 +60,16 @@ bitjs.io = bitjs.io || {};
|
||||||
* @return {number} The peeked bits, as an unsigned number.
|
* @return {number} The peeked bits, as an unsigned number.
|
||||||
*/
|
*/
|
||||||
bitjs.io.BitStream.prototype.peekBitsLtr = function(n, movePointers) {
|
bitjs.io.BitStream.prototype.peekBitsLtr = function(n, movePointers) {
|
||||||
if (n <= 0 || typeof n != typeof 1) {
|
if (n <= 0 || typeof n !== typeof 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
movePointers = movePointers || false,
|
var movePointers = movePointers || false;
|
||||||
bytePtr = this.bytePtr,
|
var bytePtr = this.bytePtr;
|
||||||
bitPtr = this.bitPtr,
|
var bitPtr = this.bitPtr;
|
||||||
result = 0,
|
var result = 0;
|
||||||
bitsIn = 0,
|
var bitsIn = 0;
|
||||||
bytes = this.bytes;
|
var bytes = this.bytes;
|
||||||
|
|
||||||
// keep going until we have no more bits left to peek at
|
// keep going until we have no more bits left to peek at
|
||||||
// TODO: Consider putting all bits from bytes we will need into a variable and then
|
// TODO: Consider putting all bits from bytes we will need into a variable and then
|
||||||
|
@ -123,11 +125,11 @@ bitjs.io = bitjs.io || {};
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var movePointers = movePointers || false,
|
var movePointers = movePointers || false;
|
||||||
bytePtr = this.bytePtr,
|
var bytePtr = this.bytePtr;
|
||||||
bitPtr = this.bitPtr,
|
var bitPtr = this.bitPtr;
|
||||||
result = 0,
|
var result = 0;
|
||||||
bytes = this.bytes;
|
var bytes = this.bytes;
|
||||||
|
|
||||||
// keep going until we have no more bits left to peek at
|
// keep going until we have no more bits left to peek at
|
||||||
// TODO: Consider putting all bits from bytes we will need into a variable and then
|
// TODO: Consider putting all bits from bytes we will need into a variable and then
|
||||||
|
@ -138,7 +140,7 @@ bitjs.io = bitjs.io || {};
|
||||||
if (bytePtr >= bytes.length) {
|
if (bytePtr >= bytes.length) {
|
||||||
throw "Error! Overflowed the bit stream! n=" + n + ", bytePtr=" + bytePtr + ", bytes.length=" +
|
throw "Error! Overflowed the bit stream! n=" + n + ", bytePtr=" + bytePtr + ", bytes.length=" +
|
||||||
bytes.length + ", bitPtr=" + bitPtr;
|
bytes.length + ", bitPtr=" + bitPtr;
|
||||||
return -1;
|
// return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var numBitsLeftInThisByte = (8 - bitPtr);
|
var numBitsLeftInThisByte = (8 - bitPtr);
|
||||||
|
@ -207,8 +209,8 @@ bitjs.io = bitjs.io || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
movePointers = movePointers || false;
|
movePointers = movePointers || false;
|
||||||
var bytePtr = this.bytePtr,
|
var bytePtr = this.bytePtr;
|
||||||
bitPtr = this.bitPtr;
|
// var bitPtr = this.bitPtr;
|
||||||
|
|
||||||
var result = this.bytes.subarray(bytePtr, bytePtr + n);
|
var result = this.bytes.subarray(bytePtr, bytePtr + n);
|
||||||
|
|
||||||
|
@ -255,7 +257,7 @@ bitjs.io = bitjs.io || {};
|
||||||
*/
|
*/
|
||||||
bitjs.io.ByteStream.prototype.peekNumber = function(n) {
|
bitjs.io.ByteStream.prototype.peekNumber = function(n) {
|
||||||
// TODO: return error if n would go past the end of the stream?
|
// TODO: return error if n would go past the end of the stream?
|
||||||
if (n <= 0 || typeof n !== typeof 1){
|
if (n <= 0 || typeof n !== typeof 1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,13 @@
|
||||||
restore: true,
|
restore: true,
|
||||||
bookmarks: calibre.bookmark ? [calibre.bookmark] : []
|
bookmarks: calibre.bookmark ? [calibre.bookmark] : []
|
||||||
});
|
});
|
||||||
reader.on("reader:bookmarked", updateBookmark.bind(reader, "add"));
|
|
||||||
reader.on("reader:unbookmarked", updateBookmark.bind(reader, "remove"));
|
if (calibre.useBookmarks) {
|
||||||
|
reader.on("reader:bookmarked", updateBookmark.bind(reader, "add"));
|
||||||
|
reader.on("reader:unbookmarked", updateBookmark.bind(reader, "remove"));
|
||||||
|
} else {
|
||||||
|
$("#bookmark, #show-Bookmarks").remove();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} action - Add or remove bookmark
|
* @param {string} action - Add or remove bookmark
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*
|
*
|
||||||
* http://kthoom.googlecode.com/hg/docs/unrar.html
|
* http://kthoom.googlecode.com/hg/docs/unrar.html
|
||||||
*/
|
*/
|
||||||
/* global bitjs */
|
/* global bitjs, importScripts */
|
||||||
|
|
||||||
// This file expects to be invoked as a Worker (see onmessage below).
|
// This file expects to be invoked as a Worker (see onmessage below).
|
||||||
importScripts("io.js");
|
importScripts("io.js");
|
||||||
|
@ -42,23 +42,23 @@ var postProgress = function() {
|
||||||
// shows a byte value as its hex representation
|
// shows a byte value as its hex representation
|
||||||
var nibble = "0123456789ABCDEF";
|
var nibble = "0123456789ABCDEF";
|
||||||
var byteValueToHexString = function(num) {
|
var byteValueToHexString = function(num) {
|
||||||
return nibble[num>>4] + nibble[num&0xF];
|
return nibble[num>>4] + nibble[num & 0xF];
|
||||||
};
|
};
|
||||||
var twoByteValueToHexString = function(num) {
|
var twoByteValueToHexString = function(num) {
|
||||||
return nibble[(num>>12)&0xF] + nibble[(num>>8)&0xF] + nibble[(num>>4)&0xF] + nibble[num&0xF];
|
return nibble[(num>>12) & 0xF] + nibble[(num>>8) & 0xF] + nibble[(num>>4) & 0xF] + nibble[num & 0xF];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Volume Types
|
// Volume Types
|
||||||
var MARK_HEAD = 0x72,
|
// MARK_HEAD = 0x72;
|
||||||
MAIN_HEAD = 0x73,
|
var MAIN_HEAD = 0x73,
|
||||||
FILE_HEAD = 0x74,
|
FILE_HEAD = 0x74,
|
||||||
COMM_HEAD = 0x75,
|
// COMM_HEAD = 0x75,
|
||||||
AV_HEAD = 0x76,
|
// AV_HEAD = 0x76,
|
||||||
SUB_HEAD = 0x77,
|
// SUB_HEAD = 0x77,
|
||||||
PROTECT_HEAD = 0x78,
|
// PROTECT_HEAD = 0x78,
|
||||||
SIGN_HEAD = 0x79,
|
// SIGN_HEAD = 0x79,
|
||||||
NEWSUB_HEAD = 0x7a,
|
// NEWSUB_HEAD = 0x7a,
|
||||||
ENDARC_HEAD = 0x7b;
|
ENDARC_HEAD = 0x7b;
|
||||||
|
|
||||||
// bstream is a bit stream
|
// bstream is a bit stream
|
||||||
|
@ -66,7 +66,7 @@ var RarVolumeHeader = function(bstream) {
|
||||||
|
|
||||||
var headPos = bstream.bytePtr;
|
var headPos = bstream.bytePtr;
|
||||||
// byte 1,2
|
// byte 1,2
|
||||||
info("Rar Volume Header @"+bstream.bytePtr);
|
info("Rar Volume Header @" + bstream.bytePtr);
|
||||||
|
|
||||||
this.crc = bstream.readBits(16);
|
this.crc = bstream.readBits(16);
|
||||||
info(" crc=" + this.crc);
|
info(" crc=" + this.crc);
|
||||||
|
@ -147,7 +147,7 @@ var RarVolumeHeader = function(bstream) {
|
||||||
this.HighPackSize = 0;
|
this.HighPackSize = 0;
|
||||||
this.HighUnpSize = 0;
|
this.HighUnpSize = 0;
|
||||||
if (this.unpackedSize == 0xffffffff) {
|
if (this.unpackedSize == 0xffffffff) {
|
||||||
this.HighUnpSize = 0x7fffffff
|
this.HighUnpSize = 0x7fffffff;
|
||||||
this.unpackedSize = 0xffffffff;
|
this.unpackedSize = 0xffffffff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ var RarVolumeHeader = function(bstream) {
|
||||||
// read in filename
|
// read in filename
|
||||||
|
|
||||||
this.filename = bstream.readBytes(this.nameSize);
|
this.filename = bstream.readBytes(this.nameSize);
|
||||||
for (var _i = 0, _s = ''; _i < this.filename.length; _i++) {
|
for (var _i = 0, _s = ""; _i < this.filename.length ; _i++) {
|
||||||
_s += String.fromCharCode(this.filename[_i]);
|
_s += String.fromCharCode(this.filename[_i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,14 +177,16 @@ var RarVolumeHeader = function(bstream) {
|
||||||
|
|
||||||
// this is adapted straight out of arcread.cpp, Archive::ReadHeader()
|
// this is adapted straight out of arcread.cpp, Archive::ReadHeader()
|
||||||
for (var I = 0; I < 4; ++I) {
|
for (var I = 0; I < 4; ++I) {
|
||||||
var rmode = extTimeFlags >> ((3-I)*4);
|
var rmode = extTimeFlags >> ((3 - I) * 4);
|
||||||
if ((rmode & 8)==0)
|
if ((rmode & 8)==0)
|
||||||
continue;
|
continue;
|
||||||
if (I!=0)
|
if (I!=0) {
|
||||||
bstream.readBits(16);
|
bstream.readBits(16);
|
||||||
var count = (rmode&3);
|
}
|
||||||
for (var J = 0; J < count; ++J)
|
var count = (rmode & 3);
|
||||||
bstream.readBits(8);
|
for (var J = 0; J < count; ++J) {
|
||||||
|
bstream.readBits(8);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +195,7 @@ var RarVolumeHeader = function(bstream) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
while(headPos + this.headSize > bstream.bytePtr) bstream.readBits(1);
|
while (headPos + this.headSize > bstream.bytePtr) bstream.readBits(1);
|
||||||
|
|
||||||
info("Found FILE_HEAD with packSize=" + this.packSize + ", unpackedSize= " + this.unpackedSize + ", hostOS=" + this.hostOS + ", unpVer=" + this.unpVer + ", method=" + this.method + ", filename=" + this.filename);
|
info("Found FILE_HEAD with packSize=" + this.packSize + ", unpackedSize= " + this.unpackedSize + ", hostOS=" + this.hostOS + ", unpVer=" + this.unpVer + ", method=" + this.method + ", filename=" + this.filename);
|
||||||
|
|
||||||
|
@ -206,24 +208,24 @@ var RarVolumeHeader = function(bstream) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var BLOCK_LZ = 0,
|
var BLOCK_LZ = 0;
|
||||||
BLOCK_PPM = 1;
|
// BLOCK_PPM = 1;
|
||||||
|
|
||||||
var rLDecode = [0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224],
|
var rLDecode = [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224],
|
||||||
rLBits = [0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],
|
rLBits = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5],
|
||||||
rDBitLengthCounts = [4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,14,0,12],
|
rDBitLengthCounts = [4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 14, 0, 12],
|
||||||
rSDDecode = [0,4,8,16,32,64,128,192],
|
rSDDecode = [0, 4, 8, 16, 32, 64, 128, 192],
|
||||||
rSDBits = [2,2,3, 4, 5, 6, 6, 6];
|
rSDBits = [2,2,3, 4, 5, 6, 6, 6];
|
||||||
|
|
||||||
var rDDecode = [0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32,
|
var rDDecode = [0, 1, 2, 3, 4, 6, 8, 12, 16, 24, 32,
|
||||||
48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072,
|
48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048, 3072,
|
||||||
4096, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536, 98304,
|
4096, 6144, 8192, 12288, 16384, 24576, 32768, 49152, 65536, 98304,
|
||||||
131072, 196608, 262144, 327680, 393216, 458752, 524288, 589824,
|
131072, 196608, 262144, 327680, 393216, 458752, 524288, 589824,
|
||||||
655360, 720896, 786432, 851968, 917504, 983040];
|
655360, 720896, 786432, 851968, 917504, 983040];
|
||||||
|
|
||||||
var rDBits = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5,
|
var rDBits = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5,
|
||||||
5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14,
|
5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14,
|
||||||
15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16];
|
15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16];
|
||||||
|
|
||||||
var rLOW_DIST_REP_COUNT = 16;
|
var rLOW_DIST_REP_COUNT = 16;
|
||||||
|
|
||||||
|
@ -232,35 +234,35 @@ var rNC = 299,
|
||||||
rLDC = 17,
|
rLDC = 17,
|
||||||
rRC = 28,
|
rRC = 28,
|
||||||
rBC = 20,
|
rBC = 20,
|
||||||
rHUFF_TABLE_SIZE = (rNC+rDC+rRC+rLDC);
|
rHUFF_TABLE_SIZE = (rNC + rDC + rRC + rLDC);
|
||||||
|
|
||||||
var UnpBlockType = BLOCK_LZ;
|
var UnpBlockType = BLOCK_LZ;
|
||||||
var UnpOldTable = new Array(rHUFF_TABLE_SIZE);
|
var UnpOldTable = new Array(rHUFF_TABLE_SIZE);
|
||||||
|
|
||||||
var BD = { //bitdecode
|
var BD = { //bitdecode
|
||||||
DecodeLen: new Array(16),
|
DecodeLen: new Array(16),
|
||||||
DecodePos: new Array(16),
|
DecodePos: new Array(16),
|
||||||
DecodeNum: new Array(rBC)
|
DecodeNum: new Array(rBC)
|
||||||
};
|
};
|
||||||
var LD = { //litdecode
|
var LD = { //litdecode
|
||||||
DecodeLen: new Array(16),
|
DecodeLen: new Array(16),
|
||||||
DecodePos: new Array(16),
|
DecodePos: new Array(16),
|
||||||
DecodeNum: new Array(rNC)
|
DecodeNum: new Array(rNC)
|
||||||
};
|
};
|
||||||
var DD = { //distdecode
|
var DD = { //distdecode
|
||||||
DecodeLen: new Array(16),
|
DecodeLen: new Array(16),
|
||||||
DecodePos: new Array(16),
|
DecodePos: new Array(16),
|
||||||
DecodeNum: new Array(rDC)
|
DecodeNum: new Array(rDC)
|
||||||
};
|
};
|
||||||
var LDD = { //low dist decode
|
var LDD = { //low dist decode
|
||||||
DecodeLen: new Array(16),
|
DecodeLen: new Array(16),
|
||||||
DecodePos: new Array(16),
|
DecodePos: new Array(16),
|
||||||
DecodeNum: new Array(rLDC)
|
DecodeNum: new Array(rLDC)
|
||||||
};
|
};
|
||||||
var RD = { //rep decode
|
var RD = { //rep decode
|
||||||
DecodeLen: new Array(16),
|
DecodeLen: new Array(16),
|
||||||
DecodePos: new Array(16),
|
DecodePos: new Array(16),
|
||||||
DecodeNum: new Array(rRC)
|
DecodeNum: new Array(rRC)
|
||||||
};
|
};
|
||||||
|
|
||||||
var rBuffer;
|
var rBuffer;
|
||||||
|
@ -742,7 +744,7 @@ function unpack(v) {
|
||||||
|
|
||||||
rBuffer = new bitjs.io.ByteBuffer(v.header.unpackedSize);
|
rBuffer = new bitjs.io.ByteBuffer(v.header.unpackedSize);
|
||||||
|
|
||||||
info("Unpacking "+v.filename+" RAR v"+Ver);
|
info("Unpacking " + v.filename+" RAR v" + Ver);
|
||||||
|
|
||||||
switch(Ver) {
|
switch(Ver) {
|
||||||
case 15: // rar 1.5 compression
|
case 15: // rar 1.5 compression
|
||||||
|
@ -816,7 +818,7 @@ var unrar = function(arrayBuffer) {
|
||||||
|
|
||||||
postMessage(new bitjs.archive.UnarchiveStartEvent());
|
postMessage(new bitjs.archive.UnarchiveStartEvent());
|
||||||
var bstream = new bitjs.io.BitStream(arrayBuffer, false /* rtl */);
|
var bstream = new bitjs.io.BitStream(arrayBuffer, false /* rtl */);
|
||||||
|
|
||||||
var header = new RarVolumeHeader(bstream);
|
var header = new RarVolumeHeader(bstream);
|
||||||
if (header.crc == 0x6152 &&
|
if (header.crc == 0x6152 &&
|
||||||
header.headType == 0x72 &&
|
header.headType == 0x72 &&
|
||||||
|
|
|
@ -7,11 +7,10 @@
|
||||||
*
|
*
|
||||||
* TAR format: http://www.gnu.org/software/automake/manual/tar/Standard.html
|
* TAR format: http://www.gnu.org/software/automake/manual/tar/Standard.html
|
||||||
*/
|
*/
|
||||||
/* global bitjs */
|
|
||||||
|
|
||||||
// This file expects to be invoked as a Worker (see onmessage below).
|
// This file expects to be invoked as a Worker (see onmessage below).
|
||||||
importScripts("io.js");
|
importScripts('io.js');
|
||||||
importScripts("archive.js");
|
importScripts('archive.js');
|
||||||
|
|
||||||
// Progress variables.
|
// Progress variables.
|
||||||
var currentFilename = "";
|
var currentFilename = "";
|
||||||
|
@ -23,147 +22,147 @@ var totalFilesInArchive = 0;
|
||||||
|
|
||||||
// Helper functions.
|
// Helper functions.
|
||||||
var info = function(str) {
|
var info = function(str) {
|
||||||
postMessage(new bitjs.archive.UnarchiveInfoEvent(str));
|
postMessage(new bitjs.archive.UnarchiveInfoEvent(str));
|
||||||
};
|
};
|
||||||
var err = function(str) {
|
var err = function(str) {
|
||||||
postMessage(new bitjs.archive.UnarchiveErrorEvent(str));
|
postMessage(new bitjs.archive.UnarchiveErrorEvent(str));
|
||||||
};
|
};
|
||||||
var postProgress = function() {
|
var postProgress = function() {
|
||||||
postMessage(new bitjs.archive.UnarchiveProgressEvent(
|
postMessage(new bitjs.archive.UnarchiveProgressEvent(
|
||||||
currentFilename,
|
currentFilename,
|
||||||
currentFileNumber,
|
currentFileNumber,
|
||||||
currentBytesUnarchivedInFile,
|
currentBytesUnarchivedInFile,
|
||||||
currentBytesUnarchived,
|
currentBytesUnarchived,
|
||||||
totalUncompressedBytesInArchive,
|
totalUncompressedBytesInArchive,
|
||||||
totalFilesInArchive));
|
totalFilesInArchive));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Removes all characters from the first zero-byte in the string onwards.
|
// Removes all characters from the first zero-byte in the string onwards.
|
||||||
var readCleanString = function(bstr, numBytes) {
|
var readCleanString = function(bstr, numBytes) {
|
||||||
var str = bstr.readString(numBytes);
|
var str = bstr.readString(numBytes);
|
||||||
var zIndex = str.indexOf(String.fromCharCode(0));
|
var zIndex = str.indexOf(String.fromCharCode(0));
|
||||||
return zIndex !== -1 ? str.substr(0, zIndex) : str;
|
return zIndex != -1 ? str.substr(0, zIndex) : str;
|
||||||
};
|
};
|
||||||
|
|
||||||
// takes a ByteStream and parses out the local file information
|
// takes a ByteStream and parses out the local file information
|
||||||
var TarLocalFile = function(bstream) {
|
var TarLocalFile = function(bstream) {
|
||||||
this.isValid = false;
|
this.isValid = false;
|
||||||
|
|
||||||
// Read in the header block
|
// Read in the header block
|
||||||
this.name = readCleanString(bstream, 100);
|
this.name = readCleanString(bstream, 100);
|
||||||
this.mode = readCleanString(bstream, 8);
|
this.mode = readCleanString(bstream, 8);
|
||||||
this.uid = readCleanString(bstream, 8);
|
this.uid = readCleanString(bstream, 8);
|
||||||
this.gid = readCleanString(bstream, 8);
|
this.gid = readCleanString(bstream, 8);
|
||||||
this.size = parseInt(readCleanString(bstream, 12), 8);
|
this.size = parseInt(readCleanString(bstream, 12), 8);
|
||||||
this.mtime = readCleanString(bstream, 12);
|
this.mtime = readCleanString(bstream, 12);
|
||||||
this.chksum = readCleanString(bstream, 8);
|
this.chksum = readCleanString(bstream, 8);
|
||||||
this.typeflag = readCleanString(bstream, 1);
|
this.typeflag = readCleanString(bstream, 1);
|
||||||
this.linkname = readCleanString(bstream, 100);
|
this.linkname = readCleanString(bstream, 100);
|
||||||
this.maybeMagic = readCleanString(bstream, 6);
|
this.maybeMagic = readCleanString(bstream, 6);
|
||||||
|
|
||||||
if (this.maybeMagic === "ustar") {
|
if (this.maybeMagic == "ustar") {
|
||||||
this.version = readCleanString(bstream, 2);
|
this.version = readCleanString(bstream, 2);
|
||||||
this.uname = readCleanString(bstream, 32);
|
this.uname = readCleanString(bstream, 32);
|
||||||
this.gname = readCleanString(bstream, 32);
|
this.gname = readCleanString(bstream, 32);
|
||||||
this.devmajor = readCleanString(bstream, 8);
|
this.devmajor = readCleanString(bstream, 8);
|
||||||
this.devminor = readCleanString(bstream, 8);
|
this.devminor = readCleanString(bstream, 8);
|
||||||
this.prefix = readCleanString(bstream, 155);
|
this.prefix = readCleanString(bstream, 155);
|
||||||
|
|
||||||
if (this.prefix.length) {
|
if (this.prefix.length) {
|
||||||
this.name = this.prefix + this.name;
|
this.name = this.prefix + this.name;
|
||||||
}
|
}
|
||||||
bstream.readBytes(12); // 512 - 500
|
bstream.readBytes(12); // 512 - 500
|
||||||
} else {
|
} else {
|
||||||
bstream.readBytes(255); // 512 - 257
|
bstream.readBytes(255); // 512 - 257
|
||||||
}
|
}
|
||||||
|
|
||||||
// Done header, now rest of blocks are the file contents.
|
// Done header, now rest of blocks are the file contents.
|
||||||
this.filename = this.name;
|
this.filename = this.name;
|
||||||
this.fileData = null;
|
this.fileData = null;
|
||||||
|
|
||||||
info("Untarring file '" + this.filename + "'");
|
info("Untarring file '" + this.filename + "'");
|
||||||
info(" size = " + this.size);
|
info(" size = " + this.size);
|
||||||
info(" typeflag = " + this.typeflag);
|
info(" typeflag = " + this.typeflag);
|
||||||
|
|
||||||
// A regular file.
|
// A regular file.
|
||||||
if (this.typeflag === 0) {
|
if (this.typeflag == 0) {
|
||||||
info(" This is a regular file.");
|
info(" This is a regular file.");
|
||||||
var sizeInBytes = parseInt(this.size);
|
var sizeInBytes = parseInt(this.size);
|
||||||
this.fileData = new Uint8Array(bstream.bytes.buffer, bstream.ptr, this.size);
|
this.fileData = new Uint8Array(bstream.bytes.buffer, bstream.ptr, this.size);
|
||||||
if (this.name.length > 0 && this.size > 0 && this.fileData && this.fileData.buffer) {
|
if (this.name.length > 0 && this.size > 0 && this.fileData && this.fileData.buffer) {
|
||||||
this.isValid = true;
|
this.isValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bstream.readBytes(this.size);
|
bstream.readBytes(this.size);
|
||||||
|
|
||||||
// Round up to 512-byte blocks.
|
// Round up to 512-byte blocks.
|
||||||
var remaining = 512 - this.size % 512;
|
var remaining = 512 - this.size % 512;
|
||||||
if (remaining > 0 && remaining < 512) {
|
if (remaining > 0 && remaining < 512) {
|
||||||
bstream.readBytes(remaining);
|
bstream.readBytes(remaining);
|
||||||
}
|
}
|
||||||
} else if (this.typeflag === 5) {
|
} else if (this.typeflag == 5) {
|
||||||
info(" This is a directory.");
|
info(" This is a directory.")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Takes an ArrayBuffer of a tar file in
|
// Takes an ArrayBuffer of a tar file in
|
||||||
// returns null on error
|
// returns null on error
|
||||||
// returns an array of DecompressedFile objects on success
|
// returns an array of DecompressedFile objects on success
|
||||||
var untar = function(arrayBuffer) {
|
var untar = function(arrayBuffer) {
|
||||||
currentFilename = "";
|
currentFilename = "";
|
||||||
currentFileNumber = 0;
|
currentFileNumber = 0;
|
||||||
currentBytesUnarchivedInFile = 0;
|
currentBytesUnarchivedInFile = 0;
|
||||||
currentBytesUnarchived = 0;
|
currentBytesUnarchived = 0;
|
||||||
totalUncompressedBytesInArchive = 0;
|
totalUncompressedBytesInArchive = 0;
|
||||||
totalFilesInArchive = 0;
|
totalFilesInArchive = 0;
|
||||||
|
|
||||||
postMessage(new bitjs.archive.UnarchiveStartEvent());
|
postMessage(new bitjs.archive.UnarchiveStartEvent());
|
||||||
var bstream = new bitjs.io.ByteStream(arrayBuffer);
|
var bstream = new bitjs.io.ByteStream(arrayBuffer);
|
||||||
var localFiles = [];
|
var localFiles = [];
|
||||||
|
|
||||||
// While we don't encounter an empty block, keep making TarLocalFiles.
|
// While we don't encounter an empty block, keep making TarLocalFiles.
|
||||||
while (bstream.peekNumber(4) !== 0) {
|
while (bstream.peekNumber(4) != 0) {
|
||||||
var oneLocalFile = new TarLocalFile(bstream);
|
var oneLocalFile = new TarLocalFile(bstream);
|
||||||
if (oneLocalFile && oneLocalFile.isValid) {
|
if (oneLocalFile && oneLocalFile.isValid) {
|
||||||
localFiles.push(oneLocalFile);
|
localFiles.push(oneLocalFile);
|
||||||
totalUncompressedBytesInArchive += oneLocalFile.size;
|
totalUncompressedBytesInArchive += oneLocalFile.size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
totalFilesInArchive = localFiles.length;
|
totalFilesInArchive = localFiles.length;
|
||||||
|
|
||||||
// got all local files, now sort them
|
// got all local files, now sort them
|
||||||
localFiles.sort(function(a, b) {
|
localFiles.sort(function(a,b) {
|
||||||
var aname = a.filename.toLowerCase();
|
var aname = a.filename.toLowerCase();
|
||||||
var bname = b.filename.toLowerCase();
|
var bname = b.filename.toLowerCase();
|
||||||
return aname > bname ? 1 : -1;
|
return aname > bname ? 1 : -1;
|
||||||
});
|
});
|
||||||
|
|
||||||
// report # files and total length
|
|
||||||
if (localFiles.length > 0) {
|
|
||||||
postProgress();
|
|
||||||
}
|
|
||||||
|
|
||||||
// now do the shipping of each file
|
|
||||||
for (var i = 0; i < localFiles.length; ++i) {
|
|
||||||
var localfile = localFiles[i];
|
|
||||||
info("Sending file '" + localfile.filename + "' up");
|
|
||||||
|
|
||||||
// update progress
|
|
||||||
currentFilename = localfile.filename;
|
|
||||||
currentFileNumber = i;
|
|
||||||
currentBytesUnarchivedInFile = localfile.size;
|
|
||||||
currentBytesUnarchived += localfile.size;
|
|
||||||
postMessage(new bitjs.archive.UnarchiveExtractEvent(localfile));
|
|
||||||
postProgress();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// report # files and total length
|
||||||
|
if (localFiles.length > 0) {
|
||||||
postProgress();
|
postProgress();
|
||||||
|
}
|
||||||
|
|
||||||
postMessage(new bitjs.archive.UnarchiveFinishEvent());
|
// now do the shipping of each file
|
||||||
|
for (var i = 0; i < localFiles.length; ++i) {
|
||||||
|
var localfile = localFiles[i];
|
||||||
|
info("Sending file '" + localfile.filename + "' up");
|
||||||
|
|
||||||
|
// update progress
|
||||||
|
currentFilename = localfile.filename;
|
||||||
|
currentFileNumber = i;
|
||||||
|
currentBytesUnarchivedInFile = localfile.size;
|
||||||
|
currentBytesUnarchived += localfile.size;
|
||||||
|
postMessage(new bitjs.archive.UnarchiveExtractEvent(localfile));
|
||||||
|
postProgress();
|
||||||
|
}
|
||||||
|
|
||||||
|
postProgress();
|
||||||
|
|
||||||
|
postMessage(new bitjs.archive.UnarchiveFinishEvent());
|
||||||
};
|
};
|
||||||
|
|
||||||
// event.data.file has the ArrayBuffer.
|
// event.data.file has the ArrayBuffer.
|
||||||
onmessage = function(event) {
|
onmessage = function(event) {
|
||||||
var ab = event.data.file;
|
var ab = event.data.file;
|
||||||
untar(ab);
|
untar(ab);
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
* ZIP format: http://www.pkware.com/documents/casestudies/APPNOTE.TXT
|
* ZIP format: http://www.pkware.com/documents/casestudies/APPNOTE.TXT
|
||||||
* DEFLATE format: http://tools.ietf.org/html/rfc1951
|
* DEFLATE format: http://tools.ietf.org/html/rfc1951
|
||||||
*/
|
*/
|
||||||
/* global bitjs */
|
/* global bitjs, importScripts, Uint8Array */
|
||||||
|
|
||||||
// This file expects to be invoked as a Worker (see onmessage below).
|
// This file expects to be invoked as a Worker (see onmessage below).
|
||||||
importScripts("io.js");
|
importScripts("io.js");
|
||||||
|
@ -44,12 +44,12 @@ var zLocalFileHeaderSignature = 0x04034b50;
|
||||||
var zArchiveExtraDataSignature = 0x08064b50;
|
var zArchiveExtraDataSignature = 0x08064b50;
|
||||||
var zCentralFileHeaderSignature = 0x02014b50;
|
var zCentralFileHeaderSignature = 0x02014b50;
|
||||||
var zDigitalSignatureSignature = 0x05054b50;
|
var zDigitalSignatureSignature = 0x05054b50;
|
||||||
var zEndOfCentralDirSignature = 0x06064b50;
|
//var zEndOfCentralDirSignature = 0x06064b50;
|
||||||
var zEndOfCentralDirLocatorSignature = 0x07064b50;
|
//var zEndOfCentralDirLocatorSignature = 0x07064b50;
|
||||||
|
|
||||||
// takes a ByteStream and parses out the local file information
|
// takes a ByteStream and parses out the local file information
|
||||||
var ZipLocalFile = function(bstream) {
|
var ZipLocalFile = function(bstream) {
|
||||||
if (typeof bstream != typeof {} || !bstream.readNumber || typeof bstream.readNumber != typeof function(){}) {
|
if (typeof bstream !== typeof {} || !bstream.readNumber || typeof bstream.readNumber != typeof function() {} ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ var ZipLocalFile = function(bstream) {
|
||||||
// "This descriptor exists only if bit 3 of the general purpose bit flag is set"
|
// "This descriptor exists only if bit 3 of the general purpose bit flag is set"
|
||||||
// But how do you figure out how big the file data is if you don't know the compressedSize
|
// But how do you figure out how big the file data is if you don't know the compressedSize
|
||||||
// from the header?!?
|
// from the header?!?
|
||||||
if ((this.generalPurpose & bitjs.BIT[3]) != 0) {
|
if ((this.generalPurpose & bitjs.BIT[3]) !== 0) {
|
||||||
this.crc32 = bstream.readNumber(4);
|
this.crc32 = bstream.readNumber(4);
|
||||||
this.compressedSize = bstream.readNumber(4);
|
this.compressedSize = bstream.readNumber(4);
|
||||||
this.uncompressedSize = bstream.readNumber(4);
|
this.uncompressedSize = bstream.readNumber(4);
|
||||||
|
@ -111,13 +111,13 @@ var ZipLocalFile = function(bstream) {
|
||||||
ZipLocalFile.prototype.unzip = function() {
|
ZipLocalFile.prototype.unzip = function() {
|
||||||
|
|
||||||
// Zip Version 1.0, no compression (store only)
|
// Zip Version 1.0, no compression (store only)
|
||||||
if (this.compressionMethod == 0 ) {
|
if (this.compressionMethod === 0 ) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
// version == 20, compression method == 8 (DEFLATE)
|
// version == 20, compression method == 8 (DEFLATE)
|
||||||
else if (this.compressionMethod == 8) {
|
else if (this.compressionMethod === 8) {
|
||||||
info("ZIP v2.0, DEFLATE: " + this.filename + " (" + this.compressedSize + " bytes)");
|
info("ZIP v2.0, DEFLATE: " + this.filename + " (" + this.compressedSize + " bytes)");
|
||||||
this.fileData = inflate(this.fileData, this.uncompressedSize);
|
this.fileData = inflate(this.fileData, this.uncompressedSize);
|
||||||
}
|
}
|
||||||
|
@ -144,10 +144,10 @@ var unzip = function(arrayBuffer) {
|
||||||
|
|
||||||
var bstream = new bitjs.io.ByteStream(arrayBuffer);
|
var bstream = new bitjs.io.ByteStream(arrayBuffer);
|
||||||
// detect local file header signature or return null
|
// detect local file header signature or return null
|
||||||
if (bstream.peekNumber(4) == zLocalFileHeaderSignature) {
|
if (bstream.peekNumber(4) === zLocalFileHeaderSignature) {
|
||||||
var localFiles = [];
|
var localFiles = [];
|
||||||
// loop until we don't see any more local files
|
// loop until we don't see any more local files
|
||||||
while (bstream.peekNumber(4) == zLocalFileHeaderSignature) {
|
while (bstream.peekNumber(4) === zLocalFileHeaderSignature) {
|
||||||
var oneLocalFile = new ZipLocalFile(bstream);
|
var oneLocalFile = new ZipLocalFile(bstream);
|
||||||
// this should strip out directories/folders
|
// this should strip out directories/folders
|
||||||
if (oneLocalFile && oneLocalFile.uncompressedSize > 0 && oneLocalFile.fileData) {
|
if (oneLocalFile && oneLocalFile.uncompressedSize > 0 && oneLocalFile.fileData) {
|
||||||
|
@ -158,14 +158,14 @@ var unzip = function(arrayBuffer) {
|
||||||
totalFilesInArchive = localFiles.length;
|
totalFilesInArchive = localFiles.length;
|
||||||
|
|
||||||
// got all local files, now sort them
|
// got all local files, now sort them
|
||||||
localFiles.sort(function(a,b) {
|
localFiles.sort(function(a, b) {
|
||||||
var aname = a.filename.toLowerCase();
|
var aname = a.filename.toLowerCase();
|
||||||
var bname = b.filename.toLowerCase();
|
var bname = b.filename.toLowerCase();
|
||||||
return aname > bname ? 1 : -1;
|
return aname > bname ? 1 : -1;
|
||||||
});
|
});
|
||||||
|
|
||||||
// archive extra data record
|
// archive extra data record
|
||||||
if (bstream.peekNumber(4) == zArchiveExtraDataSignature) {
|
if (bstream.peekNumber(4) === zArchiveExtraDataSignature) {
|
||||||
info(" Found an Archive Extra Data Signature");
|
info(" Found an Archive Extra Data Signature");
|
||||||
|
|
||||||
// skipping this record for now
|
// skipping this record for now
|
||||||
|
@ -176,11 +176,11 @@ var unzip = function(arrayBuffer) {
|
||||||
|
|
||||||
// central directory structure
|
// central directory structure
|
||||||
// TODO: handle the rest of the structures (Zip64 stuff)
|
// TODO: handle the rest of the structures (Zip64 stuff)
|
||||||
if (bstream.peekNumber(4) == zCentralFileHeaderSignature) {
|
if (bstream.peekNumber(4) === zCentralFileHeaderSignature) {
|
||||||
info(" Found a Central File Header");
|
info(" Found a Central File Header");
|
||||||
|
|
||||||
// read all file headers
|
// read all file headers
|
||||||
while (bstream.peekNumber(4) == zCentralFileHeaderSignature) {
|
while (bstream.peekNumber(4) === zCentralFileHeaderSignature) {
|
||||||
bstream.readNumber(4); // signature
|
bstream.readNumber(4); // signature
|
||||||
bstream.readNumber(2); // version made by
|
bstream.readNumber(2); // version made by
|
||||||
bstream.readNumber(2); // version needed to extract
|
bstream.readNumber(2); // version needed to extract
|
||||||
|
@ -206,7 +206,7 @@ var unzip = function(arrayBuffer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// digital signature
|
// digital signature
|
||||||
if (bstream.peekNumber(4) == zDigitalSignatureSignature) {
|
if (bstream.peekNumber(4) === zDigitalSignatureSignature) {
|
||||||
info(" Found a Digital Signature");
|
info(" Found a Digital Signature");
|
||||||
|
|
||||||
bstream.readNumber(4);
|
bstream.readNumber(4);
|
||||||
|
@ -231,66 +231,66 @@ var unzip = function(arrayBuffer) {
|
||||||
// actually do the unzipping
|
// actually do the unzipping
|
||||||
localfile.unzip();
|
localfile.unzip();
|
||||||
|
|
||||||
if (localfile.fileData != null) {
|
if (localfile.fileData !== null) {
|
||||||
postMessage(new bitjs.archive.UnarchiveExtractEvent(localfile));
|
postMessage(new bitjs.archive.UnarchiveExtractEvent(localfile));
|
||||||
postProgress();
|
postProgress();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
postProgress();
|
postProgress();
|
||||||
postMessage(new bitjs.archive.UnarchiveFinishEvent());
|
postMessage(new bitjs.archive.UnarchiveFinishEvent());
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// returns a table of Huffman codes
|
// returns a table of Huffman codes
|
||||||
// each entry's index is its code and its value is a JavaScript object
|
// each entry's index is its code and its value is a JavaScript object
|
||||||
// containing {length: 6, symbol: X}
|
// containing {length: 6, symbol: X}
|
||||||
function getHuffmanCodes(bitLengths) {
|
function getHuffmanCodes(bitLengths) {
|
||||||
// ensure bitLengths is an array containing at least one element
|
// ensure bitLengths is an array containing at least one element
|
||||||
if (typeof bitLengths != typeof [] || bitLengths.length < 1) {
|
if (typeof bitLengths !== typeof [] || bitLengths.length < 1) {
|
||||||
err("Error! getHuffmanCodes() called with an invalid array");
|
err("Error! getHuffmanCodes() called with an invalid array");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reference: http://tools.ietf.org/html/rfc1951#page-8
|
// Reference: http://tools.ietf.org/html/rfc1951#page-8
|
||||||
var numLengths = bitLengths.length,
|
var numLengths = bitLengths.length,
|
||||||
bl_count = [],
|
blCount = [],
|
||||||
MAX_BITS = 1;
|
MAX_BITS = 1;
|
||||||
|
|
||||||
// Step 1: count up how many codes of each length we have
|
// Step 1: count up how many codes of each length we have
|
||||||
for (var i = 0; i < numLengths; ++i) {
|
for (var i = 0; i < numLengths; ++i) {
|
||||||
var length = bitLengths[i];
|
var len = bitLengths[i];
|
||||||
// test to ensure each bit length is a positive, non-zero number
|
// test to ensure each bit length is a positive, non-zero number
|
||||||
if (typeof length != typeof 1 || length < 0) {
|
if (typeof len !== typeof 1 || len < 0) {
|
||||||
err("bitLengths contained an invalid number in getHuffmanCodes(): " + length + " of type " + (typeof length));
|
err("bitLengths contained an invalid number in getHuffmanCodes(): " + len + " of type " + (typeof len));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// increment the appropriate bitlength count
|
// increment the appropriate bitlength count
|
||||||
if (bl_count[length] == undefined) bl_count[length] = 0;
|
if (blCount[len] === undefined) blCount[len] = 0;
|
||||||
// a length of zero means this symbol is not participating in the huffman coding
|
// a length of zero means this symbol is not participating in the huffman coding
|
||||||
if (length > 0) bl_count[length]++;
|
if (len > 0) blCount[len]++;
|
||||||
|
|
||||||
if (length > MAX_BITS) MAX_BITS = length;
|
if (len > MAX_BITS) MAX_BITS = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2: Find the numerical value of the smallest code for each code length
|
// Step 2: Find the numerical value of the smallest code for each code length
|
||||||
var next_code = [],
|
var nextCode = [],
|
||||||
code = 0;
|
code = 0;
|
||||||
for (var bits = 1; bits <= MAX_BITS; ++bits) {
|
for (var bits = 1; bits <= MAX_BITS; ++bits) {
|
||||||
var length = bits-1;
|
var len = bits-1;
|
||||||
// ensure undefined lengths are zero
|
// ensure undefined lengths are zero
|
||||||
if (bl_count[length] == undefined) bl_count[length] = 0;
|
if (blCount[len] == undefined) blCount[len] = 0;
|
||||||
code = (code + bl_count[bits-1]) << 1;
|
code = (code + blCount[bits-1]) << 1;
|
||||||
next_code[bits] = code;
|
nextCode[bits] = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 3: Assign numerical values to all codes
|
// Step 3: Assign numerical values to all codes
|
||||||
var table = {}, tableLength = 0;
|
var table = {}, tableLength = 0;
|
||||||
for (var n = 0; n < numLengths; ++n) {
|
for (var n = 0; n < numLengths; ++n) {
|
||||||
var len = bitLengths[n];
|
var len = bitLengths[n];
|
||||||
if (len != 0) {
|
if (len !== 0) {
|
||||||
table[next_code[len]] = { length: len, symbol: n }; //, bitstring: binaryValueToString(next_code[len],len) };
|
table[nextCode[len]] = { length: len, symbol: n }; //, bitstring: binaryValueToString(nextCode[len],len) };
|
||||||
tableLength++;
|
tableLength++;
|
||||||
next_code[len]++;
|
nextCode[len]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
table.maxLength = tableLength;
|
table.maxLength = tableLength;
|
||||||
|
@ -322,9 +322,9 @@ function getFixedLiteralTable() {
|
||||||
if (!fixedHCtoLiteral) {
|
if (!fixedHCtoLiteral) {
|
||||||
var bitlengths = new Array(288);
|
var bitlengths = new Array(288);
|
||||||
for (var i = 0; i <= 143; ++i) bitlengths[i] = 8;
|
for (var i = 0; i <= 143; ++i) bitlengths[i] = 8;
|
||||||
for (i = 144; i <= 255; ++i) bitlengths[i] = 9;
|
for (var i = 144; i <= 255; ++i) bitlengths[i] = 9;
|
||||||
for (i = 256; i <= 279; ++i) bitlengths[i] = 7;
|
for (var i = 256; i <= 279; ++i) bitlengths[i] = 7;
|
||||||
for (i = 280; i <= 287; ++i) bitlengths[i] = 8;
|
for (var i = 280; i <= 287; ++i) bitlengths[i] = 8;
|
||||||
|
|
||||||
// get huffman code table
|
// get huffman code table
|
||||||
fixedHCtoLiteral = getHuffmanCodes(bitlengths);
|
fixedHCtoLiteral = getHuffmanCodes(bitlengths);
|
||||||
|
@ -335,7 +335,9 @@ function getFixedDistanceTable() {
|
||||||
// create once
|
// create once
|
||||||
if (!fixedHCtoDistance) {
|
if (!fixedHCtoDistance) {
|
||||||
var bitlengths = new Array(32);
|
var bitlengths = new Array(32);
|
||||||
for (var i = 0; i < 32; ++i) { bitlengths[i] = 5; }
|
for (var i = 0; i < 32; ++i) {
|
||||||
|
bitlengths[i] = 5;
|
||||||
|
}
|
||||||
|
|
||||||
// get huffman code table
|
// get huffman code table
|
||||||
fixedHCtoDistance = getHuffmanCodes(bitlengths);
|
fixedHCtoDistance = getHuffmanCodes(bitlengths);
|
||||||
|
@ -347,7 +349,7 @@ function getFixedDistanceTable() {
|
||||||
// then return that symbol
|
// then return that symbol
|
||||||
function decodeSymbol(bstream, hcTable) {
|
function decodeSymbol(bstream, hcTable) {
|
||||||
var code = 0, len = 0;
|
var code = 0, len = 0;
|
||||||
var match = false;
|
// var match = false;
|
||||||
|
|
||||||
// loop until we match
|
// loop until we match
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -389,14 +391,14 @@ var CodeLengthCodeOrder = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2
|
||||||
|
|
||||||
*/
|
*/
|
||||||
var LengthLookupTable = [
|
var LengthLookupTable = [
|
||||||
[0,3], [0,4], [0,5], [0,6],
|
[0, 3], [0, 4], [0, 5], [0, 6],
|
||||||
[0,7], [0,8], [0,9], [0,10],
|
[0, 7], [0, 8], [0, 9], [0, 10],
|
||||||
[1,11], [1,13], [1,15], [1,17],
|
[1, 11], [1, 13], [1, 15], [1, 17],
|
||||||
[2,19], [2,23], [2,27], [2,31],
|
[2, 19], [2, 23], [2, 27], [2, 31],
|
||||||
[3,35], [3,43], [3,51], [3,59],
|
[3, 35], [3, 43], [3, 51], [3, 59],
|
||||||
[4,67], [4,83], [4,99], [4,115],
|
[4, 67], [4, 83], [4, 99], [4, 115],
|
||||||
[5,131], [5,163], [5,195], [5,227],
|
[5, 131], [5, 163], [5, 195], [5, 227],
|
||||||
[0,258]
|
[0, 258]
|
||||||
];
|
];
|
||||||
/*
|
/*
|
||||||
Extra Extra Extra
|
Extra Extra Extra
|
||||||
|
@ -414,20 +416,20 @@ var LengthLookupTable = [
|
||||||
9 3 25-32 19 8 769-1024 29 13 24577-32768
|
9 3 25-32 19 8 769-1024 29 13 24577-32768
|
||||||
*/
|
*/
|
||||||
var DistLookupTable = [
|
var DistLookupTable = [
|
||||||
[0,1], [0,2], [0,3], [0,4],
|
[0, 1], [0, 2], [0, 3], [0, 4],
|
||||||
[1,5], [1,7],
|
[1, 5], [1, 7],
|
||||||
[2,9], [2,13],
|
[2, 9], [2, 13],
|
||||||
[3,17], [3,25],
|
[3, 17], [3, 25],
|
||||||
[4,33], [4,49],
|
[4, 33], [4, 49],
|
||||||
[5,65], [5,97],
|
[5, 65], [5, 97],
|
||||||
[6,129], [6,193],
|
[6, 129], [6, 193],
|
||||||
[7,257], [7,385],
|
[7, 257], [7, 385],
|
||||||
[8,513], [8,769],
|
[8, 513], [8, 769],
|
||||||
[9,1025], [9,1537],
|
[9, 1025], [9, 1537],
|
||||||
[10,2049], [10,3073],
|
[10, 2049], [10, 3073],
|
||||||
[11,4097], [11,6145],
|
[11, 4097], [11, 6145],
|
||||||
[12,8193], [12,12289],
|
[12, 8193], [12, 12289],
|
||||||
[13,16385], [13,24577]
|
[13, 16385], [13, 24577]
|
||||||
];
|
];
|
||||||
|
|
||||||
function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) {
|
function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) {
|
||||||
|
@ -457,7 +459,7 @@ function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// end of block reached
|
// end of block reached
|
||||||
if (symbol == 256) {
|
if (symbol === 256) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -504,12 +506,13 @@ function inflate(compressedData, numDecompressedBytes) {
|
||||||
compressedData.byteOffset,
|
compressedData.byteOffset,
|
||||||
compressedData.byteLength);
|
compressedData.byteLength);
|
||||||
var buffer = new bitjs.io.ByteBuffer(numDecompressedBytes);
|
var buffer = new bitjs.io.ByteBuffer(numDecompressedBytes);
|
||||||
var numBlocks = 0, blockSize = 0;
|
var numBlocks = 0;
|
||||||
|
var blockSize = 0;
|
||||||
|
|
||||||
// block format: http://tools.ietf.org/html/rfc1951#page-9
|
// block format: http://tools.ietf.org/html/rfc1951#page-9
|
||||||
do {
|
do {
|
||||||
var bFinal = bstream.readBits(1),
|
var bFinal = bstream.readBits(1);
|
||||||
bType = bstream.readBits(2);
|
var bType = bstream.readBits(2);
|
||||||
blockSize = 0;
|
blockSize = 0;
|
||||||
++numBlocks;
|
++numBlocks;
|
||||||
// no compression
|
// no compression
|
||||||
|
@ -524,17 +527,17 @@ function inflate(compressedData, numDecompressedBytes) {
|
||||||
blockSize = len;
|
blockSize = len;
|
||||||
}
|
}
|
||||||
// fixed Huffman codes
|
// fixed Huffman codes
|
||||||
else if(bType == 1) {
|
else if(bType === 1) {
|
||||||
blockSize = inflateBlockData(bstream, getFixedLiteralTable(), getFixedDistanceTable(), buffer);
|
blockSize = inflateBlockData(bstream, getFixedLiteralTable(), getFixedDistanceTable(), buffer);
|
||||||
}
|
}
|
||||||
// dynamic Huffman codes
|
// dynamic Huffman codes
|
||||||
else if(bType == 2) {
|
else if(bType === 2) {
|
||||||
var numLiteralLengthCodes = bstream.readBits(5) + 257;
|
var numLiteralLengthCodes = bstream.readBits(5) + 257;
|
||||||
var numDistanceCodes = bstream.readBits(5) + 1,
|
var numDistanceCodes = bstream.readBits(5) + 1,
|
||||||
numCodeLengthCodes = bstream.readBits(4) + 4;
|
numCodeLengthCodes = bstream.readBits(4) + 4;
|
||||||
|
|
||||||
// populate the array of code length codes (first de-compaction)
|
// populate the array of code length codes (first de-compaction)
|
||||||
var codeLengthsCodeLengths = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
|
var codeLengthsCodeLengths = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||||
for (var i = 0; i < numCodeLengthCodes; ++i) {
|
for (var i = 0; i < numCodeLengthCodes; ++i) {
|
||||||
codeLengthsCodeLengths[ CodeLengthCodeOrder[i] ] = bstream.readBits(3);
|
codeLengthsCodeLengths[ CodeLengthCodeOrder[i] ] = bstream.readBits(3);
|
||||||
}
|
}
|
||||||
|
@ -566,19 +569,19 @@ function inflate(compressedData, numDecompressedBytes) {
|
||||||
literalCodeLengths.push(symbol);
|
literalCodeLengths.push(symbol);
|
||||||
prevCodeLength = symbol;
|
prevCodeLength = symbol;
|
||||||
}
|
}
|
||||||
else if (symbol == 16) {
|
else if (symbol === 16) {
|
||||||
var repeat = bstream.readBits(2) + 3;
|
var repeat = bstream.readBits(2) + 3;
|
||||||
while (repeat--) {
|
while (repeat--) {
|
||||||
literalCodeLengths.push(prevCodeLength);
|
literalCodeLengths.push(prevCodeLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (symbol == 17) {
|
else if (symbol === 17) {
|
||||||
var repeat = bstream.readBits(3) + 3;
|
var repeat = bstream.readBits(3) + 3;
|
||||||
while (repeat--) {
|
while (repeat--) {
|
||||||
literalCodeLengths.push(0);
|
literalCodeLengths.push(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (symbol == 18) {
|
else if (symbol === 18) {
|
||||||
var repeat = bstream.readBits(7) + 11;
|
var repeat = bstream.readBits(7) + 11;
|
||||||
while (repeat--) {
|
while (repeat--) {
|
||||||
literalCodeLengths.push(0);
|
literalCodeLengths.push(0);
|
||||||
|
@ -605,7 +608,7 @@ function inflate(compressedData, numDecompressedBytes) {
|
||||||
currentBytesUnarchived += blockSize;
|
currentBytesUnarchived += blockSize;
|
||||||
postProgress();
|
postProgress();
|
||||||
|
|
||||||
} while (bFinal != 1);
|
} while (bFinal !== 1);
|
||||||
// we are done reading blocks if the bFinal bit was set for this block
|
// we are done reading blocks if the bFinal bit was set for this block
|
||||||
|
|
||||||
// return the buffer data bytes
|
// return the buffer data bytes
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
{% if g.user.kindle_mail and g.user.is_authenticated %}
|
{% if g.user.kindle_mail and g.user.is_authenticated %}
|
||||||
<a href="{{url_for('send_to_kindle', book_id=entry.id)}}" id="sendbtn" class="btn btn-primary" role="button"><span class="glyphicon glyphicon-send"></span> {{_('Send to Kindle')}}</a>
|
<a href="{{url_for('send_to_kindle', book_id=entry.id)}}" id="sendbtn" class="btn btn-primary" role="button"><span class="glyphicon glyphicon-send"></span> {{_('Send to Kindle')}}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if (g.user.role_download() and g.user.is_anonymous()) or g.user.is_authenticated %}
|
{% if (g.user.role_download() and g.user.is_anonymous) or g.user.is_authenticated %}
|
||||||
<div class="btn-group" role="group">
|
<div class="btn-group" role="group">
|
||||||
<button id="read-in-browser" type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
<button id="read-in-browser" type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
<span class="glyphicon glyphicon-eye-open"></span> {{_('Read in browser')}}
|
<span class="glyphicon glyphicon-eye-open"></span> {{_('Read in browser')}}
|
||||||
|
@ -157,7 +157,7 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if not g.user.is_anonymous() %}
|
{% if not g.user.is_anonymous %}
|
||||||
|
|
||||||
<div class="custom_columns">
|
<div class="custom_columns">
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" name="submit" value="submit" class="btn btn-default">{{_('Save settings')}}</button>
|
<button type="submit" name="submit" value="submit" class="btn btn-default">{{_('Save settings')}}</button>
|
||||||
<button type="submit" name="test" value="test" class="btn btn-default">{{_('Save settings and send Test E-Mail')}}</button>
|
<button type="submit" name="test" value="test" class="btn btn-default">{{_('Save settings and send Test E-Mail')}}</button>
|
||||||
<a href="{{ url_for('admin') }}" class="btn btn-default">{{_('Back')}}</a>
|
<a href="{{ url_for('admin') }}" id="back" class="btn btn-default">{{_('Back')}}</a>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
{% for entry in random %}
|
{% for entry in random %}
|
||||||
<div class="col-sm-3 col-lg-2 col-xs-6 book">
|
<div class="col-sm-3 col-lg-2 col-xs-6 book" id="books_rand">
|
||||||
<div class="cover">
|
<div class="cover">
|
||||||
<a href="{{ url_for('show_book', book_id=entry.id) }}" data-toggle="modal" data-target="#bookDetailsModal" data-remote="false">
|
<a href="{{ url_for('show_book', book_id=entry.id) }}" data-toggle="modal" data-target="#bookDetailsModal" data-remote="false">
|
||||||
{% if entry.has_cover %}
|
{% if entry.has_cover %}
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% if entries[0] %}
|
{% if entries[0] %}
|
||||||
{% for entry in entries %}
|
{% for entry in entries %}
|
||||||
<div class="col-sm-3 col-lg-2 col-xs-6 book">
|
<div class="col-sm-3 col-lg-2 col-xs-6 book" id="books">
|
||||||
<div class="cover">
|
<div class="cover">
|
||||||
<a href="{{ url_for('show_book', book_id=entry.id) }}" data-toggle="modal" data-target="#bookDetailsModal" data-remote="false">
|
<a href="{{ url_for('show_book', book_id=entry.id) }}" data-toggle="modal" data-target="#bookDetailsModal" data-remote="false">
|
||||||
{% if entry.has_cover %}
|
{% if entry.has_cover %}
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
<id>{{url_for('feed_discover')}}</id>
|
<id>{{url_for('feed_discover')}}</id>
|
||||||
<content type="text">{{_('Show Random Books')}}</content>
|
<content type="text">{{_('Show Random Books')}}</content>
|
||||||
</entry>
|
</entry>
|
||||||
{% if not current_user.is_anonymous() %}
|
{% if not current_user.is_anonymous %}
|
||||||
<entry>
|
<entry>
|
||||||
<title>{{_('Read Books')}}</title>
|
<title>{{_('Read Books')}}</title>
|
||||||
<link rel="subsection" href="{{url_for('feed_read_books')}}" type="application/atom+xml;profile=opds-catalog"/>
|
<link rel="subsection" href="{{url_for('feed_read_books')}}" type="application/atom+xml;profile=opds-catalog"/>
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
</button>
|
</button>
|
||||||
<a class="navbar-brand" href="{{url_for('index')}}">{{instance}}</a>
|
<a class="navbar-brand" href="{{url_for('index')}}">{{instance}}</a>
|
||||||
</div>
|
</div>
|
||||||
{% if g.user.is_authenticated or g.user.is_anonymous() %}
|
{% if g.user.is_authenticated or g.user.is_anonymous %}
|
||||||
<form class="navbar-form navbar-left" role="search" action="{{url_for('search')}}" method="GET">
|
<form class="navbar-form navbar-left" role="search" action="{{url_for('search')}}" method="GET">
|
||||||
<div class="form-group input-group input-group-sm">
|
<div class="form-group input-group input-group-sm">
|
||||||
<label for="query" class="sr-only">{{_('Search')}}</label>
|
<label for="query" class="sr-only">{{_('Search')}}</label>
|
||||||
|
@ -46,13 +46,13 @@
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="navbar-collapse collapse">
|
<div class="navbar-collapse collapse">
|
||||||
{% if g.user.is_authenticated or g.user.is_anonymous() %}
|
{% if g.user.is_authenticated or g.user.is_anonymous %}
|
||||||
<ul class="nav navbar-nav ">
|
<ul class="nav navbar-nav ">
|
||||||
<li><a href="{{url_for('advanced_search')}}"><span class="glyphicon glyphicon-search"></span><span class="hidden-sm"> {{_('Advanced Search')}}</span></a></li>
|
<li><a href="{{url_for('advanced_search')}}"><span class="glyphicon glyphicon-search"></span><span class="hidden-sm"> {{_('Advanced Search')}}</span></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<ul class="nav navbar-nav navbar-right" id="main-nav">
|
<ul class="nav navbar-nav navbar-right" id="main-nav">
|
||||||
{% if g.user.is_authenticated or g.user.is_anonymous() %}
|
{% if g.user.is_authenticated or g.user.is_anonymous %}
|
||||||
{% if g.user.role_upload() or g.user.role_admin()%}
|
{% if g.user.role_upload() or g.user.role_admin()%}
|
||||||
{% if g.allow_upload %}
|
{% if g.allow_upload %}
|
||||||
<li>
|
<li>
|
||||||
|
@ -68,7 +68,7 @@
|
||||||
<li><a id="top_admin" href="{{url_for('admin')}}"><span class="glyphicon glyphicon-dashboard"></span><span class="hidden-sm"> {{_('Admin')}}</span></a></li>
|
<li><a id="top_admin" href="{{url_for('admin')}}"><span class="glyphicon glyphicon-dashboard"></span><span class="hidden-sm"> {{_('Admin')}}</span></a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li><a id="top_user" href="{{url_for('profile')}}"><span class="glyphicon glyphicon-user"></span><span class="hidden-sm"> {{g.user.nickname}}</span></a></li>
|
<li><a id="top_user" href="{{url_for('profile')}}"><span class="glyphicon glyphicon-user"></span><span class="hidden-sm"> {{g.user.nickname}}</span></a></li>
|
||||||
{% if not g.user.is_anonymous() %}
|
{% if not g.user.is_anonymous %}
|
||||||
<li><a id="logout" href="{{url_for('logout')}}"><span class="glyphicon glyphicon-log-out"></span><span class="hidden-sm"> {{_('Logout')}}</span></a></li>
|
<li><a id="logout" href="{{url_for('logout')}}"><span class="glyphicon glyphicon-log-out"></span><span class="hidden-sm"> {{_('Logout')}}</span></a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -99,7 +99,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="row-fluid">
|
<div class="row-fluid">
|
||||||
{% if g.user.is_authenticated or g.user.is_anonymous() %}
|
{% if g.user.is_authenticated or g.user.is_anonymous %}
|
||||||
<div class="col-sm-2">
|
<div class="col-sm-2">
|
||||||
<nav class="navigation">
|
<nav class="navigation">
|
||||||
<ul class="list-unstyled" id="scnd-nav" intent in-standard-append="nav.navigation" in-mobile-after="#main-nav" in-mobile-class="nav navbar-nav">
|
<ul class="list-unstyled" id="scnd-nav" intent in-standard-append="nav.navigation" in-mobile-after="#main-nav" in-mobile-class="nav navbar-nav">
|
||||||
|
@ -136,11 +136,13 @@
|
||||||
{% if g.user.show_series() %}
|
{% if g.user.show_series() %}
|
||||||
<li id="nav_serie"><a href="{{url_for('series_list')}}"><span class="glyphicon glyphicon-bookmark"></span> {{_('Series')}}</a></li>
|
<li id="nav_serie"><a href="{{url_for('series_list')}}"><span class="glyphicon glyphicon-bookmark"></span> {{_('Series')}}</a></li>
|
||||||
{%endif%}
|
{%endif%}
|
||||||
|
{% if g.user.show_author() %}
|
||||||
<li id="nav_author"><a href="{{url_for('author_list')}}"><span class="glyphicon glyphicon-user"></span> {{_('Authors')}}</a></li>
|
<li id="nav_author"><a href="{{url_for('author_list')}}"><span class="glyphicon glyphicon-user"></span> {{_('Authors')}}</a></li>
|
||||||
|
{%endif%}
|
||||||
{% if g.user.filter_language() == 'all' and g.user.show_language() %}
|
{% if g.user.filter_language() == 'all' and g.user.show_language() %}
|
||||||
<li id="nav_lang"><a href="{{url_for('language_overview')}}"><span class="glyphicon glyphicon-flag"></span> {{_('Languages')}} </a></li>
|
<li id="nav_lang"><a href="{{url_for('language_overview')}}"><span class="glyphicon glyphicon-flag"></span> {{_('Languages')}} </a></li>
|
||||||
{%endif%}
|
{%endif%}
|
||||||
{% if g.user.is_authenticated or g.user.is_anonymous() %}
|
{% if g.user.is_authenticated or g.user.is_anonymous %}
|
||||||
<li class="nav-head hidden-xs">{{_('Public Shelves')}}</li>
|
<li class="nav-head hidden-xs">{{_('Public Shelves')}}</li>
|
||||||
{% for shelf in g.public_shelfes %}
|
{% for shelf in g.public_shelfes %}
|
||||||
<li><a href="{{url_for('show_shelf', shelf_id=shelf.id)}}"><span class="glyphicon glyphicon-list"></span> {{shelf.name}}</a></li>
|
<li><a href="{{url_for('show_shelf', shelf_id=shelf.id)}}"><span class="glyphicon glyphicon-list"></span> {{shelf.name}}</a></li>
|
||||||
|
@ -149,7 +151,7 @@
|
||||||
{% for shelf in g.user.shelf %}
|
{% for shelf in g.user.shelf %}
|
||||||
<li><a href="{{url_for('show_shelf', shelf_id=shelf.id)}}"><span class="glyphicon glyphicon-list"></span> {{shelf.name}}</a></li>
|
<li><a href="{{url_for('show_shelf', shelf_id=shelf.id)}}"><span class="glyphicon glyphicon-list"></span> {{shelf.name}}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if not g.user.is_anonymous() %}
|
{% if not g.user.is_anonymous %}
|
||||||
<li id="nav_createshelf" class="create-shelf"><a href="{{url_for('create_shelf')}}">{{_('Create a Shelf')}}</a></li>
|
<li id="nav_createshelf" class="create-shelf"><a href="{{url_for('create_shelf')}}">{{_('Create a Shelf')}}</a></li>
|
||||||
<li id="nav_about"><a href="{{url_for('stats')}}"><span class="glyphicon glyphicon-info-sign"></span> {{_('About')}}</a></li>
|
<li id="nav_about"><a href="{{url_for('stats')}}"><span class="glyphicon glyphicon-info-sign"></span> {{_('About')}}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -83,7 +83,8 @@
|
||||||
cssPath: "{{ url_for('static', filename='css/') }}",
|
cssPath: "{{ url_for('static', filename='css/') }}",
|
||||||
bookUrl: "{{ url_for('static', filename=bookid) }}/",
|
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') }}",
|
||||||
bookmark: "{{ bookmark.bookmark_key if bookmark != None }}"
|
bookmark: "{{ bookmark.bookmark_key if bookmark != None }}",
|
||||||
|
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>
|
||||||
|
|
12
cps/ub.py
12
cps/ub.py
|
@ -51,7 +51,7 @@ DEVELOPMENT = False
|
||||||
|
|
||||||
|
|
||||||
class UserBase:
|
class UserBase:
|
||||||
@staticmethod
|
@property
|
||||||
def is_authenticated(self):
|
def is_authenticated(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -97,11 +97,11 @@ class UserBase:
|
||||||
def role_delete_books(self):
|
def role_delete_books(self):
|
||||||
return bool((self.role is not None)and(self.role & ROLE_DELETE_BOOKS == ROLE_DELETE_BOOKS))
|
return bool((self.role is not None)and(self.role & ROLE_DELETE_BOOKS == ROLE_DELETE_BOOKS))
|
||||||
|
|
||||||
@classmethod
|
@property
|
||||||
def is_active(self):
|
def is_active(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@classmethod
|
@property
|
||||||
def is_anonymous(self):
|
def is_anonymous(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -172,6 +172,7 @@ class Anonymous(AnonymousUserMixin, UserBase):
|
||||||
settings = session.query(Settings).first()
|
settings = session.query(Settings).first()
|
||||||
self.nickname = data.nickname
|
self.nickname = data.nickname
|
||||||
self.role = data.role
|
self.role = data.role
|
||||||
|
self.id=data.id
|
||||||
self.sidebar_view = data.sidebar_view
|
self.sidebar_view = data.sidebar_view
|
||||||
self.default_language = data.default_language
|
self.default_language = data.default_language
|
||||||
self.locale = data.locale
|
self.locale = data.locale
|
||||||
|
@ -181,12 +182,17 @@ class Anonymous(AnonymousUserMixin, UserBase):
|
||||||
def role_admin(self):
|
def role_admin(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
def is_active(self):
|
def is_active(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
def is_anonymous(self):
|
def is_anonymous(self):
|
||||||
return self.anon_browse
|
return self.anon_browse
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_authenticated(self):
|
||||||
|
return False
|
||||||
|
|
||||||
# Baseclass representing Shelfs in calibre-web inapp.db
|
# Baseclass representing Shelfs in calibre-web inapp.db
|
||||||
class Shelf(Base):
|
class Shelf(Base):
|
||||||
|
|
21
cps/web.py
21
cps/web.py
|
@ -384,9 +384,12 @@ app.jinja_env.globals['url_for_other_page'] = url_for_other_page
|
||||||
|
|
||||||
|
|
||||||
def login_required_if_no_ano(func):
|
def login_required_if_no_ano(func):
|
||||||
if config.config_anonbrowse == 1:
|
@wraps(func)
|
||||||
return func
|
def decorated_view(*args, **kwargs):
|
||||||
return login_required(func)
|
if config.config_anonbrowse == 1:
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
return login_required(func)(*args, **kwargs)
|
||||||
|
return decorated_view
|
||||||
|
|
||||||
|
|
||||||
def remote_login_required(f):
|
def remote_login_required(f):
|
||||||
|
@ -1311,7 +1314,7 @@ def show_book(book_id):
|
||||||
for entry in shelfs:
|
for entry in shelfs:
|
||||||
book_in_shelfs.append(entry.shelf)
|
book_in_shelfs.append(entry.shelf)
|
||||||
|
|
||||||
if not current_user.is_anonymous():
|
if not current_user.is_anonymous:
|
||||||
matching_have_read_book = ub.session.query(ub.ReadBook).filter(ub.and_(ub.ReadBook.user_id == int(current_user.id),
|
matching_have_read_book = ub.session.query(ub.ReadBook).filter(ub.and_(ub.ReadBook.user_id == int(current_user.id),
|
||||||
ub.ReadBook.book_id == book_id)).all()
|
ub.ReadBook.book_id == book_id)).all()
|
||||||
have_read = len(matching_have_read_book) > 0 and matching_have_read_book[0].is_read
|
have_read = len(matching_have_read_book) > 0 and matching_have_read_book[0].is_read
|
||||||
|
@ -1726,7 +1729,7 @@ def feed_get_cover(book_id):
|
||||||
|
|
||||||
|
|
||||||
def render_read_books(page, are_read, as_xml=False):
|
def render_read_books(page, are_read, as_xml=False):
|
||||||
if not current_user.is_anonymous():
|
if not current_user.is_anonymous:
|
||||||
readBooks = ub.session.query(ub.ReadBook).filter(ub.ReadBook.user_id == int(current_user.id)).filter(ub.ReadBook.is_read == True).all()
|
readBooks = ub.session.query(ub.ReadBook).filter(ub.ReadBook.user_id == int(current_user.id)).filter(ub.ReadBook.is_read == True).all()
|
||||||
readBookIds = [x.book_id for x in readBooks]
|
readBookIds = [x.book_id for x in readBooks]
|
||||||
if are_read:
|
if are_read:
|
||||||
|
@ -1799,7 +1802,9 @@ def read_book(book_id, book_format):
|
||||||
book_dir = os.path.join(config.get_main_dir, "cps", "static", str(book_id))
|
book_dir = os.path.join(config.get_main_dir, "cps", "static", str(book_id))
|
||||||
if not os.path.exists(book_dir):
|
if not os.path.exists(book_dir):
|
||||||
os.mkdir(book_dir)
|
os.mkdir(book_dir)
|
||||||
bookmark = ub.session.query(ub.Bookmark).filter(ub.and_(ub.Bookmark.user_id == int(current_user.id),
|
bookmark = None
|
||||||
|
if current_user.is_authenticated:
|
||||||
|
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":
|
||||||
|
@ -2213,7 +2218,7 @@ def delete_shelf(shelf_id):
|
||||||
@app.route("/shelf/<int:shelf_id>")
|
@app.route("/shelf/<int:shelf_id>")
|
||||||
@login_required_if_no_ano
|
@login_required_if_no_ano
|
||||||
def show_shelf(shelf_id):
|
def show_shelf(shelf_id):
|
||||||
if current_user.is_anonymous():
|
if current_user.is_anonymous:
|
||||||
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
|
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
|
||||||
else:
|
else:
|
||||||
shelf = ub.session.query(ub.Shelf).filter(ub.or_(ub.and_(ub.Shelf.user_id == int(current_user.id),
|
shelf = ub.session.query(ub.Shelf).filter(ub.or_(ub.and_(ub.Shelf.user_id == int(current_user.id),
|
||||||
|
@ -2248,7 +2253,7 @@ def order_shelf(shelf_id):
|
||||||
setattr(book, 'order', to_save[str(book.book_id)])
|
setattr(book, 'order', to_save[str(book.book_id)])
|
||||||
counter += 1
|
counter += 1
|
||||||
ub.session.commit()
|
ub.session.commit()
|
||||||
if current_user.is_anonymous():
|
if current_user.is_anonymous:
|
||||||
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
|
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
|
||||||
else:
|
else:
|
||||||
shelf = ub.session.query(ub.Shelf).filter(ub.or_(ub.and_(ub.Shelf.user_id == int(current_user.id),
|
shelf = ub.session.query(ub.Shelf).filter(ub.or_(ub.and_(ub.Shelf.user_id == int(current_user.id),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user