summaryrefslogtreecommitdiff
path: root/js/app.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2020-04-23 14:18:37 +0300
committerAndrew Dolgov <[email protected]>2020-04-23 14:18:37 +0300
commit2f910e138f8f9ff68ad6a24977a6c90c8725b291 (patch)
tree21efbf4b084a2225ee6b265ab2a3a0388d03a87c /js/app.js
parent4ba712725fd11023b6e95c1c6cc4e401abf53cf1 (diff)
fix App.Offline.get()
Diffstat (limited to 'js/app.js')
-rw-r--r--js/app.js142
1 files changed, 71 insertions, 71 deletions
diff --git a/js/app.js b/js/app.js
index 793c9f9..74c2fca 100644
--- a/js/app.js
+++ b/js/app.js
@@ -248,6 +248,77 @@ const App = {
App.Offline.populateList();
},
+ get: function(bookId, callback) {
+ console.log("offline cache: " + bookId);
+
+ $.post("backend.php", {op: "getinfo", id: bookId}, function(data) {
+
+ if (data) {
+ const cacheId = 'epube-book.' + bookId;
+
+ localforage.setItem(cacheId, data).then(function(data) {
+
+ console.log(cacheId + ' got data');
+
+ const promises = [];
+
+ promises.push(fetch('backend.php?op=download&id=' + data.epub_id, {credentials: 'same-origin'}).then(function(resp) {
+ if (resp.status == 200) {
+ console.log(cacheId + ' got book');
+
+ callback();
+
+ localforage.setItem(cacheId + '.book', resp.blob());
+ }
+ }));
+
+ promises.push(fetch("backend.php?op=getpagination&id=" + data.epub_id, {credentials: 'same-origin'}).then(function(resp) {
+ if (resp.status == 200) {
+ console.log(cacheId + ' got pagination');
+
+ resp.text().then(function(text) {
+ localforage.setItem(cacheId + '.locations', JSON.parse(text));
+ });
+ }
+ }));
+
+ promises.push(fetch("backend.php?op=getlastread&id=" + data.epub_id, {credentials: 'same-origin'}).then(function(resp) {
+ if (resp.status == 200) {
+ console.log(cacheId + ' got lastread');
+ resp.text().then(function(text) {
+ localforage.setItem(cacheId + '.lastread', JSON.parse(text));
+ });
+ }
+ }));
+
+ if (data.has_cover) {
+
+ promises.push(fetch("backend.php?op=cover&id=" + bookId, {credentials: 'same-origin'}).then(function(resp) {
+
+ if (resp.status == 200) {
+ console.log(cacheId + ' got cover');
+ localforage.setItem(cacheId + '.cover', resp.blob());
+ }
+
+ }));
+
+ }
+
+ Promise.all(promises).then(function() {
+ $(".dl-progress")
+ .show()
+ .html("Finished downloading <b>" + data.title + "</b>");
+
+ window.clearTimeout(App._dl_progress_timeout);
+
+ App._dl_progress_timeout = window.setTimeout(function() {
+ $(".dl-progress").fadeOut();
+ }, 5*1000);
+ });
+ });
+ }
+ });
+ },
getAll: function() {
if (confirm("Download all books on this page?")) {
@@ -476,75 +547,4 @@ const App = {
});
}
},
- get: function(bookId, callback) {
- console.log("offline cache: " + bookId);
-
- $.post("backend.php", {op: "getinfo", id: bookId}, function(data) {
-
- if (data) {
- const cacheId = 'epube-book.' + bookId;
-
- localforage.setItem(cacheId, data).then(function(data) {
-
- console.log(cacheId + ' got data');
-
- const promises = [];
-
- promises.push(fetch('backend.php?op=download&id=' + data.epub_id, {credentials: 'same-origin'}).then(function(resp) {
- if (resp.status == 200) {
- console.log(cacheId + ' got book');
-
- callback();
-
- localforage.setItem(cacheId + '.book', resp.blob());
- }
- }));
-
- promises.push(fetch("backend.php?op=getpagination&id=" + data.epub_id, {credentials: 'same-origin'}).then(function(resp) {
- if (resp.status == 200) {
- console.log(cacheId + ' got pagination');
-
- resp.text().then(function(text) {
- localforage.setItem(cacheId + '.locations', JSON.parse(text));
- });
- }
- }));
-
- promises.push(fetch("backend.php?op=getlastread&id=" + data.epub_id, {credentials: 'same-origin'}).then(function(resp) {
- if (resp.status == 200) {
- console.log(cacheId + ' got lastread');
- resp.text().then(function(text) {
- localforage.setItem(cacheId + '.lastread', JSON.parse(text));
- });
- }
- }));
-
- if (data.has_cover) {
-
- promises.push(fetch("backend.php?op=cover&id=" + bookId, {credentials: 'same-origin'}).then(function(resp) {
-
- if (resp.status == 200) {
- console.log(cacheId + ' got cover');
- localforage.setItem(cacheId + '.cover', resp.blob());
- }
-
- }));
-
- }
-
- Promise.all(promises).then(function() {
- $(".dl-progress")
- .show()
- .html("Finished downloading <b>" + data.title + "</b>");
-
- window.clearTimeout(App._dl_progress_timeout);
-
- App._dl_progress_timeout = window.setTimeout(function() {
- $(".dl-progress").fadeOut();
- }, 5*1000);
- });
- });
- }
- });
- },
};