Skip to content

Commit

Permalink
Added swipe support for comic reader and txt reader (#925)
Browse files Browse the repository at this point in the history
Bugfix for txt file not present on serving file
  • Loading branch information
OzzieIsaacs committed Jan 24, 2021
1 parent 0b32738 commit d2ad78e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
8 changes: 8 additions & 0 deletions cps/static/js/kthoom.js
Expand Up @@ -635,6 +635,14 @@ function init(filename) {
// Focus the scrollable area so that keyboard scrolling work as expected
$("#mainContent").focus();

$("#mainContent").swipe( {
swipeRight:function() {
showLeftPage();
},
swipeLeft:function() {
showRightPage();
},
});
$("#mainImage").click(function(evt) {
// Firefox does not support offsetX/Y so we have to manually calculate
// where the user clicked in the image.
Expand Down
8 changes: 2 additions & 6 deletions cps/templates/readcbr.html
Expand Up @@ -13,14 +13,10 @@
<link rel="stylesheet" href="{{ url_for('static', filename='css/kthoom.css') }}" type="text/css"/>

<script src="{{ url_for('static', filename='js/libs/jquery.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/libs/plugins.js') }}"></script>
<script src="{{ url_for('static', filename='js/libs/screenfull.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/io/bytestream.js') }}"></script>
<script src="{{ url_for('static', filename='js/io/bytebuffer.js') }}"></script>
<script src="{{ url_for('static', filename='js/io/bitstream.js') }}"></script>
<script src="{{ url_for('static', filename='js/archive/archive.js') }}"></script>
<script src="{{ url_for('static', filename='js/archive/rarvm.js') }}"></script>
<script src="{{ url_for('static', filename='js/archive/unrar5.js') }}"></script>
<script src="{{ url_for('static', filename='js/kthoom.js') }}"></script>
<script src="{{ url_for('static', filename='js/archive/archive.js') }}"></script>
<script>
var updateArrows = function() {
if ($('input[name="direction"]:checked').val() === "0") {
Expand Down
9 changes: 9 additions & 0 deletions cps/templates/readtxt.html
Expand Up @@ -12,6 +12,7 @@
<!-- EPUBJS Renderer -->
<!--<script src="../build/epub.js"></script>-->
<script src="{{ url_for('static', filename='js/libs/jquery.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/libs/plugins.js') }}"></script>

<style type="text/css">

Expand Down Expand Up @@ -97,6 +98,14 @@
$( "#right" ).click(function() {
nextPage();
});
$("#readmain").swipe( {
swipeRight:function() {
prevPage();
},
swipeLeft:function() {
nextPage();
},
});
//bind mouse
$(window).bind('DOMMouseScroll mousewheel', function(event) {
var delta = 0;
Expand Down
15 changes: 9 additions & 6 deletions cps/web.py
Expand Up @@ -1198,7 +1198,7 @@ def serve_book(book_id, book_format, anyname):
book = calibre_db.get_book(book_id)
data = calibre_db.get_book_format(book_id, book_format.upper())
if not data:
abort(404)
return "File not in Database"
log.info('Serving book: %s', data.name)
if config.config_use_google_drive:
headers = Headers()
Expand All @@ -1207,11 +1207,14 @@ def serve_book(book_id, book_format, anyname):
return do_gdrive_download(df, headers, (book_format.upper() == 'TXT'))
else:
if book_format.upper() == 'TXT':
rawdata = open(os.path.join(config.config_calibre_dir, book.path, data.name + "." + book_format),
"rb").read()
result = chardet.detect(rawdata)
return make_response(
rawdata.decode(result['encoding']).encode('utf-8'))
try:
rawdata = open(os.path.join(config.config_calibre_dir, book.path, data.name + "." + book_format),
"rb").read()
result = chardet.detect(rawdata)
return make_response(
rawdata.decode(result['encoding']).encode('utf-8'))
except FileNotFoundError:
return "File Not Found"
return send_from_directory(os.path.join(config.config_calibre_dir, book.path), data.name + "." + book_format)


Expand Down

0 comments on commit d2ad78e

Please sign in to comment.