Commit 14b6202e authored by Ozzieisaacs's avatar Ozzieisaacs

Code cosmetics

Fixes func in helper,web
Fixes for pdf reader
fixes for calling from another folder
renamed to calibreweb for importing in python caller script
parent 50973ffb
......@@ -23,7 +23,8 @@ import os
# Insert local directories into path
sys.path.append(os.path.join(sys.path[0], 'vendor'))
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'vendor'))
from cps import create_app
......
......@@ -204,7 +204,7 @@ def view_configuration():
content.config_default_role |= constants.ROLE_EDIT_SHELFS
val = 0
for key,v in to_save.items():
for key, __ in to_save.items():
if key.startswith('show'):
val |= int(key[5:])
content.config_default_show = val
......
......@@ -23,7 +23,8 @@ import os
from collections import namedtuple
BASE_DIR = sys.path[0]
# Base dir is parent of current file, necessary if called from different folder
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)),os.pardir))
STATIC_DIR = os.path.join(BASE_DIR, 'cps', 'static')
TEMPLATES_DIR = os.path.join(BASE_DIR, 'cps', 'templates')
TRANSLATIONS_DIR = os.path.join(BASE_DIR, 'cps', 'translations')
......@@ -104,9 +105,7 @@ def has_flag(value, bit_flag):
return bit_flag == (bit_flag & (value or 0))
"""
:rtype: BookMeta
"""
# :rtype: BookMeta
BookMeta = namedtuple('BookMeta', 'file_path, extension, title, author, cover, description, tags, series, '
'series_id, languages')
......
......@@ -342,7 +342,10 @@ def setup_db():
try:
if not os.path.exists(dbpath):
raise
engine = create_engine('sqlite:///' + dbpath, echo=False, isolation_level="SERIALIZABLE", connect_args={'check_same_thread': False})
engine = create_engine('sqlite:///' + dbpath,
echo=False,
isolation_level="SERIALIZABLE",
connect_args={'check_same_thread': False})
conn = engine.connect()
except Exception:
content = ub.session.query(ub.Settings).first()
......
......@@ -362,42 +362,6 @@ def upload_single_file(request, book, book_id):
"<a href=\"" + url_for('web.show_book', book_id=book.id) + "\">" + uploadText + "</a>")
def upload_single_file(request, book, book_id):
if 'btn-upload-cover' in request.files:
requested_file = request.files['btn-upload-cover']
# check for empty request
if requested_file.filename != '':
file_ext = requested_file.filename.rsplit('.', 1)[-1].lower()
filepath = os.path.normpath(os.path.join(config.config_calibre_dir, book.path))
saved_filename = os.path.join(filepath, 'cover.' + file_ext)
# check if file path exists, otherwise create it, copy file to calibre path and delete temp file
if not os.path.exists(filepath):
try:
os.makedirs(filepath)
except OSError:
flash(_(u"Failed to create path for cover %(path)s (Permission denied).", cover=filepath),
category="error")
return redirect(url_for('show_book', book_id=book.id))
try:
requested_file.save(saved_filename)
# im=Image.open(saved_filename)
book.has_cover = 1
except OSError:
flash(_(u"Failed to store cover-file %(cover)s.", cover=saved_filename), category="error")
return redirect(url_for('web.show_book', book_id=book.id))
except IOError:
flash(_(u"Cover-file is not a valid image file" % saved_filename), category="error")
return redirect(url_for('web.show_book', book_id=book.id))
if helper.save_cover(requested_file, book.path) is True:
return True
else:
# ToDo Message not always coorect
flash(_(u"Cover is not a supported imageformat (jpg/png/webp), can't save"), category="error")
return False
return None
def upload_cover(request, book):
if 'btn-upload-cover' in request.files:
requested_file = request.files['btn-upload-cover']
......@@ -411,6 +375,7 @@ def upload_cover(request, book):
return False
return None
@editbook.route("/admin/book/<int:book_id>", methods=['GET', 'POST'])
@login_required_if_no_ano
@edit_required
......
......@@ -491,12 +491,12 @@ def save_cover_from_filestorage(filepath, saved_filename, img):
return False
try:
img.save(os.path.join(filepath, saved_filename))
except OSError:
log.error(u"Failed to store cover-file")
return False
except IOError:
log.error(u"Cover-file is not a valid image file")
return False
except OSError:
log.error(u"Failed to store cover-file")
return False
return True
......@@ -703,7 +703,7 @@ def fill_indexpage(page, database, db_filter, order, *join):
def get_typeahead(database, query, replace=('','')):
db.session.connection().connection.connection.create_function("lower", 1, lcase)
entries = db.session.query(database).filter(db.func.lower(database.name).ilike("%" + query + "%")).all()
entries = db.session.query(database).filter(func.lower(database.name).ilike("%" + query + "%")).all()
json_dumps = json.dumps([dict(name=r.name.replace(*replace)) for r in entries])
return json_dumps
......@@ -713,16 +713,16 @@ def get_search_results(term):
q = list()
authorterms = re.split("[, ]+", term)
for authorterm in authorterms:
q.append(db.Books.authors.any(db.func.lower(db.Authors.name).ilike("%" + authorterm + "%")))
q.append(db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + authorterm + "%")))
db.Books.authors.any(db.func.lower(db.Authors.name).ilike("%" + term + "%"))
db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + term + "%"))
return db.session.query(db.Books).filter(common_filters()).filter(
or_(db.Books.tags.any(db.func.lower(db.Tags.name).ilike("%" + term + "%")),
db.Books.series.any(db.func.lower(db.Series.name).ilike("%" + term + "%")),
or_(db.Books.tags.any(func.lower(db.Tags.name).ilike("%" + term + "%")),
db.Books.series.any(func.lower(db.Series.name).ilike("%" + term + "%")),
db.Books.authors.any(and_(*q)),
db.Books.publishers.any(db.func.lower(db.Publishers.name).ilike("%" + term + "%")),
db.func.lower(db.Books.title).ilike("%" + term + "%")
db.Books.publishers.any(func.lower(db.Publishers.name).ilike("%" + term + "%")),
func.lower(db.Books.title).ilike("%" + term + "%")
)).all()
def get_unique_other_books(library_books, author_books):
......
......@@ -121,5 +121,5 @@ class StderrLogger(object):
self.buffer = ''
else:
self.buffer += message
except:
except Exception:
self.logger.debug("Logging Error")
......@@ -266,10 +266,10 @@ def delete_shelf(shelf_id):
return redirect(url_for('web.index'))
# @shelf.route("/shelfdown/<int:shelf_id>")
@shelf.route("/shelf/<int:shelf_id>", defaults={'type': 1})
@shelf.route("/shelf/<int:shelf_id>/<int:type>")
@shelf.route("/shelf/<int:shelf_id>", defaults={'shelf_type': 1})
@shelf.route("/shelf/<int:shelf_id>/<int:shelf_type>")
@login_required
def show_shelf(type, shelf_id):
def show_shelf(shelf_type, shelf_id):
if current_user.is_anonymous:
shelf = ub.session.query(ub.Shelf).filter(ub.Shelf.is_public == 1, ub.Shelf.id == shelf_id).first()
else:
......@@ -280,7 +280,7 @@ def show_shelf(type, shelf_id):
result = list()
# user is allowed to access shelf
if shelf:
page = "shelf.html" if type == 1 else 'shelfdown.html'
page = "shelf.html" if shelf_type == 1 else 'shelfdown.html'
books_in_shelf = ub.session.query(ub.BookShelf).filter(ub.BookShelf.shelf == shelf_id).order_by(
ub.BookShelf.order.asc()).all()
......
......@@ -8,7 +8,7 @@
* Copyright(c) 2011 Google Inc.
*/
/* global bitjs */
/* global bitjs, Uint8Array */
var bitjs = bitjs || {};
bitjs.archive = bitjs.archive || {};
......@@ -17,7 +17,7 @@ bitjs.archive = bitjs.archive || {};
// ===========================================================================
// Stolen from Closure because it's the best way to do Java-like inheritance.
bitjs.base = function(me, opt_methodName, var_args) {
bitjs.base = function(me, optMethodName, varArgs) {
var caller = arguments.callee.caller;
if (caller.superClass_) {
// This is a constructor. Call the superclass constructor.
......@@ -28,10 +28,10 @@ bitjs.archive = bitjs.archive || {};
var args = Array.prototype.slice.call(arguments, 2);
var foundCaller = false;
for (var ctor = me.constructor; ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
if (ctor.prototype[opt_methodName] === caller) {
if (ctor.prototype[optMethodName] === caller) {
foundCaller = true;
} else if (foundCaller) {
return ctor.prototype[opt_methodName].apply(me, args);
return ctor.prototype[optMethodName].apply(me, args);
}
}
......@@ -39,8 +39,8 @@ bitjs.archive = bitjs.archive || {};
// then one of two things happened:
// 1) The caller is an instance method.
// 2) This method was not called by the right caller.
if (me[opt_methodName] === caller) {
return me.constructor.prototype[opt_methodName].apply(me, args);
if (me[optMethodName] === caller) {
return me.constructor.prototype[optMethodName].apply(me, args);
} else {
throw Error(
"goog.base called from a method of one name " +
......@@ -49,10 +49,10 @@ bitjs.archive = bitjs.archive || {};
};
bitjs.inherits = function(childCtor, parentCtor) {
/** @constructor */
function tempCtor() {};
tempCtor.prototype = parentCtor.prototype;
function TempCtor() {}
TempCtor.prototype = parentCtor.prototype;
childCtor.superClass_ = parentCtor.prototype;
childCtor.prototype = new tempCtor();
childCtor.prototype = new TempCtor();
childCtor.prototype.constructor = childCtor;
};
// ===========================================================================
......@@ -188,10 +188,10 @@ bitjs.archive = bitjs.archive || {};
* Base class for all Unarchivers.
*
* @param {ArrayBuffer} arrayBuffer The Array Buffer.
* @param {string} opt_pathToBitJS Optional string for where the BitJS files are located.
* @param {string} optPathToBitJS Optional string for where the BitJS files are located.
* @constructor
*/
bitjs.archive.Unarchiver = function(arrayBuffer, opt_pathToBitJS) {
bitjs.archive.Unarchiver = function(arrayBuffer, optPathToBitJS) {
/**
* The ArrayBuffer object.
* @type {ArrayBuffer}
......@@ -204,7 +204,7 @@ bitjs.archive = bitjs.archive || {};
* @type {string}
* @private
*/
this.pathToBitJS_ = opt_pathToBitJS || "/";
this.pathToBitJS_ = optPathToBitJS || "/";
/**
* A map from event type to an array of listeners.
......@@ -319,8 +319,8 @@ bitjs.archive = bitjs.archive || {};
* @extends {bitjs.archive.Unarchiver}
* @constructor
*/
bitjs.archive.Unzipper = function(arrayBuffer, opt_pathToBitJS) {
bitjs.base(this, arrayBuffer, opt_pathToBitJS);
bitjs.archive.Unzipper = function(arrayBuffer, optPathToBitJS) {
bitjs.base(this, arrayBuffer, optPathToBitJS);
};
bitjs.inherits(bitjs.archive.Unzipper, bitjs.archive.Unarchiver);
bitjs.archive.Unzipper.prototype.getScriptFileName = function() {
......@@ -332,8 +332,8 @@ bitjs.archive = bitjs.archive || {};
* @extends {bitjs.archive.Unarchiver}
* @constructor
*/
bitjs.archive.Unrarrer = function(arrayBuffer, opt_pathToBitJS) {
bitjs.base(this, arrayBuffer, opt_pathToBitJS);
bitjs.archive.Unrarrer = function(arrayBuffer, optPathToBitJS) {
bitjs.base(this, arrayBuffer, optPathToBitJS);
};
bitjs.inherits(bitjs.archive.Unrarrer, bitjs.archive.Unarchiver);
bitjs.archive.Unrarrer.prototype.getScriptFileName = function() {
......@@ -345,8 +345,8 @@ bitjs.archive = bitjs.archive || {};
* @extends {bitjs.archive.Unarchiver}
* @constructor
*/
bitjs.archive.Untarrer = function(arrayBuffer, opt_pathToBitJS) {
bitjs.base(this, arrayBuffer, opt_pathToBitJS);
bitjs.archive.Untarrer = function(arrayBuffer, optPathToBitJS) {
bitjs.base(this, arrayBuffer, optPathToBitJS);
};
bitjs.inherits(bitjs.archive.Untarrer, bitjs.archive.Unarchiver);
bitjs.archive.Untarrer.prototype.getScriptFileName = function() {
......@@ -357,20 +357,19 @@ bitjs.archive = bitjs.archive || {};
* Factory method that creates an unarchiver based on the byte signature found
* in the arrayBuffer.
* @param {ArrayBuffer} ab
* @param {string=} opt_pathToBitJS Path to the unarchiver script files.
* @param {string=} optPathToBitJS Path to the unarchiver script files.
* @return {bitjs.archive.Unarchiver}
*/
bitjs.archive.GetUnarchiver = function(ab, opt_pathToBitJS) {
bitjs.archive.GetUnarchiver = function(ab, optPathToBitJS) {
var unarchiver = null;
var pathToBitJS = opt_pathToBitJS || '';
var pathToBitJS = optPathToBitJS || "";
var h = new Uint8Array(ab, 0, 10);
if (h[0] == 0x52 && h[1] == 0x61 && h[2] == 0x72 && h[3] == 0x21) { // Rar!
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)
} else if (h[0] === 80 && h[1] === 75) { // PK (Zip)
unarchiver = new bitjs.archive.Unzipper(ab, pathToBitJS);
} else { // Try with tar
console.log('geter');
unarchiver = new bitjs.archive.Untarrer(ab, pathToBitJS);
}
return unarchiver;
......
This diff is collapsed.
This diff is collapsed.
......@@ -10,9 +10,11 @@
* TAR format: http://www.gnu.org/software/automake/manual/tar/Standard.html
*/
/* global bitjs, importScripts, Uint8Array */
// This file expects to be invoked as a Worker (see onmessage below).
importScripts('../io/bytestream.js');
importScripts('archive.js');
importScripts("../io/bytestream.js");
importScripts("archive.js");
// Progress variables.
var currentFilename = "";
......@@ -21,6 +23,7 @@ var currentBytesUnarchivedInFile = 0;
var currentBytesUnarchived = 0;
var totalUncompressedBytesInArchive = 0;
var totalFilesInArchive = 0;
var allLocalFiles = [];
// Helper functions.
var info = function(str) {
......@@ -44,8 +47,8 @@ var postProgress = function() {
currentBytesUnarchivedInFile,
currentBytesUnarchived,
totalUncompressedBytesInArchive,
totalFilesInArchive,
));
totalFilesInArchive
));
};
// takes a ByteStream and parses out the local file information
......@@ -66,7 +69,7 @@ var TarLocalFile = function(bstream) {
this.linkname = readCleanString(bstream, 100);
this.maybeMagic = readCleanString(bstream, 6);
if (this.maybeMagic == "ustar") {
if (this.maybeMagic === "ustar") {
this.version = readCleanString(bstream, 2);
this.uname = readCleanString(bstream, 32);
this.gname = readCleanString(bstream, 32);
......@@ -103,14 +106,14 @@ var TarLocalFile = function(bstream) {
}
// Round up to 512-byte blocks.
var remaining = 512 - bytesRead % 512;
var remaining = 512 - (bytesRead % 512);
if (remaining > 0 && remaining < 512) {
bstream.readBytes(remaining);
}
} else if (this.typeflag == 5) {
info(" This is a directory.");
}
}
};
var untar = function(arrayBuffer) {
postMessage(new bitjs.archive.UnarchiveStartEvent());
......@@ -125,7 +128,7 @@ var untar = function(arrayBuffer) {
var bstream = new bitjs.io.ByteStream(arrayBuffer);
postProgress();
// 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);
if (oneLocalFile && oneLocalFile.isValid) {
// If we make it to this point and haven't thrown an error, we have successfully
......@@ -159,8 +162,8 @@ onmessage = function(event) {
// Overrun the buffer.
// unarchiveState = UnarchiveState.WAITING;
} else {
console.error("Found an error while untarring");
console.log(e);
err("Found an error while untarring");
err(e);
throw e;
}
}
......
......@@ -14,10 +14,10 @@
/* global bitjs, importScripts, Uint8Array*/
// This file expects to be invoked as a Worker (see onmessage below).
importScripts('../io/bitstream.js');
importScripts('../io/bytebuffer.js');
importScripts('../io/bytestream.js');
importScripts('archive.js');
importScripts("../io/bitstream.js");
importScripts("../io/bytebuffer.js");
importScripts("../io/bytestream.js");
importScripts("archive.js");
// Progress variables.
var currentFilename = "";
......@@ -118,13 +118,11 @@ ZipLocalFile.prototype.unzip = function() {
currentBytesUnarchivedInFile = this.compressedSize;
currentBytesUnarchived += this.compressedSize;
this.fileData = zeroCompression(this.fileData, this.uncompressedSize);
}
// version == 20, compression method == 8 (DEFLATE)
else if (this.compressionMethod === 8) {
} else if (this.compressionMethod === 8) {
// version == 20, compression method == 8 (DEFLATE)
info("ZIP v2.0, DEFLATE: " + this.filename + " (" + this.compressedSize + " bytes)");
this.fileData = inflate(this.fileData, this.uncompressedSize);
}
else {
} else {
err("UNSUPPORTED VERSION/FORMAT: ZIP v" + this.version + ", compression method=" + this.compressionMethod + ": " + this.filename + " (" + this.compressedSize + " bytes)");
this.fileData = null;
}
......@@ -497,13 +495,11 @@ function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) {
// copy literal byte to output
buffer.insertByte(symbol);
blockSize++;
}
else {
} else {
// end of block reached
if (symbol === 256) {
break;
}
else {
} else {
var lengthLookup = LengthLookupTable[symbol - 257],
length = lengthLookup[1] + bstream.readBits(lengthLookup[0]),
distLookup = DistLookupTable[decodeSymbol(bstream, hcDistanceTable)],
......@@ -566,7 +562,7 @@ function inflate(compressedData, numDecompressedBytes) {
blockSize = 0;
// ++numBlocks;
// no compression
if (bType == 0) {
if (bType === 0) {
// skip remaining bits in this byte
while (bstream.bitPtr !== 0) bstream.readBits(1);
var len = bstream.readBits(16);
......@@ -575,13 +571,11 @@ function inflate(compressedData, numDecompressedBytes) {
if (len > 0) buffer.insertBytes(bstream.readBytes(len));
blockSize = len;
}
// fixed Huffman codes
else if (bType === 1) {
} else if (bType === 1) {
// fixed Huffman codes
blockSize = inflateBlockData(bstream, getFixedLiteralTable(), getFixedDistanceTable(), buffer);
}
// dynamic Huffman codes
else if (bType === 2) {
} else if (bType === 2) {
// dynamic Huffman codes
var numLiteralLengthCodes = bstream.readBits(5) + 257;
var numDistanceCodes = bstream.readBits(5) + 1,
numCodeLengthCodes = bstream.readBits(4) + 4;
......@@ -664,4 +658,4 @@ function inflate(compressedData, numDecompressedBytes) {
// event.data.file has the ArrayBuffer.
onmessage = function(event) {
unzip(event.data.file, true);
};
\ No newline at end of file
};
......@@ -26,7 +26,7 @@ $("#sort_name").click(function() {
var cnt = $("#second").contents();
$("#list").append(cnt);
// Count no of elements
var listItems = $('#list').children(".row");
var listItems = $("#list").children(".row");
var listlength = listItems.length;
// check for each element if its Starting character matches
$(".row").each(function() {
......@@ -35,8 +35,8 @@ $("#sort_name").click(function() {
} else {
store = this.attributes["data-id"];
}
$(this).find('a').html(store.value);
if($(this).css("display") != "none") {
$(this).find("a").html(store.value);
if ($(this).css("display") !== "none") {
count++;
}
});
......@@ -49,7 +49,7 @@ $("#sort_name").click(function() {
// search for the middle of all visibe elements
$(".row").each(function() {
index++;
if($(this).css("display") != "none") {
if ($(this).css("display") !== "none") {
middle--;
if (middle <= 0) {
return false;
......@@ -67,8 +67,8 @@ $("#desc").click(function() {
return;
}
var index = 0;
var list = $('#list');
var second = $('#second');
var list = $("#list");
var second = $("#second");
// var cnt = ;
list.append(second.contents());
var listItems = list.children(".row");
......@@ -78,13 +78,13 @@ $("#desc").click(function() {
// Find count of middle element
var count = $(".row:visible").length;
if (count > 20) {
var middle = parseInt(count / 2) + (count % 2);
middle = parseInt(count / 2) + (count % 2);
//var middle = parseInt(count / 2) + (count % 2);
// search for the middle of all visible elements
$(reversed).each(function() {
index++;
if($(this).css("display") != "none") {
if ($(this).css("display") !== "none") {
middle--;
if (middle <= 0) {
return false;
......@@ -93,9 +93,8 @@ $("#desc").click(function() {
});
list.append(reversed.slice(0, index));
second.append(reversed.slice(index,elementLength));
}
else {
second.append(reversed.slice(index, elementLength));
} else {
list.append(reversed.slice(0, elementLength));
}
direction = 0;
......@@ -108,11 +107,11 @@ $("#asc").click(function() {
}
var index = 0;
var list = $("#list");
var second = $('#second');
var second = $("#second");
list.append(second.contents());
var listItems = list.children(".row");
reversed = listItems.get().reverse();
elementLength = reversed.length;
var reversed = listItems.get().reverse();
var elementLength = reversed.length;
// Find count of middle element
var count = $(".row:visible").length;
......@@ -123,7 +122,7 @@ $("#asc").click(function() {
// search for the middle of all visible elements
$(reversed).each(function() {
index++;
if($(this).css("display") != "none") {
if ($(this).css("display") !== "none") {
middle--;
if (middle <= 0) {
return false;
......@@ -134,7 +133,7 @@ $("#asc").click(function() {
// middle = parseInt(elementLength / 2) + (elementLength % 2);
list.append(reversed.slice(0, index));
second.append(reversed.slice(index,elementLength));
second.append(reversed.slice(index, elementLength));
} else {
list.append(reversed.slice(0, elementLength));
}
......@@ -145,7 +144,7 @@ $("#all").click(function() {
var cnt = $("#second").contents();
$("#list").append(cnt);
// Find count of middle element
var listItems = $('#list').children(".row");
var listItems = $("#list").children(".row");
var listlength = listItems.length;
var middle = parseInt(listlength / 2) + (listlength % 2);
// go through all elements and make them visible
......@@ -154,7 +153,7 @@ $("#all").click(function() {
});
// Move second half of all elements
if (listlength > 20) {
$("#second").append(listItems.slice(middle,listlength));
$("#second").append(listItems.slice(middle, listlength));
}
});
......@@ -166,7 +165,7 @@ $(".char").click(function() {
var cnt = $("#second").contents();
$("#list").append(cnt);
// Count no of elements
var listItems = $('#list').children(".row");
var listItems = $("#list").children(".row");
var listlength = listItems.length;
// check for each element if its Starting character matches
$(".row").each(function() {
......@@ -183,7 +182,7 @@ $(".char").click(function() {
// search for the middle of all visibe elements
$(".row").each(function() {
index++;
if($(this).css("display") != "none") {
if ($(this).css("display") !== "none") {
middle--;
if (middle <= 0) {
return false;
......@@ -191,6 +190,6 @@ $(".char").click(function() {
}
});
// Move second half of visible elements
$("#second").append(listItems.slice(index,listlength));
$("#second").append(listItems.slice(index, listlength));
}
});
......@@ -64,7 +64,7 @@ bitjs.io = bitjs.io || {};
return 0;
}
var movePointers = movePointers || false;
movePointers = movePointers || false;
var bytePtr = this.bytePtr;
var bitPtr = this.bitPtr;
var result = 0;
......@@ -125,7 +125,7 @@ bitjs.io = bitjs.io || {};
return 0;
}
var movePointers = movePointers || false;
movePointers = movePointers || false;
var bytePtr = this.bytePtr;
var bitPtr = this.bitPtr;
var result = 0;
......@@ -197,7 +197,7 @@ bitjs.io = bitjs.io || {};
* @return {Uint8Array} The subarray.
*/
bitjs.io.BitStream.prototype.peekBytes = function(n, movePointers) {
if (n <= 0 || typeof n != typeof 1) {
if (n <= 0 || typeof n !== typeof 1) {
return 0;
}
......@@ -322,7 +322,7 @@ bitjs.io = bitjs.io || {};
* @return {Uint8Array} The subarray.
*/
bitjs.io.ByteStream.prototype.peekBytes = function(n, movePointers) {
if (n <= 0 || typeof n != typeof 1) {
if (n <= 0 || typeof n !== typeof 1) {
return null;
}
......@@ -352,7 +352,7 @@ bitjs.io = bitjs.io || {};
* @return {string} The next n bytes as a string.
*/
bitjs.io.ByteStream.prototype.peekString = function(n) {
if (n <= 0 || typeof n != typeof 1) {
if (n <= 0 || typeof n !== typeof 1) {
return "";
}
......
......@@ -15,7 +15,10 @@
* Typed Arrays: http://www.khronos.org/registry/typedarray/specs/latest/#6
*/
/* global screenfull, bitjs */
/* global screenfull, bitjs, Uint8Array, opera */
/* exported init, event */
if (window.opera) {
window.console.log = function(str) {
opera.postError(str);
......@@ -101,12 +104,12 @@ kthoom.setSettings = function() {
var createURLFromArray = function(array, mimeType) {
var offset = array.byteOffset;
var len = array.byteLength;
var url;
// var url;
var blob;
if (mimeType === 'image/xml+svg') {
const xmlStr = new TextDecoder('utf-8').decode(array);
return 'data:image/svg+xml;UTF-8,' + encodeURIComponent(xmlStr);
if (mimeType === "image/xml+svg") {
var xmlStr = new TextDecoder("utf-8").decode(array);
return "data:image/svg+xml;UTF-8," + encodeURIComponent(xmlStr);
}
// TODO: Move all this browser support testing to a common place
......@@ -140,7 +143,7 @@ kthoom.ImageFile = function(file) {
var fileExtension = file.filename.split(".").pop().toLowerCase();
this.mimeType = fileExtension === "png" ? "image/png" :
(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;
if ( this.mimeType !== undefined) {
this.dataURI = createURLFromArray(file.fileData, this.mimeType);
this.data = file;
......@@ -154,17 +157,18 @@ function initProgressClick() {
currentImage = page;
updatePage();
});
};
}
function loadFromArrayBuffer(ab) {
var start = (new Date).getTime();
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
} else if (h[0] === 255 && h[1] === 216) { // JPEG
// ToDo: check
updateProgress(100);
lastCompletion = 100;
......@@ -180,12 +184,12 @@ function loadFromArrayBuffer(ab) {
if (totalImages === 0) {
totalImages = e.totalFilesInArchive;
}
updateProgress(percentage *100);
updateProgress(percentage * 100);
lastCompletion = percentage * 100;
});
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.INFO,
function(e) {
// console.log(e.msg); 77 Enable debug output here
// console.log(e.msg); // Enable debug output here
});
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.EXTRACT,
function(e) {
......@@ -211,8 +215,7 @@ function loadFromArrayBuffer(ab) {
if (imageFiles.length === currentImage + 1) {
updatePage(lastCompletion);
}
}
else {
} else {
totalImages--;
}
}
......@@ -231,22 +234,22 @@ function loadFromArrayBuffer(ab) {
function scrollTocToActive() {
// Scroll to the thumbnail in the TOC on page change
$('#tocView').stop().animate({
scrollTop: $('#tocView a.active').position().top
$("#tocView").stop().animate({
scrollTop: $("#tocView a.active").position().top
}, 200);
}
function updatePage() {
$('.page').text((currentImage + 1 ) + "/" + totalImages);
$(".page").text((currentImage + 1 ) + "/" + totalImages);
// Mark the current page in the TOC
$('#tocView a[data-page]')
$("#tocView a[data-page]")
// Remove the currently active thumbnail
.removeClass('active')
.removeClass("active")
// Find the new one
.filter('[data-page='+ (currentImage + 1) +']')
.filter("[data-page=" + (currentImage + 1) + "]")
// Set it to active
.addClass('active');
.addClass("active");
scrollTocToActive();
updateProgress();
......@@ -270,8 +273,8 @@ function updateProgress(loadPercentage) {
if (loadPercentage === 100) {
$("#progress")
.removeClass('loading')
.find(".load").text('');
.removeClass("loading")
.find(".load").text("");
}
}
......@@ -326,7 +329,7 @@ function setImage(url) {
xhr.onload = function() {
$("#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);
......@@ -378,17 +381,17 @@ function setImage(url) {
function showLeftPage() {
if (settings.direction === 0) {
showPrevPage()
showPrevPage();
} else {
showNextPage()
showNextPage();
}
}
function showRightPage() {
if (settings.direction === 0) {
showNextPage()
showNextPage();
} else {
showPrevPage()
showPrevPage();
}
}
......@@ -504,7 +507,7 @@ function keyHandler(evt) {
updateScale(false);
break;
case kthoom.Key.SPACE:
var container = $('#mainContent');
var container = $("#mainContent");
var atTop = container.scrollTop() === 0;
var atBottom = container.scrollTop() >= container[0].scrollHeight - container.height();
......@@ -577,9 +580,9 @@ function init(filename) {
$(this).toggleClass("icon-menu icon-right");
// We need this in a timeout because if we call it during the CSS transition, IE11 shakes the page ¯\_(ツ)_/¯
setTimeout(function(){
setTimeout(function() {
// Focus on the TOC or the main content area, depending on which is open
$('#main:not(.closed) #mainContent, #sidebar.open #tocView').focus();
$("#main:not(.closed) #mainContent, #sidebar.open #tocView").focus();
scrollTocToActive();
}, 500);
});
......@@ -630,7 +633,7 @@ function init(filename) {
}
// Focus the scrollable area so that keyboard scrolling work as expected
$('#mainContent').focus();
$("#mainContent").focus();
$("#mainImage").click(function(evt) {
// Firefox does not support offsetX/Y so we have to manually calculate
......
......@@ -15,18 +15,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* exported TableActions */
$(function() {
$("#domain_submit").click(function(event) {
event.preventDefault();
$("#domain_add").ajaxForm();
$(this).closest("form").submit();
$.ajax({
$.ajax ({
method:"get",
url: window.location.pathname + "/../../ajax/domainlist",
async: true,
timeout: 900,
success:function(data){
success:function(data) {
$("#domain-table").bootstrapTable("load", data);
}
});
......
......@@ -57,7 +57,7 @@
this.$modalBar = this.$modal.find(".progress-bar");
// Translate texts
this.$modalTitle.text(this.options.modalTitle)
this.$modalTitle.text(this.options.modalTitle);
this.$modalFooter.children("button").text(this.options.modalFooter);
this.$modal.on("hidden.bs.modal", $.proxy(this.reset, this));
......@@ -113,8 +113,7 @@
if (contentType.indexOf("application/json") !== -1) {
var response = $.parseJSON(xhr.responseText);
url = response.location;
}
else{
} else {
url = this.options.redirect_url;
}
window.location.href = url;
......@@ -136,12 +135,10 @@
if (contentType.indexOf("text/plain") !== -1) {
responseText = "<pre>" + responseText + "</pre>";
document.write(responseText);
}
else {
} else {
this.$modalBar.text(responseText);
}
}
else {
} else {
this.$modalBar.text(this.options.modalTitleFailed);
}
},
......
......@@ -41,7 +41,7 @@ See https://github.com/adobe-type-tools/cmap-resources
PDFViewerApplicationOptions.set('sidebarViewOnLoad', 0);
PDFViewerApplicationOptions.set('imageResourcesPath', "{{ url_for('static', filename='css/images/') }}");
PDFViewerApplicationOptions.set('workerSrc', "{{ url_for('static', filename='js/libs/pdf.worker.js') }}");
PDFViewerApplication.open("{{ url_for('serve_book', book_id=pdffile, book_format='pdf') }}");
PDFViewerApplication.open("{{ url_for('web.serve_book', book_id=pdffile, book_format='pdf') }}");
});
</script>
<link rel="resource" type="application/l10n" href="{{ url_for('static', filename='locale/locale.properties') }}">
......
......@@ -3,7 +3,7 @@
<div class="discover">
<h2>{{title}}</h2>
{% if g.user.role_download() %}
<a id="shelf_down" href="{{ url_for('shelf.show_shelf', type=2, shelf_id=shelf.id) }}" class="btn btn-primary">{{ _('Download') }} </a>
<a id="shelf_down" href="{{ url_for('shelf.show_shelf', shelf_type=2, shelf_id=shelf.id) }}" class="btn btn-primary">{{ _('Download') }} </a>
{% endif %}
{% if g.user.is_authenticated %}
{% if (g.user.role_edit_shelfs() and shelf.is_public ) or not shelf.is_public %}
......
......@@ -419,8 +419,8 @@ def get_matching_tags():
title_input = request.args.get('book_title')
include_tag_inputs = request.args.getlist('include_tag')
exclude_tag_inputs = request.args.getlist('exclude_tag')
q = q.filter(db.Books.authors.any(db.func.lower(db.Authors.name).ilike("%" + author_input + "%")),
db.func.lower(db.Books.title).ilike("%" + title_input + "%"))
q = q.filter(db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + author_input + "%")),
func.lower(db.Books.title).ilike("%" + title_input + "%"))
if len(include_tag_inputs) > 0:
for tag in include_tag_inputs:
q = q.filter(db.Books.tags.any(db.Tags.id == tag))
......@@ -858,15 +858,15 @@ def advanced_search():
searchterm = " + ".join(filter(None, searchterm))
q = q.filter()
if author_name:
q = q.filter(db.Books.authors.any(db.func.lower(db.Authors.name).ilike("%" + author_name + "%")))
q = q.filter(db.Books.authors.any(func.lower(db.Authors.name).ilike("%" + author_name + "%")))
if book_title:
q = q.filter(db.func.lower(db.Books.title).ilike("%" + book_title + "%"))
q = q.filter(func.lower(db.Books.title).ilike("%" + book_title + "%"))
if pub_start:
q = q.filter(db.Books.pubdate >= pub_start)
if pub_end:
q = q.filter(db.Books.pubdate <= pub_end)
if publisher:
q = q.filter(db.Books.publishers.any(db.func.lower(db.Publishers.name).ilike("%" + publisher + "%")))
q = q.filter(db.Books.publishers.any(func.lower(db.Publishers.name).ilike("%" + publisher + "%")))
for tag in include_tag_inputs:
q = q.filter(db.Books.tags.any(db.Tags.id == tag))
for tag in exclude_tag_inputs:
......@@ -889,7 +889,7 @@ def advanced_search():
rating_low = int(rating_low) * 2
q = q.filter(db.Books.ratings.any(db.Ratings.rating >= rating_low))
if description:
q = q.filter(db.Books.comments.any(db.func.lower(db.Comments.text).ilike("%" + description + "%")))
q = q.filter(db.Books.comments.any(func.lower(db.Comments.text).ilike("%" + description + "%")))
# search custom culumns
for c in cc:
......@@ -903,7 +903,7 @@ def advanced_search():
db.cc_classes[c.id].value == custom_query))
else:
q = q.filter(getattr(db.Books, 'custom_column_'+str(c.id)).any(
db.func.lower(db.cc_classes[c.id].value).ilike("%" + custom_query + "%")))
func.lower(db.cc_classes[c.id].value).ilike("%" + custom_query + "%")))
q = q.all()
ids = list()
for element in q:
......
......@@ -140,6 +140,7 @@ class emailbase():
else:
raise smtplib.SMTPServerDisconnected('please run connect() first')
@classmethod
def _print_debug(self, *args):
log.debug(args)
......
......@@ -2,7 +2,7 @@
universal = 1
[metadata]
name = calibre-web
name = calibreweb
version= 0.6.3
url = https://github.com/janeczku/calibre-web
project_urls =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment