From d7c357a52d14512ad267c962bd8104ae68765cd3 Mon Sep 17 00:00:00 2001 From: maxgithubprofile <21055122+maxgithubprofile@users.noreply.github.com> Date: Sat, 25 Nov 2023 12:39:47 +0300 Subject: [PATCH] fix: app cache and ws notifications (#1144) --- js/image-uploader.js | 11 ++++++-- js/lib/client/resoursesdb.js | 9 +++++-- js/satolist.js | 49 ++++++++++++++++++----------------- proxy16/node/notifications.js | 2 +- tpls/indexcordova.html.tpl | 1 + 5 files changed, 43 insertions(+), 29 deletions(-) diff --git a/js/image-uploader.js b/js/image-uploader.js index e3016f4319..fef744b33a 100644 --- a/js/image-uploader.js +++ b/js/image-uploader.js @@ -15,11 +15,16 @@ ImageUploader = function(app) { if (1 == 1) { return self.uploadImage({ base64 }, 'peertube').catch(err => { + console.error(err) return self.uploadImage({ base64 }, 'imgur') }).catch(err => { + console.error(err) return self.uploadImage({ base64 }, 'up1') }).then(url => { return Promise.resolve(url) + }).catch(err => { + console.error(err) + return Promise.reject(err) }) } @@ -99,15 +104,17 @@ ImageUploader = function(app) { resolve(url) } - p.fail = function(){ + p.fail = function(e){ app.Logger.info({ actionId: "IMG_PEERTUBE_UPLOAD_FAILED" }); - reject() + reject(e) } app.ajax.run(p) + }).catch((e) => { + reject(e) }); return diff --git a/js/lib/client/resoursesdb.js b/js/lib/client/resoursesdb.js index 3600fed64f..13cbd51818 100644 --- a/js/lib/client/resoursesdb.js +++ b/js/lib/client/resoursesdb.js @@ -144,6 +144,7 @@ ResoursesDB = function(storageName, version, storages){ } self.clearAll = function(key){ + console.log('clearAll', key) return transaction(key).then(items => { const req = items.clear(); @@ -188,8 +189,7 @@ ResoursesDB = function(storageName, version, storages){ if (time >= req.result.cachedTo && !getold) { - if(useapptimeCorrection()){ - + if (useapptimeCorrection()){ var ttime = time - apptimeCorrection @@ -197,6 +197,11 @@ ResoursesDB = function(storageName, version, storages){ reject('delete'); return; } + + if(!getold){ + reject('Data does not exist'); + return; + } } else{ reject('delete'); diff --git a/js/satolist.js b/js/satolist.js index b586a8f7b0..27e2946be3 100644 --- a/js/satolist.js +++ b/js/satolist.js @@ -9777,7 +9777,7 @@ Platform = function (app, listofnodes) { }) }, - getNotifications: function (blockdif) { + getNotifications: function () { var n = this; @@ -9788,9 +9788,7 @@ Platform = function (app, listofnodes) { return self.sdk.node.get.timepr().then(r => { - console.log('n.storage.block', n.storage.block) - - return self.sdk.missed.get(n.storage.block - (blockdif || 0)).catch(e => { + return self.sdk.missed.get(n.storage.block).catch(e => { if(e != 'block'){ return Promise.reject(e) } @@ -9826,6 +9824,8 @@ Platform = function (app, listofnodes) { }).catch(e => { + console.error(e) + n.inited = false; n.loading = false; @@ -18257,7 +18257,7 @@ Platform = function (app, listofnodes) { var socket; var opened = false; var closing = false; - var lost = 0; + var wait = null; self.connected = {}; @@ -19510,7 +19510,11 @@ Platform = function (app, listofnodes) { 'newblocks': { loadMore: function (data, clbk) { - if (data.block <= platform.currentBlock) { + var hb = (data.block || data.height) + + if (hb <= platform.currentBlock) { + + platform.sdk.notifications.wsBlock(hb) if(clbk) clbk(0) @@ -19520,13 +19524,12 @@ Platform = function (app, listofnodes) { var s = platform.sdk.node.transactions; - var dif = platform.currentBlock - data.block + var dif = platform.currentBlock - hb - platform.currentBlock = data.block; + platform.currentBlock = hb; platform.lasttimecheck = new Date() platform.lastblocktime = new Date() - lost = data.block; try{ localStorage['lastblock'] = platform.currentBlock @@ -19540,7 +19543,7 @@ Platform = function (app, listofnodes) { //self.reconnected = platform.currentBlock; - platform.sdk.notifications.wsBlock(data.height) + platform.sdk.notifications.wsBlock(hb) _.each(s.unspent, function (unspents) { _.each(unspents, function (txu) { @@ -19552,7 +19555,7 @@ Platform = function (app, listofnodes) { clbk(dif) - data.difference = platform.currentBlock - (data.block || data.height) + data.difference = platform.currentBlock - hb platform.actions.ws.block(data) @@ -19591,7 +19594,10 @@ Platform = function (app, listofnodes) { loadMore: function (data, clbk) { - if (data.height <= platform.currentBlock) return + if (data.height <= platform.currentBlock) { + platform.sdk.notifications.wsBlock(data.data.height) + return + } var s = platform.sdk.node.transactions; @@ -19604,9 +19610,6 @@ Platform = function (app, listofnodes) { }catch(e){ } - - lost = platform.currentBlock; - platform.sdk.notifications.wsBlock(data.height) @@ -20312,7 +20315,6 @@ Platform = function (app, listofnodes) { } closing = false; - //lost = platform.currentBlock; self.close(); @@ -20387,10 +20389,10 @@ Platform = function (app, listofnodes) { self.connected = {}; - lost = platform.sdk.notifications.storage.block || platform.currentBlock || 0 + //lost = platform.sdk.notifications.storage.block || platform.currentBlock || 0 - console.log("block LOST", lost) - self.getMissed(true).then(() => { + + self.getMissed().then(() => { }) opened = true; @@ -20556,7 +20558,7 @@ Platform = function (app, listofnodes) { self.getMissed = function (initial) { - if (!initial && ((!platform.lastblocktime || (new Date() < platform.lastblocktime.addMinutes(3))) || (lost < 1))) return Promise.resolve() + if (!initial && ((!platform.lastblocktime || (new Date() < platform.lastblocktime.addMinutes(2))))) return Promise.resolve() if (self.loadingMissed) return Promise.resolve() @@ -20564,15 +20566,13 @@ Platform = function (app, listofnodes) { return platform.sdk.node.get.timepr().then(r => { - return platform.sdk.missed.get(lost) + return platform.sdk.missed.get(platform.sdk.notifications.storage.block || platform.currentBlock || 0) }).then(({block, notifications}) => { self.messageHandler(block, function () { self.loadingMissed = false; - lost = 0; - if(!notifications) return lazyEach({ @@ -20591,6 +20591,8 @@ Platform = function (app, listofnodes) { }).catch(e => { + console.error(e) + self.loadingMissed = false; return Promise.reject(e) @@ -20929,7 +20931,6 @@ Platform = function (app, listofnodes) { self.close() self.loadingMissed = false; - lost = 0; } diff --git a/proxy16/node/notifications.js b/proxy16/node/notifications.js index 296b86cd97..370b99486a 100755 --- a/proxy16/node/notifications.js +++ b/proxy16/node/notifications.js @@ -327,7 +327,7 @@ class Notifications{ this.logger.w('system', 'info', `Notification: Firebase autocheck fail`) - destroy() + this.destroy() try{ this.run() diff --git a/tpls/indexcordova.html.tpl b/tpls/indexcordova.html.tpl index 7de1105831..bca8b4e556 100644 --- a/tpls/indexcordova.html.tpl +++ b/tpls/indexcordova.html.tpl @@ -127,5 +127,6 @@ __JSPOST__ +