From ef029c4d62fc86764947bd4590c7726be6e4b30b Mon Sep 17 00:00:00 2001 From: Chronos Date: Wed, 3 May 2017 07:13:25 +0300 Subject: [PATCH 01/88] BbtcRelax memento plugin --- BtcRelaxPlugin.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 BtcRelaxPlugin.js diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js new file mode 100644 index 0000000..ed9d01c --- /dev/null +++ b/BtcRelaxPlugin.js @@ -0,0 +1,29 @@ +function BtcRelaxApi(server, token) +{ + this.server = server; + this.token = token; +} + +//BtcRelaxApi.prototype.addNew = function(query) { +// var result = http().get("https://api.discogs.com/database/search?q=" + encodeURIComponent(query) + "&key=" + this.apiKey + "&secret=" + this.apiSecret + "&type=" + this.type); +// var json = JSON.parse(result.body); +// return json.results; +//} + + +BtcRelaxApi.prototype.prepareEntity = function(vEntry) { + var loc = vEntry.field("Loc"); + var nLat = Math.round(loc.lat * 1000000) / 1000000; + var nLng = Math.round(loc.lng * 1000000) / 1000000; + var vAdv = "dummyAdv"; + var vPrice = "100"; + var vRegion = "dummyRegion"; + var nUrl = vEntry.field("PublicURL"); + var commands = + '[{"type":"item_add","inf":{"lat":"' + nLat + '","lng":"' + nLng + '","link":"' + nUrl + + '","advName":"' + vAdv + '","price":"' + vPrice + '","region":"' + vRegion + '"}}]'; + return commands; +} + + + From fc77794338d10d4bebf3f9d12483f35e750be385 Mon Sep 17 00:00:00 2001 From: Chronos Date: Wed, 3 May 2017 07:14:25 +0300 Subject: [PATCH 02/88] Revert "BbtcRelax memento plugin" This reverts commit ef029c4d62fc86764947bd4590c7726be6e4b30b. --- BtcRelaxPlugin.js | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 BtcRelaxPlugin.js diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js deleted file mode 100644 index ed9d01c..0000000 --- a/BtcRelaxPlugin.js +++ /dev/null @@ -1,29 +0,0 @@ -function BtcRelaxApi(server, token) -{ - this.server = server; - this.token = token; -} - -//BtcRelaxApi.prototype.addNew = function(query) { -// var result = http().get("https://api.discogs.com/database/search?q=" + encodeURIComponent(query) + "&key=" + this.apiKey + "&secret=" + this.apiSecret + "&type=" + this.type); -// var json = JSON.parse(result.body); -// return json.results; -//} - - -BtcRelaxApi.prototype.prepareEntity = function(vEntry) { - var loc = vEntry.field("Loc"); - var nLat = Math.round(loc.lat * 1000000) / 1000000; - var nLng = Math.round(loc.lng * 1000000) / 1000000; - var vAdv = "dummyAdv"; - var vPrice = "100"; - var vRegion = "dummyRegion"; - var nUrl = vEntry.field("PublicURL"); - var commands = - '[{"type":"item_add","inf":{"lat":"' + nLat + '","lng":"' + nLng + '","link":"' + nUrl + - '","advName":"' + vAdv + '","price":"' + vPrice + '","region":"' + vRegion + '"}}]'; - return commands; -} - - - From 5db7f2964a604a19776600507e38836f37fdc6c2 Mon Sep 17 00:00:00 2001 From: Chronos Date: Wed, 3 May 2017 07:17:20 +0300 Subject: [PATCH 03/88] BbtcRelax memento plugin --- BtcRelaxPlugin.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 BtcRelaxPlugin.js diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js new file mode 100644 index 0000000..c6a9439 --- /dev/null +++ b/BtcRelaxPlugin.js @@ -0,0 +1,30 @@ +function BtcRelaxApi(server, token) +{ + this.server = server; + this.token = token; +} + +//BtcRelaxApi.prototype.addNew = function(query) { +// var result = http().get("https://api.discogs.com/database/search?q=" + encodeURIComponent(query) + "&key=" + this.apiKey + "&secret=" + this.apiSecret + "&type=" + this.type); +// var json = JSON.parse(result.body); +// return json.results; +//} + + +BtcRelaxApi.prototype.prepareEntity(vEntry) +{ + var loc = vEntry.field("Loc"); + var nLat = Math.round(loc.lat * 1000000) / 1000000; + var nLng = Math.round(loc.lng * 1000000) / 1000000; + var vAdv = "dummyAdv"; + var vPrice = "100"; + var vRegion = "dummyRegion"; + var nUrl = vEntry.field("PublicURL"); + var commands = + '[{"type":"item_add","inf":{"lat":"' + nLat + '","lng":"' + nLng + '","link":"' + nUrl + + '","advName":"' + vAdv + '","price":"' + vPrice + '","region":"' + vRegion + '"}}]'; + return commands; +} + + + From a4899409f6bb10c5b929ae445d09e5242cdd1fb7 Mon Sep 17 00:00:00 2001 From: Chronos Date: Sun, 7 May 2017 11:05:57 +0300 Subject: [PATCH 04/88] First release 1.2.2.1 Added bookmark.JSON --- BtcRelaxPlugin.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index c6a9439..ed9d01c 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -11,8 +11,7 @@ function BtcRelaxApi(server, token) //} -BtcRelaxApi.prototype.prepareEntity(vEntry) -{ +BtcRelaxApi.prototype.prepareEntity = function(vEntry) { var loc = vEntry.field("Loc"); var nLat = Math.round(loc.lat * 1000000) / 1000000; var nLng = Math.round(loc.lng * 1000000) / 1000000; From 1d989340e37de4f07fa49137e459c5d01739a30c Mon Sep 17 00:00:00 2001 From: godchronos Date: Wed, 19 Jul 2017 16:19:53 +0000 Subject: [PATCH 05/88] Delete BtcRelaxPlugin.js --- BtcRelaxPlugin.js | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 BtcRelaxPlugin.js diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js deleted file mode 100644 index ed9d01c..0000000 --- a/BtcRelaxPlugin.js +++ /dev/null @@ -1,29 +0,0 @@ -function BtcRelaxApi(server, token) -{ - this.server = server; - this.token = token; -} - -//BtcRelaxApi.prototype.addNew = function(query) { -// var result = http().get("https://api.discogs.com/database/search?q=" + encodeURIComponent(query) + "&key=" + this.apiKey + "&secret=" + this.apiSecret + "&type=" + this.type); -// var json = JSON.parse(result.body); -// return json.results; -//} - - -BtcRelaxApi.prototype.prepareEntity = function(vEntry) { - var loc = vEntry.field("Loc"); - var nLat = Math.round(loc.lat * 1000000) / 1000000; - var nLng = Math.round(loc.lng * 1000000) / 1000000; - var vAdv = "dummyAdv"; - var vPrice = "100"; - var vRegion = "dummyRegion"; - var nUrl = vEntry.field("PublicURL"); - var commands = - '[{"type":"item_add","inf":{"lat":"' + nLat + '","lng":"' + nLng + '","link":"' + nUrl + - '","advName":"' + vAdv + '","price":"' + vPrice + '","region":"' + vRegion + '"}}]'; - return commands; -} - - - From d05ca7ee6a283b93a496626217adbee6815e6d49 Mon Sep 17 00:00:00 2001 From: godchronos Date: Wed, 19 Jul 2017 16:21:30 +0000 Subject: [PATCH 06/88] Create BtcRelaxPlugin.js --- BtcRelaxPlugin.js | 167 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 BtcRelaxPlugin.js diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js new file mode 100644 index 0000000..fd96de1 --- /dev/null +++ b/BtcRelaxPlugin.js @@ -0,0 +1,167 @@ +function BtcRelaxApi( v_server , v_tokenId, v_tokenKey, v_readOnly ) +{ + this.server = v_server; + this.tokenId = v_tokenId; + this.tokenKey = v_tokenKey; + this.isReadOnly = v_readOnly; +} + + +BtcRelaxApi.prototype.prepareEntity = function (vEntry) { + var nLat = vEntry.field("Latitude"); + var nLng = vEntry.field("Longitude"); + var vAdv = vEntry.field("FrontTitle"); + var vPrice = vEntry.field("TotalPrice"); + var cReg= vEntry.field("Regions"); + var vDescr=vEntry.field("PointDescription"); + var vRegCounts=cReg.length; + var vRegion = null; + var commands = null; + if(vRegCounts>0) + { + var regObj =cReg[0]; + vRegion=this.getRegionPath(regObj); + log("Region name:"+vRegion); + var nUrl = vEntry.field("PublicURL"); + commands = + '[{"type":"AddPoint","inf":{"lat":"' + nLat + '","lng":"' + nLng + '","link":"' + nUrl + + '","advName":"' + vAdv + '","price":"' + vPrice + '","region":"' + vRegion + '","descr":"' + vDescr + '"}}]'; + }; + return commands; +}; + +BtcRelaxApi.prototype.syncEntry = function(vEntry) +{ + var isSent=vEntry.field("isSent"); + var ServerState=vEntry.field("ServerStatus"); + if (isSent==false) + { + if (ServerState=="ReadyToSend" ) { if (!this.isReadOnly) { this.newEntry(vEntry);}; }; + } else{ this.getEntryState(vEntry) }; +} + +BtcRelaxApi.prototype.newEntry = function(vEntry) +{ + var msg=vEntry.field("ServerRequest"); + var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; + log("Calling URL:"+callUrl); + var result=http().get(callUrl+encodeURIComponent(msg)); + if(result.code==200) + { + var json=JSON.parse(result.body); + log("Catched:"+json.body); + if (json.bookmarkId !== undefined) + { + var pointId = json.bookmarkId; + if (pointId>0) + { + vEntry.set("isSent",true); + vEntry.set("BookmarkId",pointId); + }; + }; + }; +} + +BtcRelaxApi.prototype.getEntryState = function(vEntry) +{ + var pointId=vEntry.field("BookmarkId"); + if (pointId>0) + { + + var msg = '[{"type":"GetPointState","bookmarkId":"' + pointId + '"}]'; + var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; + vEntry.set("ServerRequest",callUrl+encodeURIComponent(msg)); + var result=http().get(callUrl+encodeURIComponent(msg)); + if(result.code==200) { + var json=JSON.parse(result.body); + var state =json.serverState; + vEntry.set("ServerStatus",state); + }; + }; +} + +BtcRelaxApi.prototype.syncEntries = function() +{ + var clib = lib(); + var entries =clib.entries(); + var count =entries.length; + log("For validate:"+count); + for (i=0;i0) + { + res=res+", "+this.getRegionPath(entry.field("ParentRegion")[0]); + }; + return res; +}; + +// var bra=new BtcRelaxApi("http://shop.btcrelax.xyz/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); +// bra.validateEntries(); +// bra.syncEntries(); From af8c6dcca8d2db527c1b401255b66c815de9ac1c Mon Sep 17 00:00:00 2001 From: godchronos Date: Fri, 21 Jul 2017 12:12:09 +0000 Subject: [PATCH 07/88] Update BtcRelaxPlugin.js Remove check for state before send --- BtcRelaxPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index fd96de1..eb23adc 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -36,7 +36,7 @@ BtcRelaxApi.prototype.syncEntry = function(vEntry) var ServerState=vEntry.field("ServerStatus"); if (isSent==false) { - if (ServerState=="ReadyToSend" ) { if (!this.isReadOnly) { this.newEntry(vEntry);}; }; + if (!this.isReadOnly) { this.newEntry(vEntry);}; } else{ this.getEntryState(vEntry) }; } From e00a3483432b44a442e9177353f550adaed14d52 Mon Sep 17 00:00:00 2001 From: godchronos Date: Fri, 21 Jul 2017 13:21:26 +0000 Subject: [PATCH 08/88] Update BtcRelaxPlugin.js --- BtcRelaxPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index eb23adc..f943012 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -44,7 +44,7 @@ BtcRelaxApi.prototype.newEntry = function(vEntry) { var msg=vEntry.field("ServerRequest"); var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; - log("Calling URL:"+callUrl); + log("Calling URL:"+callUrl+msg); var result=http().get(callUrl+encodeURIComponent(msg)); if(result.code==200) { From a6e8dc77447ab61b917ec7c49f869206dfc4bf98 Mon Sep 17 00:00:00 2001 From: godchronos Date: Fri, 21 Jul 2017 13:55:09 +0000 Subject: [PATCH 09/88] Update BtcRelaxPlugin.js --- BtcRelaxPlugin.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index f943012..7124bbe 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -49,15 +49,15 @@ BtcRelaxApi.prototype.newEntry = function(vEntry) if(result.code==200) { var json=JSON.parse(result.body); - log("Catched:"+json.body); - if (json.bookmarkId !== undefined) - { + log("Catched:"+json.body); + if (json.bookmarkId !== undefined) + { var pointId = json.bookmarkId; - if (pointId>0) - { - vEntry.set("isSent",true); - vEntry.set("BookmarkId",pointId); - }; + if (pointId>0) + { + vEntry.set("isSent",true); + vEntry.set("BookmarkId",pointId); + }; }; }; } @@ -165,3 +165,6 @@ BtcRelaxApi.prototype.getRegionPath = function(entry) // var bra=new BtcRelaxApi("http://shop.btcrelax.xyz/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); // bra.validateEntries(); // bra.syncEntries(); + +//var cE = entry(); +//bra.syncEntry(cE); From e73f4de1a85ca339999d2710c18fc5347e08165d Mon Sep 17 00:00:00 2001 From: Chronos Date: Sat, 22 Jul 2017 14:31:37 +0300 Subject: [PATCH 10/88] Global functions Signed-off-by:Chronos --- BtcRelaxPlugin.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 7124bbe..e9e0e70 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -162,9 +162,17 @@ BtcRelaxApi.prototype.getRegionPath = function(entry) return res; }; -// var bra=new BtcRelaxApi("http://shop.btcrelax.xyz/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); -// bra.validateEntries(); -// bra.syncEntries(); +function syncAll() +{ + var bra=new BtcRelaxApi("http://shop.btcrelax.xyz/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); + bra.validateEntries(); + bra.syncEntries(); +} -//var cE = entry(); -//bra.syncEntry(cE); +function syncCurrent() +{ + var bra=new BtcRelaxApi("http://shop.btcrelax.xyz/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); + var cE = entry(); + bra.validateEntry(cE); + bra.syncEntry(cE); +} From 6cccbd5c989d4c007baab69a7fa15fe0bed6199c Mon Sep 17 00:00:00 2001 From: Chronos Date: Sat, 22 Jul 2017 14:31:59 +0300 Subject: [PATCH 11/88] Global functions Signed-off-by:Chronos From f80e2ae7b8d48e4d883dd1a96f84c37b12962408 Mon Sep 17 00:00:00 2001 From: Chronos Date: Sat, 22 Jul 2017 15:53:36 +0300 Subject: [PATCH 12/88] Global functions Signed-off-by:Chronos --- BtcRelaxPlugin.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index e9e0e70..a286f00 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -24,8 +24,8 @@ BtcRelaxApi.prototype.prepareEntity = function (vEntry) { log("Region name:"+vRegion); var nUrl = vEntry.field("PublicURL"); commands = - '[{"type":"AddPoint","inf":{"lat":"' + nLat + '","lng":"' + nLng + '","link":"' + nUrl + - '","advName":"' + vAdv + '","price":"' + vPrice + '","region":"' + vRegion + '","descr":"' + vDescr + '"}}]'; + '{"type":"AddPoint","inf":{"lat":"' + nLat + '","lng":"' + nLng + '","link":"' + nUrl + + '","advName":"' + vAdv + '","price":"' + vPrice + '","region":"' + vRegion + '","descr":"' + vDescr + '"}}'; }; return commands; }; @@ -129,7 +129,7 @@ BtcRelaxApi.prototype.validateEntry = function(vEntry) var nCmd=this.prepareEntity(vEntry); if (nCmd!=null) { - vEntry.set("ServerStatus","ReadyToSend"); + vEntry.set("ServerStatus","Ready"); vEntry.set("BookmarkId",0); vEntry.set("ServerRequest",nCmd); }; From a3709b16ba79ec48cee5118969f3d5fc20a349a5 Mon Sep 17 00:00:00 2001 From: Chronos Date: Sat, 22 Jul 2017 16:11:19 +0300 Subject: [PATCH 13/88] Global functions Signed-off-by:Chronos --- BtcRelaxPlugin.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index a286f00..72ab0ee 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -43,7 +43,7 @@ BtcRelaxApi.prototype.syncEntry = function(vEntry) BtcRelaxApi.prototype.newEntry = function(vEntry) { var msg=vEntry.field("ServerRequest"); - var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; + var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; log("Calling URL:"+callUrl+msg); var result=http().get(callUrl+encodeURIComponent(msg)); if(result.code==200) @@ -67,9 +67,8 @@ BtcRelaxApi.prototype.getEntryState = function(vEntry) var pointId=vEntry.field("BookmarkId"); if (pointId>0) { - - var msg = '[{"type":"GetPointState","bookmarkId":"' + pointId + '"}]'; - var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; + var msg = '{"type":"GetPointState","bookmarkId":"' + pointId + '"}'; + var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; vEntry.set("ServerRequest",callUrl+encodeURIComponent(msg)); var result=http().get(callUrl+encodeURIComponent(msg)); if(result.code==200) { From 0932eb56e4cf6483e593576aba7f5e90e8b15e68 Mon Sep 17 00:00:00 2001 From: Chronos Date: Mon, 24 Jul 2017 03:27:29 +0300 Subject: [PATCH 14/88] Create support for dynamic server name Signed-off-by:Chronos --- BtcRelaxPlugin.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 72ab0ee..14dff5d 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -161,16 +161,16 @@ BtcRelaxApi.prototype.getRegionPath = function(entry) return res; }; -function syncAll() +function syncAll(vSrever) { - var bra=new BtcRelaxApi("http://shop.btcrelax.xyz/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); + var bra=new BtcRelaxApi( vSrever + "/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); bra.validateEntries(); bra.syncEntries(); } -function syncCurrent() +function syncCurrent(vSrever) { - var bra=new BtcRelaxApi("http://shop.btcrelax.xyz/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); + var bra=new BtcRelaxApi( vSrever + "/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); var cE = entry(); bra.validateEntry(cE); bra.syncEntry(cE); From f7bba9cbb051314cc54754cb470f08042d31b316 Mon Sep 17 00:00:00 2001 From: godchronos Date: Mon, 24 Jul 2017 14:24:31 +0300 Subject: [PATCH 15/88] Update BtcRelaxPlugin.js Added message notifications to user --- BtcRelaxPlugin.js | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 14dff5d..23e20ce 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -49,15 +49,15 @@ BtcRelaxApi.prototype.newEntry = function(vEntry) if(result.code==200) { var json=JSON.parse(result.body); - log("Catched:"+json.body); if (json.bookmarkId !== undefined) { var pointId = json.bookmarkId; - if (pointId>0) - { - vEntry.set("isSent",true); - vEntry.set("BookmarkId",pointId); - }; + message("Succesfully added point id:"+pointId); + if (pointId>0) + { + vEntry.set("isSent",true); + vEntry.set("BookmarkId",pointId); + }; }; }; } @@ -74,8 +74,17 @@ BtcRelaxApi.prototype.getEntryState = function(vEntry) if(result.code==200) { var json=JSON.parse(result.body); var state =json.serverState; - vEntry.set("ServerStatus",state); - }; + var oldState = vEntry.field('ServerStatus'); + vEntry.set("ServerStatus",state); + if (state !== oldState) + { + message("Point id:"+pointId+" changed!"); + }; + } + else + { + message("Error getting state for point id:"+pointId); + }; }; } @@ -112,10 +121,10 @@ BtcRelaxApi.prototype.validateEntry = function(vEntry) {AdvertiseTitle=AdvertiseTitle+" & "+linkedEntry.field("ItemTypeName");} vTotalPrice=vTotalPrice+linkedEntry.field("DefaultPrice"); }; - log("Name:"+AdvertiseTitle+":TotalPrice:"+vTotalPrice); var urlToPic = vEntry.field("PublicURL"); log("URL:"+urlToPic); - if (urlToPic===''){ log("Url not found");} + if (urlToPic==='') + { message("Url for name:"+AdvertiseTitle+" and total price:"+vTotalPrice+" not found");} else { vEntry.set("FrontTitle",AdvertiseTitle); var loc = vEntry.field("Loc"); @@ -127,11 +136,11 @@ BtcRelaxApi.prototype.validateEntry = function(vEntry) vEntry.set("FrontTitle",AdvertiseTitle); var nCmd=this.prepareEntity(vEntry); if (nCmd!=null) - { - vEntry.set("ServerStatus","Ready"); - vEntry.set("BookmarkId",0); - vEntry.set("ServerRequest",nCmd); - }; + { + vEntry.set("ServerStatus","Ready"); + vEntry.set("BookmarkId",0); + vEntry.set("ServerRequest",nCmd); + }; }; }; }; @@ -161,16 +170,16 @@ BtcRelaxApi.prototype.getRegionPath = function(entry) return res; }; -function syncAll(vSrever) +function syncAll(vServer) { - var bra=new BtcRelaxApi( vSrever + "/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); + var bra=new BtcRelaxApi( vServer + "/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); bra.validateEntries(); bra.syncEntries(); } -function syncCurrent(vSrever) +function syncCurrent(vServer) { - var bra=new BtcRelaxApi( vSrever + "/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); + var bra=new BtcRelaxApi( vServer + "/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); var cE = entry(); bra.validateEntry(cE); bra.syncEntry(cE); From 88a1cbeca3fcd00f4a3c40ea50aa530e6b1cdb24 Mon Sep 17 00:00:00 2001 From: godchronos Date: Tue, 1 Aug 2017 10:35:26 +0000 Subject: [PATCH 16/88] Update BtcRelaxPlugin.js refreshPub and refreshAllPubs methods add. While divide entity Bookmark and publication. --- BtcRelaxPlugin.js | 123 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 94 insertions(+), 29 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 23e20ce..557565e 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -37,7 +37,7 @@ BtcRelaxApi.prototype.syncEntry = function(vEntry) if (isSent==false) { if (!this.isReadOnly) { this.newEntry(vEntry);}; - } else{ this.getEntryState(vEntry) }; + }; } BtcRelaxApi.prototype.newEntry = function(vEntry) @@ -51,41 +51,77 @@ BtcRelaxApi.prototype.newEntry = function(vEntry) var json=JSON.parse(result.body); if (json.bookmarkId !== undefined) { - var pointId = json.bookmarkId; - message("Succesfully added point id:"+pointId); - if (pointId>0) + var pointId = json.bookmarkId; + if (pointId>0) { - vEntry.set("isSent",true); - vEntry.set("BookmarkId",pointId); - }; + this.newPublication(vEntry, pointId) + } + else + { + message('Inadequate response from Server while sending!'); + log("Entry with URL:"+vEntry.field("PublicURL")+" rejected by server!"); + exit(); + } }; }; } -BtcRelaxApi.prototype.getEntryState = function(vEntry) +BtcRelaxApi.prototype.newPublication = function(vEntry, vPointId) +{ + var isPubCount = vEntrty.field("PublicationEntry").length; + if(isPubCount===0) + { + var pubLib=libByName("Publication"); + var newPub = new Object(); + var vRegionTitle=this.getRegionPath(vEntry); + newPub["BookmarkId"]=vPointId; + newPub["FrontShopTitle"]=vEntry.field("FrontTitle"); + newPub["Photos"]=vEntry.field("PublicURL"); + var pub=pubLib.create(newPub); + pub.set("Location",vEntry.field("Loc")); + pub.set("Price",vEntry.field("TotalPrice")); + vEntry.set("PublicationEntry",pub); + vEntry.set("isSent",true); + } + else + { + log("Entry with URL:"+vEntry.field("PublicURL")+" already has publication!"); + } +} + +BtcRelaxApi.prototype.prepareRequest = function(vPub) { - var pointId=vEntry.field("BookmarkId"); - if (pointId>0) - { - var msg = '{"type":"GetPointState","bookmarkId":"' + pointId + '"}'; - var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; - vEntry.set("ServerRequest",callUrl+encodeURIComponent(msg)); - var result=http().get(callUrl+encodeURIComponent(msg)); - if(result.code==200) { + var pointId=vPub.field("BookmarkId"); + if (pointId>0) + { + var msg = '{"type":"GetPointState","bookmarkId":"' + pointId + '"}'; + var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; + vPub.set("Request",callUrl+encodeURIComponent(msg)); + message("Prepared BookmarkId:"+pointId); + } + else + { + message("Error getting state for point id:"+pointId); + }; +} + +BtcRelaxApi.prototype.getPublicationState = function(vPub) +{ + this.prepareRequest(vPub); + var vRequest = vPub.field("Request"); + var result=http().get(vRequest); + vPub.set("Response",result); + if(result.code==200) { var json=JSON.parse(result.body); var state =json.serverState; - var oldState = vEntry.field('ServerStatus'); - vEntry.set("ServerStatus",state); + message("Returned status:"+state); + var oldState = vPub.field('Status'); + vPub.set("Status",state); if (state !== oldState) { - message("Point id:"+pointId+" changed!"); + message("BookmarkId:"+pointId+" changed!"); }; - } - else - { - message("Error getting state for point id:"+pointId); - }; - }; + }; } BtcRelaxApi.prototype.syncEntries = function() @@ -137,8 +173,6 @@ BtcRelaxApi.prototype.validateEntry = function(vEntry) var nCmd=this.prepareEntity(vEntry); if (nCmd!=null) { - vEntry.set("ServerStatus","Ready"); - vEntry.set("BookmarkId",0); vEntry.set("ServerRequest",nCmd); }; }; @@ -147,8 +181,8 @@ BtcRelaxApi.prototype.validateEntry = function(vEntry) BtcRelaxApi.prototype.validateEntries = function() { - var clib = lib(); - var entries = clib.entries(); + var clib = lib(); + var entries = clib.entries(); var count =entries.length; log("For validate:"+count); for(var i=0;i Date: Tue, 1 Aug 2017 10:35:46 +0000 Subject: [PATCH 17/88] divide entity Bookmark and publication. refreshPub and refreshAllPubs methods add. While divide entity Bookmark and publication. From d65f5e6171ffea2ef313745854d029f10d80b001 Mon Sep 17 00:00:00 2001 From: godchronos Date: Tue, 1 Aug 2017 10:48:00 +0000 Subject: [PATCH 18/88] Logging extending Add loging while work with pub object --- BtcRelaxPlugin.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 557565e..86182bd 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -33,7 +33,6 @@ BtcRelaxApi.prototype.prepareEntity = function (vEntry) { BtcRelaxApi.prototype.syncEntry = function(vEntry) { var isSent=vEntry.field("isSent"); - var ServerState=vEntry.field("ServerStatus"); if (isSent==false) { if (!this.isReadOnly) { this.newEntry(vEntry);}; @@ -94,10 +93,10 @@ BtcRelaxApi.prototype.prepareRequest = function(vPub) var pointId=vPub.field("BookmarkId"); if (pointId>0) { - var msg = '{"type":"GetPointState","bookmarkId":"' + pointId + '"}'; + log("Preparing bookmark Id:"+pointId); + var msg = '{"type":"GetPointState","bookmarkId":"' + pointId + '"}'; var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; vPub.set("Request",callUrl+encodeURIComponent(msg)); - message("Prepared BookmarkId:"+pointId); } else { @@ -114,7 +113,7 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) if(result.code==200) { var json=JSON.parse(result.body); var state =json.serverState; - message("Returned status:"+state); + log("Returned status:"+state); var oldState = vPub.field('Status'); vPub.set("Status",state); if (state !== oldState) From 052d27a4863fcbaf6196dfce1db402602bc9f6f5 Mon Sep 17 00:00:00 2001 From: godchronos Date: Wed, 2 Aug 2017 19:07:59 +0300 Subject: [PATCH 19/88] Added loging of result code while insert new point --- BtcRelaxPlugin.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 86182bd..49283f0 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -47,7 +47,9 @@ BtcRelaxApi.prototype.newEntry = function(vEntry) var result=http().get(callUrl+encodeURIComponent(msg)); if(result.code==200) { - var json=JSON.parse(result.body); + var rcode=result.code; + log("Answer result:"+rcode); + var json=JSON.parse(result.body); if (json.bookmarkId !== undefined) { var pointId = json.bookmarkId; From d9083daaec3b963a3b77a232f82d1d17e09a9bc4 Mon Sep 17 00:00:00 2001 From: godchronos Date: Fri, 4 Aug 2017 01:31:12 +0300 Subject: [PATCH 20/88] Added informing --- BtcRelaxPlugin.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 49283f0..a4096dd 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -78,6 +78,7 @@ BtcRelaxApi.prototype.newPublication = function(vEntry, vPointId) newPub["BookmarkId"]=vPointId; newPub["FrontShopTitle"]=vEntry.field("FrontTitle"); newPub["Photos"]=vEntry.field("PublicURL"); + newPub["RegionTitle"]=vRegionTitle; var pub=pubLib.create(newPub); pub.set("Location",vEntry.field("Loc")); pub.set("Price",vEntry.field("TotalPrice")); @@ -203,7 +204,8 @@ BtcRelaxApi.prototype.validateEntries = function() { var current =entries[i]; this.getPublicationState(current); - }; + message("Processed:"+i+" of "+count+" items"); + }; }; From 48c99536745f138072bd51d974dde9aa9fe85eca Mon Sep 17 00:00:00 2001 From: godchronos Date: Fri, 4 Aug 2017 09:07:45 +0000 Subject: [PATCH 21/88] Add setStatus method --- BtcRelaxPlugin.js | 59 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index a4096dd..fec677d 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -47,13 +47,13 @@ BtcRelaxApi.prototype.newEntry = function(vEntry) var result=http().get(callUrl+encodeURIComponent(msg)); if(result.code==200) { - var rcode=result.code; - log("Answer result:"+rcode); var json=JSON.parse(result.body); - if (json.bookmarkId !== undefined) + var rcode=json.code; + log("Answer result:"+rcode); + if (rcode === 0) { - var pointId = json.bookmarkId; - if (pointId>0) + var pointId = json.bookmarkId; + if (pointId>0) { this.newPublication(vEntry, pointId) } @@ -61,12 +61,36 @@ BtcRelaxApi.prototype.newEntry = function(vEntry) { message('Inadequate response from Server while sending!'); log("Entry with URL:"+vEntry.field("PublicURL")+" rejected by server!"); - exit(); } - }; + } + else + { + var rmessage=json.message; + message("Code:"+rcode+" with message:"+rmessage+" returned while try to insert!"); + }; }; } +BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) +{ + switch(vNewState) + { case 'Saled': + vPub.set("FinishDate",memento().ToDate()); + break; + case 'Rejected': + vPub.set("FinishDate",memento().ToDate()); + break; + case 'Published': + vPub.set("StartDate",memento().ToDate()); + break; + default: + message("Unknown state!"); + exit(); + break; + }; + vPub.set("Status",vNewState); +} + BtcRelaxApi.prototype.newPublication = function(vEntry, vPointId) { var isPubCount = vEntrty.field("PublicationEntry").length; @@ -112,16 +136,16 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) this.prepareRequest(vPub); var vRequest = vPub.field("Request"); var result=http().get(vRequest); - vPub.set("Response",result); if(result.code==200) { - var json=JSON.parse(result.body); - var state =json.serverState; - log("Returned status:"+state); - var oldState = vPub.field('Status'); - vPub.set("Status",state); - if (state !== oldState) + var json=JSON.parse(result.body); + vPub.set("Response",result); + var state =json.serverState; + log("Returned status:"+state); + var oldState = vPub.field('Status'); + if (state !== oldState) { - message("BookmarkId:"+pointId+" changed!"); + this.setNewState(vPub,state); + message("BookmarkId:"+pointId+" changed!"); }; }; } @@ -252,3 +276,8 @@ function refreshAllPubs(vServer) bra.getPublicationsStates(cE); } + +//refreshAllPubs('https://ua.bitganj.website'); +//refreshPub('https://ua.bitganj.website'); +//syncCurrent('https://ua.bitganj.website'); +//syncAll('https://ua.bitganj.website'); From 714ff7a30cca5d16c62782fde5f9dfbb6b610f89 Mon Sep 17 00:00:00 2001 From: godchronos Date: Fri, 4 Aug 2017 09:19:28 +0000 Subject: [PATCH 22/88] Update BtcRelaxPlugin.js --- BtcRelaxPlugin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index fec677d..e0095d7 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -93,7 +93,7 @@ BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) BtcRelaxApi.prototype.newPublication = function(vEntry, vPointId) { - var isPubCount = vEntrty.field("PublicationEntry").length; + var isPubCount = vEntry.field("PublicationEntry").length; if(isPubCount===0) { var pubLib=libByName("Publication"); @@ -145,7 +145,7 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) if (state !== oldState) { this.setNewState(vPub,state); - message("BookmarkId:"+pointId+" changed!"); + message("BookmarkId:"+pointId+" changed!"); }; }; } From 13582d6775d40b99538c1e5edbfd0ebe83c4dad8 Mon Sep 17 00:00:00 2001 From: godchronos Date: Fri, 4 Aug 2017 09:32:10 +0000 Subject: [PATCH 23/88] Region title input argument patch --- BtcRelaxPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index e0095d7..a67dc96 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -98,7 +98,7 @@ BtcRelaxApi.prototype.newPublication = function(vEntry, vPointId) { var pubLib=libByName("Publication"); var newPub = new Object(); - var vRegionTitle=this.getRegionPath(vEntry); + var vRegionTitle=this.getRegionPath(vEntry.field("Regions")[0]); newPub["BookmarkId"]=vPointId; newPub["FrontShopTitle"]=vEntry.field("FrontTitle"); newPub["Photos"]=vEntry.field("PublicURL"); From 9d012f5b423e1f8ca27b33ff4fdecb75384092b6 Mon Sep 17 00:00:00 2001 From: godchronos Date: Fri, 4 Aug 2017 09:37:52 +0000 Subject: [PATCH 24/88] Update BtcRelaxPlugin.js --- BtcRelaxPlugin.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index a67dc96..0a208fb 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -75,13 +75,13 @@ BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) { switch(vNewState) { case 'Saled': - vPub.set("FinishDate",memento().ToDate()); + vPub.set("FinishDate",moment().ToDate()); break; case 'Rejected': - vPub.set("FinishDate",memento().ToDate()); + vPub.set("FinishDate",moment().ToDate()); break; case 'Published': - vPub.set("StartDate",memento().ToDate()); + vPub.set("StartDate",moment().ToDate()); break; default: message("Unknown state!"); From a4b63899c7bc28b8757bacf46ca8eeadc760665d Mon Sep 17 00:00:00 2001 From: godchronos Date: Fri, 4 Aug 2017 12:51:32 +0300 Subject: [PATCH 25/88] Update BtcRelaxPlugin.js --- BtcRelaxPlugin.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 0a208fb..4009b21 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -75,13 +75,13 @@ BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) { switch(vNewState) { case 'Saled': - vPub.set("FinishDate",moment().ToDate()); + vPub.set("FinishDate",moment().toDate()); break; case 'Rejected': - vPub.set("FinishDate",moment().ToDate()); + vPub.set("FinishDate",moment().toDate()); break; case 'Published': - vPub.set("StartDate",moment().ToDate()); + vPub.set("StartDate",moment().toDate()); break; default: message("Unknown state!"); @@ -139,7 +139,8 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) if(result.code==200) { var json=JSON.parse(result.body); vPub.set("Response",result); - var state =json.serverState; + var pointId=vPub.field("BookmarkId"); +var state =json.serverState; log("Returned status:"+state); var oldState = vPub.field('Status'); if (state !== oldState) From 9e71c21c4c20cc22739d728dea1aa73c78342c1e Mon Sep 17 00:00:00 2001 From: godchronos Date: Fri, 4 Aug 2017 23:57:09 +0300 Subject: [PATCH 26/88] Stringify JSON result --- BtcRelaxPlugin.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 4009b21..bff8f6e 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -33,8 +33,8 @@ BtcRelaxApi.prototype.prepareEntity = function (vEntry) { BtcRelaxApi.prototype.syncEntry = function(vEntry) { var isSent=vEntry.field("isSent"); - if (isSent==false) - { + if (isSent===false) + { if (!this.isReadOnly) { this.newEntry(vEntry);}; }; } @@ -55,7 +55,7 @@ BtcRelaxApi.prototype.newEntry = function(vEntry) var pointId = json.bookmarkId; if (pointId>0) { - this.newPublication(vEntry, pointId) + this.newPublication(vEntry, pointId) } else { @@ -138,7 +138,7 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) var result=http().get(vRequest); if(result.code==200) { var json=JSON.parse(result.body); - vPub.set("Response",result); + vPub.set("Response",JSON.stringify(result)); var pointId=vPub.field("BookmarkId"); var state =json.serverState; log("Returned status:"+state); From f3689d3798805563ad19912cf9727ed9fb533957 Mon Sep 17 00:00:00 2001 From: godchronos Date: Sat, 5 Aug 2017 00:04:51 +0300 Subject: [PATCH 27/88] Log result --- BtcRelaxPlugin.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index bff8f6e..a9a7d7f 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -136,9 +136,10 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) this.prepareRequest(vPub); var vRequest = vPub.field("Request"); var result=http().get(vRequest); +log(result); if(result.code==200) { var json=JSON.parse(result.body); - vPub.set("Response",JSON.stringify(result)); + vPub.set("Response",JSON.stringify(json)); var pointId=vPub.field("BookmarkId"); var state =json.serverState; log("Returned status:"+state); From e6c253f7a7ffe00ea158ab9667c1525473d76579 Mon Sep 17 00:00:00 2001 From: godchronos Date: Sun, 6 Aug 2017 08:23:32 +0300 Subject: [PATCH 28/88] PreOrdered state was added --- BtcRelaxPlugin.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index a9a7d7f..8461a81 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -83,7 +83,10 @@ BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) case 'Published': vPub.set("StartDate",moment().toDate()); break; - default: + case 'PreOrdered': + message("Bookmark id:"+vPub.field("BookmarkId")+" was preordered"); + break; + default: message("Unknown state!"); exit(); break; From 1ca7b066c44315e9bdfd2eea39523eef0b43568b Mon Sep 17 00:00:00 2001 From: godchronos Date: Thu, 17 Aug 2017 13:21:37 +0300 Subject: [PATCH 29/88] Set state anyway, and even unknown! --- BtcRelaxPlugin.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 8461a81..51bdafc 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -85,10 +85,12 @@ BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) break; case 'PreOrdered': message("Bookmark id:"+vPub.field("BookmarkId")+" was preordered"); - break; - default: - message("Unknown state!"); - exit(); + break; + case 'Preparing': + message("Bookmark id:"+vPub.field("BookmarkId")+" need for revision!"); + break; + default: + message("Bookmark id:"+vPub.field("BookmarkId")+" has unknown state:"+vNewState); break; }; vPub.set("Status",vNewState); From d5cd8eca7b614790d1586c23a83c1deef54788ce Mon Sep 17 00:00:00 2001 From: godchronos Date: Thu, 24 Aug 2017 14:56:01 +0300 Subject: [PATCH 30/88] GetOrderId --- BtcRelaxPlugin.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 51bdafc..0003d6c 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -149,6 +149,11 @@ log(result); var state =json.serverState; log("Returned status:"+state); var oldState = vPub.field('Status'); + var orderId = json.OrderId; + . if (orderId !== undefined) + { + vPub.set("OrderId", orderId); + }; if (state !== oldState) { this.setNewState(vPub,state); From a18df9e9dffbe14c6260da3b2a03ffb12d82aaa6 Mon Sep 17 00:00:00 2001 From: godchronos Date: Thu, 24 Aug 2017 15:10:05 +0300 Subject: [PATCH 31/88] log order id catched from server --- BtcRelaxPlugin.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 0003d6c..32a79ee 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -150,7 +150,8 @@ var state =json.serverState; log("Returned status:"+state); var oldState = vPub.field('Status'); var orderId = json.OrderId; - . if (orderId !== undefined) + . log("OrderId:"+orderId); + if (orderId !== undefined) { vPub.set("OrderId", orderId); }; From 8ac7343b37c52dbcbb03da58f94f370e7872c401 Mon Sep 17 00:00:00 2001 From: godchronos Date: Thu, 24 Aug 2017 15:13:32 +0300 Subject: [PATCH 32/88] --- BtcRelaxPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 32a79ee..df6b71c 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -150,7 +150,7 @@ var state =json.serverState; log("Returned status:"+state); var oldState = vPub.field('Status'); var orderId = json.OrderId; - . log("OrderId:"+orderId); + log("OrderId:"+orderId); if (orderId !== undefined) { vPub.set("OrderId", orderId); From 926793699ce65e1290fe6fbc384af67782eb912c Mon Sep 17 00:00:00 2001 From: godchronos Date: Sat, 26 Aug 2017 22:01:36 +0300 Subject: [PATCH 33/88] new function newOrder --- BtcRelaxPlugin.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index df6b71c..1bf8f8f 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -96,6 +96,15 @@ BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) vPub.set("Status",vNewState); } +BtcRelaxApi.prototype.newOrder = +function(vOrderId) +{ + var vOrderLib=libByName("Orders"); + var vNewOrder=new Object(); + vNewOrder["OrderId"]=vOrderId; + vOrderLib.create(vNewOrder); +} + BtcRelaxApi.prototype.newPublication = function(vEntry, vPointId) { var isPubCount = vEntry.field("PublicationEntry").length; @@ -290,7 +299,16 @@ function refreshAllPubs(vServer) } +function addOrder(vServer, vOrderId) +{ + var bra=new BtcRelaxApi( vServer + "/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); + var cE = entry(); + bra.newOrder(vOrderId); +} + + //refreshAllPubs('https://ua.bitganj.website'); //refreshPub('https://ua.bitganj.website'); //syncCurrent('https://ua.bitganj.website'); //syncAll('https://ua.bitganj.website'); +//addOrder('https://ua.bitganj.website',vNew) \ No newline at end of file From 07efc1712dc9bdcfa29347d121c10ecc1805887c Mon Sep 17 00:00:00 2001 From: godchronos Date: Tue, 29 Aug 2017 13:43:54 +0000 Subject: [PATCH 34/88] Create relation to pub from Order In case when Get publication status result has OrderId. Then, relate Order with publication. --- BtcRelaxPlugin.js | 53 +++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 1bf8f8f..59f4bdf 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -96,13 +96,29 @@ BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) vPub.set("Status",vNewState); } -BtcRelaxApi.prototype.newOrder = +BtcRelaxApi.prototype.getOrderById = function(vOrderId) { - var vOrderLib=libByName("Orders"); - var vNewOrder=new Object(); - vNewOrder["OrderId"]=vOrderId; - vOrderLib.create(vNewOrder); + var vResult; + var vOrderLib=libByName("Orders"); + var entries = vOrderLib.entries(); + var count =entries.length; + for(var i=0;i Date: Tue, 29 Aug 2017 18:53:19 +0300 Subject: [PATCH 35/88] Log order creation --- BtcRelaxPlugin.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 59f4bdf..eda1b90 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -99,25 +99,28 @@ BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) BtcRelaxApi.prototype.getOrderById = function(vOrderId) { - var vResult; - var vOrderLib=libByName("Orders"); + log("Getting order Id:"+vOrderId); + var vResult; + var vOrderLib=libByName("Orders"); var entries = vOrderLib.entries(); var count =entries.length; + log("Local library, already has:"+count+" orders."); for(var i=0;i Date: Tue, 29 Aug 2017 23:25:52 +0300 Subject: [PATCH 36/88] Add prepare order request method --- BtcRelaxPlugin.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index eda1b90..647f467 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -164,6 +164,22 @@ BtcRelaxApi.prototype.prepareRequest = function(vPub) }; } +BtcRelaxApi.prototype.prepareOrderRequest = function(vOrder) +{ + var vOrderId=vOrder.field("OrderId"); + if ( vOrderId>0) + { + var msg = '{"type":"GetOrderById","OrderId":"' + vOrderId + '"}'; + var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; + vOrder=set("Request",callUrl+encodeURIComponent(msg)); + } + else + { + message("Error getting for order id:"+vOrderId); + }; +} + + BtcRelaxApi.prototype.getPublicationState = function(vPub) { this.prepareRequest(vPub); @@ -184,7 +200,8 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) vPub.set("OrderId", orderId); var vOrder = this.getOrderById(orderId); vOrder.set("PublicationEntry",vPub); - }; + this.prepareOrderRequest(vOrder); +}; if (state !== oldState) { this.setNewState(vPub,state); From 34cfcd1b735171f68b62327758cd92d0f71429a1 Mon Sep 17 00:00:00 2001 From: godchronos Date: Tue, 29 Aug 2017 23:44:19 +0300 Subject: [PATCH 37/88] Check exists order compare bug --- BtcRelaxPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 647f467..4ad5b49 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -109,7 +109,7 @@ function(vOrderId) { var current =entries[i]; var vCurId =current.field("OrderId"); - if (vOrderId===vCurId) + if (vOrderId==vCurId) { log("Order with id:"+vOrderId+" already exist!"); vResult = current; From 123b5bf3edcbea1662d2da27efd981bf3c3b1c96 Mon Sep 17 00:00:00 2001 From: godchronos Date: Wed, 30 Aug 2017 00:00:40 +0300 Subject: [PATCH 38/88] Check for init var of Order --- BtcRelaxPlugin.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 4ad5b49..33db789 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -196,12 +196,15 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) var orderId = json.OrderId; if (orderId !== undefined) { - log("OrderId:"+orderId); + log("OrderId:"+orderId); vPub.set("OrderId", orderId); var vOrder = this.getOrderById(orderId); - vOrder.set("PublicationEntry",vPub); + if (vOrder!==undefined) + { + vOrder.set("PublicationEntry",vPub); this.prepareOrderRequest(vOrder); -}; + }; + }; if (state !== oldState) { this.setNewState(vPub,state); From c42497a69e89b26949ce8f4edf5c0836116c74a7 Mon Sep 17 00:00:00 2001 From: godchronos Date: Wed, 30 Aug 2017 13:10:15 +0300 Subject: [PATCH 39/88] --- BtcRelaxPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 33db789..f1f52ff 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -171,7 +171,7 @@ BtcRelaxApi.prototype.prepareOrderRequest = function(vOrder) { var msg = '{"type":"GetOrderById","OrderId":"' + vOrderId + '"}'; var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; - vOrder=set("Request",callUrl+encodeURIComponent(msg)); + vOrder.set("Request",callUrl+encodeURIComponent(msg)); } else { From 73f27fba0f9dac2d7f945d580ec4428d95eb9216 Mon Sep 17 00:00:00 2001 From: godchronos Date: Wed, 30 Aug 2017 14:03:52 +0000 Subject: [PATCH 40/88] Make internal server var as is --- BtcRelaxPlugin.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index f1f52ff..b4f5c39 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -42,7 +42,7 @@ BtcRelaxApi.prototype.syncEntry = function(vEntry) BtcRelaxApi.prototype.newEntry = function(vEntry) { var msg=vEntry.field("ServerRequest"); - var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; + var callUrl=this.server+"/PointsApi.php"+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; log("Calling URL:"+callUrl+msg); var result=http().get(callUrl+encodeURIComponent(msg)); if(result.code==200) @@ -155,7 +155,7 @@ BtcRelaxApi.prototype.prepareRequest = function(vPub) { log("Preparing bookmark Id:"+pointId); var msg = '{"type":"GetPointState","bookmarkId":"' + pointId + '"}'; - var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; + var callUrl=this.server+"/PointsApi.php"+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; vPub.set("Request",callUrl+encodeURIComponent(msg)); } else @@ -170,7 +170,7 @@ BtcRelaxApi.prototype.prepareOrderRequest = function(vOrder) if ( vOrderId>0) { var msg = '{"type":"GetOrderById","OrderId":"' + vOrderId + '"}'; - var callUrl=this.server+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; + var callUrl=this.server+"/OrdersApi.php"+'?tokenId='+this.tokenId+'&tokenKey='+this.tokenKey+'&action='; vOrder.set("Request",callUrl+encodeURIComponent(msg)); } else @@ -311,7 +311,7 @@ BtcRelaxApi.prototype.getRegionPath = function(entry) function syncAll(vServer) { - var bra=new BtcRelaxApi( vServer + "/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); + var bra=new BtcRelaxApi( vServer,2,"be55d4034229177ca6f864a87cb630d3", false); bra.validateEntries(); bra.syncEntries(); } @@ -326,7 +326,7 @@ function syncCurrent(vServer) function refreshPub(vServer) { - var bra=new BtcRelaxApi( vServer + "/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); + var bra=new BtcRelaxApi( vServer,2,"be55d4034229177ca6f864a87cb630d3", false); var cE = entry(); bra.getPublicationState(cE); @@ -334,7 +334,7 @@ function refreshPub(vServer) function refreshAllPubs(vServer) { - var bra=new BtcRelaxApi( vServer + "/PointsApi.php",2,"be55d4034229177ca6f864a87cb630d3", false); + var bra=new BtcRelaxApi( vServer,2,"be55d4034229177ca6f864a87cb630d3", false); var cE = entry(); bra.getPublicationsStates(cE); From ccc7114b802b31a04b66b31aaad3620990e5e14b Mon Sep 17 00:00:00 2001 From: Chronos Date: Wed, 30 Aug 2017 17:17:26 +0300 Subject: [PATCH 41/88] Fill info about status of Order Signed-off-by:Chronos --- BtcRelaxPlugin.js | 17 ++++++++++++++++- README.md | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index b4f5c39..1bc0b52 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -185,7 +185,6 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) this.prepareRequest(vPub); var vRequest = vPub.field("Request"); var result=http().get(vRequest); - log(result); if(result.code==200) { var json=JSON.parse(result.body); vPub.set("Response",JSON.stringify(json)); @@ -213,6 +212,22 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) }; } +BtcRelaxApi.prototype.getOrderState = function(vOrder) +{ + this.prepareOrderRequest(vOrder); + var vRequest = vOrder.field("Request"); + var result=http().get(vRequest); + if(result.code==200) { + var json=JSON.parse(result.body); + vOrder.set("Response",JSON.stringify(json)); + var state =json.serverState; + var vInvoiceAddress=json.invoiceAddress; + vOrder.set("state",state); + vOrder.set("InvoiceAddress",vInvoiceAddress); + }; +} + + BtcRelaxApi.prototype.syncEntries = function() { var clib = lib(); diff --git a/README.md b/README.md index 458b3cc..7f1610a 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ # scripts + +Define object for communicate from libraries into MementoDatabase to BtcRelax system. \ No newline at end of file From 6e71f017c8c6c7a0f06a8d94a5448cea6ae3bf61 Mon Sep 17 00:00:00 2001 From: godchronos Date: Wed, 30 Aug 2017 17:41:13 +0300 Subject: [PATCH 42/88] Get order state after publication state changed --- BtcRelaxPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 1bc0b52..57d5d86 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -201,7 +201,7 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) if (vOrder!==undefined) { vOrder.set("PublicationEntry",vPub); - this.prepareOrderRequest(vOrder); + this.getOrderState(vOrder); }; }; if (state !== oldState) From 70c4d47fa98d9b911d35f4d3baac16bd7d966e68 Mon Sep 17 00:00:00 2001 From: Chronos Date: Wed, 30 Aug 2017 17:59:50 +0300 Subject: [PATCH 43/88] Check order id from server is integer ? Signed-off-by:Chronos --- BtcRelaxPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 1bc0b52..1a99983 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -193,7 +193,7 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) log("Returned status:"+state); var oldState = vPub.field('Status'); var orderId = json.OrderId; - if (orderId !== undefined) + if (orderId>0) { log("OrderId:"+orderId); vPub.set("OrderId", orderId); From 2c5b74688a7d4324d68eb0e28f57886362d07dd3 Mon Sep 17 00:00:00 2001 From: Chronos Date: Thu, 31 Aug 2017 19:05:48 +0300 Subject: [PATCH 44/88] Add support for bookmark status lost Signed-off-by:Chronos --- BtcRelaxPlugin.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index a8146f4..7512b9a 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -83,13 +83,17 @@ BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) case 'Published': vPub.set("StartDate",moment().toDate()); break; - case 'PreOrdered': - message("Bookmark id:"+vPub.field("BookmarkId")+" was preordered"); + case 'PreOrdered': + message("Bookmark id:"+vPub.field("BookmarkId")+" was preordered"); + break; + case 'Preparing': + message("Bookmark id:"+vPub.field("BookmarkId")+" need for revision!"); break; - case 'Preparing': - message("Bookmark id:"+vPub.field("BookmarkId")+" need for revision!"); + case 'Lost': + vPub.set("FinishDate",moment().toDate()); + message("Bookmark id:"+vPub.field("BookmarkId")+" was lost!"); break; - default: + default: message("Bookmark id:"+vPub.field("BookmarkId")+" has unknown state:"+vNewState); break; }; From 8a5bc15f0034628aa10223f4bda6d7452e84ab3a Mon Sep 17 00:00:00 2001 From: godchronos Date: Mon, 11 Sep 2017 14:46:06 +0000 Subject: [PATCH 45/88] Create refreshAllPubs.js --- refreshAllPubs.js | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 refreshAllPubs.js diff --git a/refreshAllPubs.js b/refreshAllPubs.js new file mode 100644 index 0000000..b39b38f --- /dev/null +++ b/refreshAllPubs.js @@ -0,0 +1,3 @@ +var vServer='https://ua.bitganj.website'; +refreshAllPubs(vServer); + From 61b210fd5c299168718df61951d1926d5ba0a394 Mon Sep 17 00:00:00 2001 From: godchronos Date: Mon, 11 Sep 2017 14:48:04 +0000 Subject: [PATCH 46/88] Final of that part --- BtcRelaxPlugin.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 7512b9a..3cc64de 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -358,8 +358,3 @@ function refreshAllPubs(vServer) bra.getPublicationsStates(cE); } - -//refreshAllPubs('https://ua.bitganj.website'); -//refreshPub('https://ua.bitganj.website'); -//syncCurrent('https://ua.bitganj.website'); -//syncAll('https://ua.bitganj.website'); From d8bf82ed981c2a642b78c0136d30a843a5f9cfe4 Mon Sep 17 00:00:00 2001 From: godchronos Date: Mon, 11 Sep 2017 20:10:16 +0000 Subject: [PATCH 47/88] Create file refreshPub.js --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f1610a..2a92784 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # scripts -Define object for communicate from libraries into MementoDatabase to BtcRelax system. \ No newline at end of file +Define object for communicate from libraries into MementoDatabase to BtcRelax system. + +For productive recomended to use, quick files: +refreshAllPubs.js; +refreshPub.js; +syncCurrent('https://ua.bitganj.website'); +syncAll('https://ua.bitganj.website'); From 287e55dec0d6088266740233785964118ff6675a Mon Sep 17 00:00:00 2001 From: godchronos Date: Mon, 11 Sep 2017 20:11:29 +0000 Subject: [PATCH 48/88] Create refreshPub.js --- refreshPub.js | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 refreshPub.js diff --git a/refreshPub.js b/refreshPub.js new file mode 100644 index 0000000..1a2f9cc --- /dev/null +++ b/refreshPub.js @@ -0,0 +1,2 @@ +var vServer='https://ua.bitganj.website'; +refreshPub(vServer); From 51901d1fe776882233e7fb1827b704fb63e484a4 Mon Sep 17 00:00:00 2001 From: godchronos Date: Tue, 12 Sep 2017 15:27:31 +0000 Subject: [PATCH 49/88] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 2a92784..e39775a 100644 --- a/README.md +++ b/README.md @@ -5,5 +5,3 @@ Define object for communicate from libraries into MementoDatabase to BtcRelax sy For productive recomended to use, quick files: refreshAllPubs.js; refreshPub.js; -syncCurrent('https://ua.bitganj.website'); -syncAll('https://ua.bitganj.website'); From 41c23b13da07809ac6c8aad8c8ecf5c5a249ac7a Mon Sep 17 00:00:00 2001 From: godchronos Date: Tue, 12 Sep 2017 15:28:10 +0000 Subject: [PATCH 50/88] Create syncCurrent.js --- syncCurrent.js | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 syncCurrent.js diff --git a/syncCurrent.js b/syncCurrent.js new file mode 100644 index 0000000..62ba04d --- /dev/null +++ b/syncCurrent.js @@ -0,0 +1,2 @@ +syncCurrent('https://ua.bitganj.website'); + From 930234cf32dca434ff738a1a1e855a6503469942 Mon Sep 17 00:00:00 2001 From: godchronos Date: Tue, 12 Sep 2017 15:29:37 +0000 Subject: [PATCH 51/88] Create syncAll.js --- syncAll.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 syncAll.js diff --git a/syncAll.js b/syncAll.js new file mode 100644 index 0000000..e8408fc --- /dev/null +++ b/syncAll.js @@ -0,0 +1 @@ +syncAll('https://ua.bitganj.website'); From 4e649cc85a9aa86419fb8980323bc037f09b1869 Mon Sep 17 00:00:00 2001 From: Chronos Date: Mon, 25 Sep 2017 13:34:50 +0300 Subject: [PATCH 52/88] Getting info from chain Signed-off-by:Chronos Signed-off-by:Chronos --- BtcRelaxPlugin.js | 54 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 7512b9a..e85ed45 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -1,3 +1,5 @@ +/* global http */ + function BtcRelaxApi( v_server , v_tokenId, v_tokenKey, v_readOnly ) { this.server = v_server; @@ -100,6 +102,27 @@ BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) vPub.set("Status",vNewState); } +BtcRelaxApi.prototype.getIterateOrders=function() +{ + var clib = lib(); + var entries =clib.entries(); + var count =entries.length; + for (i=0;i0) + { + var req="https://api.smartbit.com.au/v1/blockchain/address/"+vAddr+"?tx=0"; + current.set("ChainRequest",req); + //var vCRes=queryChain(req); + this.queryChain(current); + //current.set("ChainResponse", JSON.stringify(vCRes)); + }; + }; +} + + BtcRelaxApi.prototype.getOrderById = function(vOrderId) { @@ -183,7 +206,6 @@ BtcRelaxApi.prototype.prepareOrderRequest = function(vOrder) }; } - BtcRelaxApi.prototype.getPublicationState = function(vPub) { this.prepareRequest(vPub); @@ -231,6 +253,19 @@ BtcRelaxApi.prototype.getOrderState = function(vOrder) }; } +BtcRelaxApi.prototype.queryChain = function(vOrder) +{ + var vRequest = vOrder.field("ChainRequest"); + var result=http().get(vRequest); + if(result.code==200) { + var json=JSON.parse(result.body); + vOrder.set("ChainResponse",JSON.stringify(json)); + var vReceived =json.address.received; + var vBalance=json.address.balance; + vOrder.set("InvoiceBalance",vBalance); + }; +} + BtcRelaxApi.prototype.syncEntries = function() { @@ -300,7 +335,7 @@ BtcRelaxApi.prototype.validateEntries = function() }; }; - BtcRelaxApi.prototype.getPublicationsStates = function() +BtcRelaxApi.prototype.getPublicationsStates = function() { var clib = lib(); var entries = clib.entries(); @@ -313,9 +348,7 @@ BtcRelaxApi.prototype.validateEntries = function() message("Processed:"+i+" of "+count+" items"); }; }; - - - + BtcRelaxApi.prototype.getRegionPath = function(entry) { var res; @@ -354,11 +387,18 @@ function refreshPub(vServer) function refreshAllPubs(vServer) { var bra=new BtcRelaxApi( vServer,2,"be55d4034229177ca6f864a87cb630d3", false); - var cE = entry(); - bra.getPublicationsStates(cE); + bra.getPublicationsStates(); } + + +function refreshAllOrders(vServer) +{ + var bra=new BtcRelaxApi( vServer,2,"be55d4034229177ca6f864a87cb630d3", false); + bra.getIterateOrders(); +} + //refreshAllPubs('https://ua.bitganj.website'); //refreshPub('https://ua.bitganj.website'); //syncCurrent('https://ua.bitganj.website'); From 43765f6d60def675723504f9ec7ea7d30016587e Mon Sep 17 00:00:00 2001 From: Chronos Date: Mon, 25 Sep 2017 13:45:44 +0300 Subject: [PATCH 53/88] Create branch for productive Signed-off-by:Chronos Signed-off-by:Chronos --- BtcRelaxPlugin.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index e85ed45..f17afc1 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -39,7 +39,7 @@ BtcRelaxApi.prototype.syncEntry = function(vEntry) { if (!this.isReadOnly) { this.newEntry(vEntry);}; }; -} +}; BtcRelaxApi.prototype.newEntry = function(vEntry) { @@ -71,7 +71,7 @@ BtcRelaxApi.prototype.newEntry = function(vEntry) message("Code:"+rcode+" with message:"+rmessage+" returned while try to insert!"); }; }; -} +}; BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) { @@ -100,7 +100,7 @@ BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) break; }; vPub.set("Status",vNewState); -} +}; BtcRelaxApi.prototype.getIterateOrders=function() { @@ -120,7 +120,7 @@ BtcRelaxApi.prototype.getIterateOrders=function() //current.set("ChainResponse", JSON.stringify(vCRes)); }; }; -} +}; BtcRelaxApi.prototype.getOrderById = @@ -149,7 +149,7 @@ function(vOrderId) vResult = vOrderLib.create(vNewOrder); log("Order with id:"+vOrderId+" created!"); return vResult; -} +}; BtcRelaxApi.prototype.newPublication = function(vEntry, vPointId) { @@ -173,7 +173,7 @@ BtcRelaxApi.prototype.newPublication = function(vEntry, vPointId) { log("Entry with URL:"+vEntry.field("PublicURL")+" already has publication!"); } -} +}; BtcRelaxApi.prototype.prepareRequest = function(vPub) { @@ -189,7 +189,7 @@ BtcRelaxApi.prototype.prepareRequest = function(vPub) { message("Error getting state for point id:"+pointId); }; -} +}; BtcRelaxApi.prototype.prepareOrderRequest = function(vOrder) { @@ -204,7 +204,7 @@ BtcRelaxApi.prototype.prepareOrderRequest = function(vOrder) { message("Error getting for order id:"+vOrderId); }; -} +}; BtcRelaxApi.prototype.getPublicationState = function(vPub) { @@ -236,14 +236,14 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) message("BookmarkId:"+pointId+" changed!"); }; }; -} +}; BtcRelaxApi.prototype.getOrderState = function(vOrder) { this.prepareOrderRequest(vOrder); var vRequest = vOrder.field("Request"); var result=http().get(vRequest); - if(result.code==200) { + if(result.code===200) { var json=JSON.parse(result.body); vOrder.set("Response",JSON.stringify(json)); var state =json.serverState; @@ -251,20 +251,20 @@ BtcRelaxApi.prototype.getOrderState = function(vOrder) vOrder.set("state",state); vOrder.set("InvoiceAddress",vInvoiceAddress); }; -} +}; BtcRelaxApi.prototype.queryChain = function(vOrder) { var vRequest = vOrder.field("ChainRequest"); var result=http().get(vRequest); - if(result.code==200) { + if(result.code===200) { var json=JSON.parse(result.body); vOrder.set("ChainResponse",JSON.stringify(json)); var vReceived =json.address.received; var vBalance=json.address.balance; vOrder.set("InvoiceBalance",vBalance); }; -} +}; BtcRelaxApi.prototype.syncEntries = function() @@ -366,7 +366,7 @@ function syncAll(vServer) var bra=new BtcRelaxApi( vServer,2,"be55d4034229177ca6f864a87cb630d3", false); bra.validateEntries(); bra.syncEntries(); -} +}; function syncCurrent(vServer) { @@ -374,7 +374,7 @@ function syncCurrent(vServer) var cE = entry(); bra.validateEntry(cE); bra.syncEntry(cE); -} +}; function refreshPub(vServer) { @@ -382,14 +382,14 @@ function refreshPub(vServer) var cE = entry(); bra.getPublicationState(cE); -} +}; function refreshAllPubs(vServer) { var bra=new BtcRelaxApi( vServer,2,"be55d4034229177ca6f864a87cb630d3", false); bra.getPublicationsStates(); -} +}; @@ -397,7 +397,7 @@ function refreshAllOrders(vServer) { var bra=new BtcRelaxApi( vServer,2,"be55d4034229177ca6f864a87cb630d3", false); bra.getIterateOrders(); -} +}; //refreshAllPubs('https://ua.bitganj.website'); //refreshPub('https://ua.bitganj.website'); From 4f58f8484d089f55a72853e3086313df9c30ac51 Mon Sep 17 00:00:00 2001 From: Chronos Date: Mon, 25 Sep 2017 14:51:03 +0300 Subject: [PATCH 54/88] Full refresh of info from chain Signed-off-by:Chronos Signed-off-by:Chronos --- BtcRelaxPlugin.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index f17afc1..486279a 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -107,22 +107,23 @@ BtcRelaxApi.prototype.getIterateOrders=function() var clib = lib(); var entries =clib.entries(); var count =entries.length; + log("Total orders:"+count); for (i=0;i0) { - var req="https://api.smartbit.com.au/v1/blockchain/address/"+vAddr+"?tx=0"; + log("Checking order:"+current.field("OrderId")); + var req="https://api.smartbit.com.au/v1/blockchain/address/"+vAddr+"?tx=0"; current.set("ChainRequest",req); - //var vCRes=queryChain(req); this.queryChain(current); - //current.set("ChainResponse", JSON.stringify(vCRes)); }; }; }; + BtcRelaxApi.prototype.getOrderById = function(vOrderId) { @@ -250,6 +251,7 @@ BtcRelaxApi.prototype.getOrderState = function(vOrder) var vInvoiceAddress=json.invoiceAddress; vOrder.set("state",state); vOrder.set("InvoiceAddress",vInvoiceAddress); + vOrder.set("Modified",moment().toDate()); }; }; @@ -260,9 +262,17 @@ BtcRelaxApi.prototype.queryChain = function(vOrder) if(result.code===200) { var json=JSON.parse(result.body); vOrder.set("ChainResponse",JSON.stringify(json)); - var vReceived =json.address.received; - var vBalance=json.address.balance; - vOrder.set("InvoiceBalance",vBalance); + var vSuc =json.success; + if (vSuc) + { + var vAdrInf=json.address; + var vTotal=vAdrInf.total; + var vBalance=vTotal.balance; + var vReceived=vTotal.received; + vOrder.set("AddressBalance",vBalance); + vOrder.set("Received",vReceived); + vOrder.set("Modified",moment().toDate()); + }; }; }; @@ -403,3 +413,4 @@ function refreshAllOrders(vServer) //refreshPub('https://ua.bitganj.website'); //syncCurrent('https://ua.bitganj.website'); //syncAll('https://ua.bitganj.website'); +//refreshAllOrders('https://ua.bitganj.website'); From 729eee0ce6f87b5a312bb1033a3475d4201e0f1a Mon Sep 17 00:00:00 2001 From: "godChronos@tuta.io" Date: Tue, 26 Sep 2017 01:50:37 +0300 Subject: [PATCH 55/88] --- BtcRelaxPlugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 486279a..f7a107c 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -398,7 +398,7 @@ function refreshAllPubs(vServer) { var bra=new BtcRelaxApi( vServer,2,"be55d4034229177ca6f864a87cb630d3", false); bra.getPublicationsStates(); - + bra.getIterateOrders(); }; From ecc72efad886623b562dc0940288ed1a656a6055 Mon Sep 17 00:00:00 2001 From: "godChronos@tuta.io" Date: Thu, 28 Sep 2017 07:37:46 +0300 Subject: [PATCH 56/88] From f7096d6cb791867a3f6222501c95d14d87b75630 Mon Sep 17 00:00:00 2001 From: "godChronos@tuta.io" Date: Thu, 28 Sep 2017 07:41:06 +0300 Subject: [PATCH 57/88] From 61ff5c04e4f2b63d13418e0fc96cb769b37825cb Mon Sep 17 00:00:00 2001 From: "godChronos@tuta.io" Date: Fri, 29 Sep 2017 03:17:14 +0300 Subject: [PATCH 58/88] --- BtcRelaxPlugin.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 6ec065c..112b762 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -111,14 +111,7 @@ BtcRelaxApi.prototype.getIterateOrders=function() for (i=0;i0) - { - log("Checking order:"+current.field("OrderId")); - var req="https://api.smartbit.com.au/v1/blockchain/address/"+vAddr+"?tx=0"; - current.set("ChainRequest",req); - this.queryChain(current); - }; + this.queryChain(current); }; }; @@ -249,14 +242,27 @@ BtcRelaxApi.prototype.getOrderState = function(vOrder) vOrder.set("Response",JSON.stringify(json)); var state =json.serverState; var vInvoiceAddress=json.invoiceAddress; - vOrder.set("state",state); + if (vInvoiceAddress.length>0) + { + vOrder.set("state",state); vOrder.set("InvoiceAddress",vInvoiceAddress); vOrder.set("Modified",moment().toDate()); - }; + this.queryChain(vOrder); + }; +}; }; BtcRelaxApi.prototype.queryChain = function(vOrder) { + + var vAddr=vOrder.field("InvoiceAddress"); + if (vAddr.length>0) + { + log("Checking order:"+vOrder.field("OrderId")); + var req="https://api.smartbit.com.au/v1/blockchain/address/"+vAddr+"?tx=0"; + vOrder.set("ChainRequest",req); + + }; var vRequest = vOrder.field("ChainRequest"); var result=http().get(vRequest); if(result.code===200) { From 472d52d9464990bb309adc86c9a32cf3b1a3fc87 Mon Sep 17 00:00:00 2001 From: Chronos Date: Tue, 17 Oct 2017 01:33:53 +0300 Subject: [PATCH 59/88] Add api Signed-off-by:Chronos Signed-off-by:Chronos --- BtcRelaxPlugin.js | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 112b762..69be87a 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -73,31 +73,44 @@ BtcRelaxApi.prototype.newEntry = function(vEntry) }; }; -BtcRelaxApi.prototype.setNewState=function(vPub,vNewState) +BtcRelaxApi.prototype.setNewState=function(vPub,vNewState, vOrderId) { switch(vNewState) { case 'Saled': - vPub.set("FinishDate",moment().toDate()); - break; + vPub.set("FinishDate",moment().toDate()); + vPub.set("OrderId", vOrderId); + break; case 'Rejected': - vPub.set("FinishDate",moment().toDate()); - break; - case 'Published': - vPub.set("StartDate",moment().toDate()); - break; - case 'PreOrdered': - message("Bookmark id:"+vPub.field("BookmarkId")+" was preordered"); - break; + vPub.set("FinishDate",moment().toDate()); + vPub.set("OrderId", null); + break; + case 'Published': + vPub.set("StartDate",moment().toDate()); + vPub.set("OrderId", null); + break; + case 'PreOrdered': + message("Bookmark id:"+vPub.field("BookmarkId")+" was preordered"); + vPub.set("OrderId", vOrderId); + break; case 'Preparing': message("Bookmark id:"+vPub.field("BookmarkId")+" need for revision!"); - break; + vPub.set("OrderId", null); + break; case 'Lost': vPub.set("FinishDate",moment().toDate()); message("Bookmark id:"+vPub.field("BookmarkId")+" was lost!"); break; + case 'Finished': + vPub.set("FinishDate",moment().toDate()); + vPub.set("OrderId", vOrderId); + break; + case 'Canceled': + vPub.set("FinishDate",moment().toDate()); + vPub.set("OrderId", null); + break; default: - message("Bookmark id:"+vPub.field("BookmarkId")+" has unknown state:"+vNewState); - break; + message("Bookmark id:"+vPub.field("BookmarkId")+" has unknown state:"+vNewState); + break; }; vPub.set("Status",vNewState); }; @@ -216,7 +229,7 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) if (orderId>0) { log("OrderId:"+orderId); - vPub.set("OrderId", orderId); + var vOrder = this.getOrderById(orderId); if (vOrder!==undefined) { @@ -226,8 +239,8 @@ BtcRelaxApi.prototype.getPublicationState = function(vPub) }; if (state !== oldState) { - this.setNewState(vPub,state); - message("BookmarkId:"+pointId+" changed!"); + this.setNewState(vPub,state, orderId); + message("BookmarkId:"+pointId+" changed!"); }; }; }; From ef6c690fec0ae219dc707a5c103b779ec769de49 Mon Sep 17 00:00:00 2001 From: "godChronos@tuta.io" Date: Tue, 17 Oct 2017 17:56:36 +0300 Subject: [PATCH 60/88] From aa88dd923e92e3b10b4193abb0e5fe5bdca21c5f Mon Sep 17 00:00:00 2001 From: "godChronos@tuta.io" Date: Tue, 17 Oct 2017 18:03:23 +0300 Subject: [PATCH 61/88] Add telegram gate --- BtcRelaxTelegramBot.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 BtcRelaxTelegramBot.js diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js new file mode 100644 index 0000000..b7914e3 --- /dev/null +++ b/BtcRelaxTelegramBot.js @@ -0,0 +1,23 @@ +function prepareUpdateRequest(vEntry) +{ + var cEntry; + if (vEntry!==undefined) + { + cEntry=vEntry; + } + else + { + cEntry=entry(); + }; + + var mU=cEntry.field("APItoken"); + var vO=cEntry.field("UpdateId"); + if (vO>0) + { + cEntry.set("ServerRequest",mU+'getUpdates&offset='+vO); + } + else + { + cEntry.set("ServerRequest",mU+'getUpdates'); + }; +} \ No newline at end of file From 28163cc1f44604df02fa3b9a2467210ef0e0dbfb Mon Sep 17 00:00:00 2001 From: "godChronos@tuta.io" Date: Tue, 17 Oct 2017 18:03:46 +0300 Subject: [PATCH 62/88] --- refreshOrders.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 refreshOrders.js diff --git a/refreshOrders.js b/refreshOrders.js new file mode 100644 index 0000000..8d2dbb4 --- /dev/null +++ b/refreshOrders.js @@ -0,0 +1 @@ +refreshAllOrders('https://ua.bitganj.website'); \ No newline at end of file From 5c49453e67a4d0f1d3c343178917e7af683929d1 Mon Sep 17 00:00:00 2001 From: Chronos Date: Tue, 17 Oct 2017 18:24:21 +0300 Subject: [PATCH 63/88] Add api Signed-off-by:Chronos Signed-off-by:Chronos --- BtcRelaxPlugin.js | 2 +- BtcRelaxTelegramBot.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/BtcRelaxPlugin.js b/BtcRelaxPlugin.js index 69be87a..c3ca6d4 100644 --- a/BtcRelaxPlugin.js +++ b/BtcRelaxPlugin.js @@ -1,4 +1,4 @@ -/* global http */ +/* global http, moment */ function BtcRelaxApi( v_server , v_tokenId, v_tokenKey, v_readOnly ) { diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index b7914e3..51f8293 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -20,4 +20,23 @@ function prepareUpdateRequest(vEntry) { cEntry.set("ServerRequest",mU+'getUpdates'); }; +} + +function getUpdateInfo(vEntry) +{ + var vRequest = vEntry.field("ServerRequest"); + var result=http().get(vRequest); + if(result.code===200) { + var json=JSON.parse(result.body); + var state =json.ok; + if (state===true) + { + vEntry.set("ServerResponse",JSON.stringify(json)); + + } + else + { + message('Error while get updates!'); + }; + }; } \ No newline at end of file From c2d60b1dc07b7fa12e517a9a0ba9f06bdf2fb63b Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Wed, 18 Oct 2017 05:12:10 +0300 Subject: [PATCH 64/88] add --- BtcRelaxTelegramBot.js | 44 ++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index 51f8293..ed330be 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -18,25 +18,35 @@ function prepareUpdateRequest(vEntry) } else { - cEntry.set("ServerRequest",mU+'getUpdates'); + cEntry.set("ServerRequest",mU+'getUpdates'); }; -} +}; + function getUpdateInfo(vEntry) { - var vRequest = vEntry.field("ServerRequest"); - var result=http().get(vRequest); - if(result.code===200) { - var json=JSON.parse(result.body); - var state =json.ok; - if (state===true) - { - vEntry.set("ServerResponse",JSON.stringify(json)); - - } - else - { - message('Error while get updates!'); - }; +var vRequest = vEntry.field("ServerRequest"); +var result=http().get(vRequest); +if(result.code===200) { + var json=JSON.parse(result.body); + var state =json.ok; + if (state===true) + { +vEntry.set("ServerResponse",JSON.stringify(json)); + var vUList=json.result; + for (var UInfo in vUList) + { + var uI=vUList[UInfo]; + var vLast=vEntry.field("UpdateId"); + if (vLast!==uI.update_id) +{ +message(uI.update_id); +}; }; -} \ No newline at end of file + }; + }; +}; + +var vC=entry(); +prepareUpdateRequest(vC); +getUpdateInfo(vC); \ No newline at end of file From 4ff88a14a677b4eaa80ba0e8be983f0fe9819bbf Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Wed, 18 Oct 2017 05:44:26 +0300 Subject: [PATCH 65/88] proceessing update --- BtcRelaxTelegramBot.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index ed330be..9dd72fe 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -14,7 +14,7 @@ function prepareUpdateRequest(vEntry) var vO=cEntry.field("UpdateId"); if (vO>0) { - cEntry.set("ServerRequest",mU+'getUpdates&offset='+vO); + cEntry.set("ServerRequest",mU+'getUpdates?offset='+vO); } else { @@ -29,24 +29,31 @@ var vRequest = vEntry.field("ServerRequest"); var result=http().get(vRequest); if(result.code===200) { var json=JSON.parse(result.body); +   vEntry.set("ServerResponse",JSON.stringify(json)); var state =json.ok; if (state===true) { -vEntry.set("ServerResponse",JSON.stringify(json)); var vUList=json.result; for (var UInfo in vUList) { var uI=vUList[UInfo]; var vLast=vEntry.field("UpdateId"); if (vLast!==uI.update_id) -{ -message(uI.update_id); -}; + { + processUpdateInfo(vEntry,uI); + }; }; }; }; }; +function processUpdateInfo(vEntry, vUpdateInfo) +{ +   var vUId = vUpdateInfo.update_id; + vEntry.set("UpdateId",vUId); +}; + + var vC=entry(); prepareUpdateRequest(vC); getUpdateInfo(vC); \ No newline at end of file From 88643a7c0bfba93f704af43b049ee889d6f22e2c Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 02:30:27 +0300 Subject: [PATCH 66/88] Add history --- BtcRelaxTelegramBot.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index 9dd72fe..abe52dc 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -50,6 +50,11 @@ if(result.code===200) { function processUpdateInfo(vEntry, vUpdateInfo) {   var vUId = vUpdateInfo.update_id; + var vHLib = libByName("TelegramUpdates"); + var vUInfo = new Object(); + vUInfo["UpdateId"]=vUId; + var nUI=vHLib.create(vUInfo); + nUI.set("TelegramBot",vEntry); vEntry.set("UpdateId",vUId); }; From c74d5dd27d7f32b12f2d8eb87c6606fe34ccd029 Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 02:48:33 +0300 Subject: [PATCH 67/88] Update type message --- BtcRelaxTelegramBot.js | 4 ++++ data-sources/discogs.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index abe52dc..8617889 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -52,6 +52,10 @@ function processUpdateInfo(vEntry, vUpdateInfo)   var vUId = vUpdateInfo.update_id; var vHLib = libByName("TelegramUpdates"); var vUInfo = new Object(); +   if (vUpdateInfo.message !== undefined) + { + vUInfo["UpdateType"]="Message"; + }; vUInfo["UpdateId"]=vUId; var nUI=vHLib.create(vUInfo); nUI.set("TelegramBot",vEntry); diff --git a/data-sources/discogs.js b/data-sources/discogs.js index f01f228..97abaff 100644 --- a/data-sources/discogs.js +++ b/data-sources/discogs.js @@ -56,4 +56,4 @@ Discogs.prototype.extra = function(id) { if (result.genres !== undefined) result['genres'] = result.genres.join(); return result; -} +} \ No newline at end of file From 78902b06d14365ef358e39d31297789997efd069 Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 03:01:31 +0300 Subject: [PATCH 68/88] set RawInfo --- BtcRelaxTelegramBot.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index 8617889..e8b7f22 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -55,11 +55,14 @@ function processUpdateInfo(vEntry, vUpdateInfo)   if (vUpdateInfo.message !== undefined) { vUInfo["UpdateType"]="Message"; - }; +     var vM = vUpdateInfo.message;   + vUInfo["Text"]=vM.text; + }; vUInfo["UpdateId"]=vUId; var nUI=vHLib.create(vUInfo); nUI.set("TelegramBot",vEntry); - vEntry.set("UpdateId",vUId); +   var vRI=JSON.stringify(vUpdateInfo);  nUI.set("RawUpdateInfo",vRI); +   vEntry.set("UpdateId",vUId); }; From 56d9b0c69d88c82f1fbf7bddc0121977ad36c8a4 Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 03:34:28 +0300 Subject: [PATCH 69/88] add update info --- BtcRelaxTelegramBot.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index e8b7f22..7bbfa4b 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -61,7 +61,9 @@ function processUpdateInfo(vEntry, vUpdateInfo) vUInfo["UpdateId"]=vUId; var nUI=vHLib.create(vUInfo); nUI.set("TelegramBot",vEntry); -   var vRI=JSON.stringify(vUpdateInfo);  nUI.set("RawUpdateInfo",vRI); +   var vRI=JSON.stringify(vUpdateInfo); + message(vRI); + nUI.set("RawUpdateInfo",vRI);   vEntry.set("UpdateId",vUId); }; From 88aa6b13d2fa35d8ed4deeefc9837a1c1593a89d Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 06:07:42 +0300 Subject: [PATCH 70/88] add user --- BtcRelaxTelegramBot.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index 7bbfa4b..86b2562 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -56,17 +56,41 @@ function processUpdateInfo(vEntry, vUpdateInfo) { vUInfo["UpdateType"]="Message";     var vM = vUpdateInfo.message;   - vUInfo["Text"]=vM.text; - }; + vUInfo["Text"]=vM.text; + var vUF=vM.from; + var vUsr=getUser(vUF); + vUsr.set("TelegramBot",vEntry); + }; vUInfo["UpdateId"]=vUId; var nUI=vHLib.create(vUInfo); nUI.set("TelegramBot",vEntry);   var vRI=JSON.stringify(vUpdateInfo); - message(vRI); nUI.set("RawUpdateInfo",vRI);   vEntry.set("UpdateId",vUId); }; +function getUser(vUser) +{ + var vUL=libByName("TelegramUsers"); + var vID=vUser.id; +   for (var UInfo in vUL) + { + var vU=vUL[UInfo]; + if (vID==vU.id) + { + return(vU); + }; + }; + var nU = new Object(); + nU["UserId"]=vID; + nU["UserName"]=vUser.username; + nU["isBot"]=vUser.is_bot; + var nUE=vUL.create(nU); + return nUE; +}; + + + var vC=entry(); prepareUpdateRequest(vC); From 3661754dca8a75f73c4719d1e8d2c99372e5c213 Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 06:13:51 +0300 Subject: [PATCH 71/88] Current user mdg --- BtcRelaxTelegramBot.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index 86b2562..42a7503 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -76,8 +76,10 @@ function getUser(vUser)   for (var UInfo in vUL) { var vU=vUL[UInfo]; - if (vID==vU.id) + var cId=vU.id; +       if (vID===cId) { + message(vID); return(vU); }; }; From 19e0c055505c04145d097b1adaf3d8d019e8a375 Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 06:21:19 +0300 Subject: [PATCH 72/88] Add users info --- BtcRelaxTelegramBot.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index 42a7503..a7571d4 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -76,10 +76,9 @@ function getUser(vUser)   for (var UInfo in vUL) { var vU=vUL[UInfo]; - var cId=vU.id; + var cId=vU.UserId;       if (vID===cId) { - message(vID); return(vU); }; }; From b09c1ac9cfd50c4f052c87e3c82372fb5b81f4d2 Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 06:30:13 +0300 Subject: [PATCH 73/88] Fulfill user info --- BtcRelaxTelegramBot.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index a7571d4..81a1af8 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -85,6 +85,8 @@ function getUser(vUser) var nU = new Object(); nU["UserId"]=vID; nU["UserName"]=vUser.username; + nU["FirstName"]=vUser.first_name; + nU["LastName"]=vUser.last_name; nU["isBot"]=vUser.is_bot; var nUE=vUL.create(nU); return nUE; From 97803ee0e146cc5ccf28439c87e0bf15f39dfa86 Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 06:35:51 +0300 Subject: [PATCH 74/88] User --- BtcRelaxTelegramBot.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index 81a1af8..dadfb2c 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -72,12 +72,13 @@ function processUpdateInfo(vEntry, vUpdateInfo) function getUser(vUser) { var vUL=libByName("TelegramUsers"); - var vID=vUser.id; + var vID=vUser.UserId;   for (var UInfo in vUL) { var vU=vUL[UInfo]; var cId=vU.UserId; -       if (vID===cId) +       message(cId); + if (vID===cId) { return(vU); }; From e7b734d63e709e33cbbdad711c7545308c7b2ffd Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 06:43:59 +0300 Subject: [PATCH 75/88] Message user id From ed94c3a596ef6dd6682007c8a146e7685779ff30 Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 06:48:09 +0300 Subject: [PATCH 76/88] Stop when founD --- BtcRelaxTelegramBot.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index dadfb2c..b8672d6 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -80,7 +80,8 @@ function getUser(vUser)       message(cId); if (vID===cId) { - return(vU); + return vU; + break; }; }; var nU = new Object(); From bc0a1eb29654ab12057cab69c5cf53b692cd6f42 Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 06:52:43 +0300 Subject: [PATCH 77/88] log user id --- BtcRelaxTelegramBot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index b8672d6..5b5dd2f 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -72,12 +72,12 @@ function processUpdateInfo(vEntry, vUpdateInfo) function getUser(vUser) { var vUL=libByName("TelegramUsers"); - var vID=vUser.UserId; + var vID=vUser.id;   for (var UInfo in vUL) { var vU=vUL[UInfo]; var cId=vU.UserId; -       message(cId); +       log("Exists user id:"+cId); if (vID===cId) { return vU; From 948dc4b7ec5afb074a92002d04a4b3af09ba5819 Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 07:08:09 +0300 Subject: [PATCH 78/88] isUserEXists --- BtcRelaxTelegramBot.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index 5b5dd2f..b007c5b 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -73,7 +73,9 @@ function getUser(vUser) { var vUL=libByName("TelegramUsers"); var vID=vUser.id; -   for (var UInfo in vUL) +   log("Getting user id:"+vID); + var isUserExists=false; + for (var UInfo in vUL) { var vU=vUL[UInfo]; var cId=vU.UserId; @@ -81,17 +83,21 @@ function getUser(vUser) if (vID===cId) { return vU; + isUserExists=true; break; }; }; - var nU = new Object(); - nU["UserId"]=vID; - nU["UserName"]=vUser.username; - nU["FirstName"]=vUser.first_name; - nU["LastName"]=vUser.last_name; - nU["isBot"]=vUser.is_bot; - var nUE=vUL.create(nU); - return nUE; + if (!isUserExists) + { + var nU = new Object(); + nU["UserId"]=vID; + nU["UserName"]=vUser.username; + nU["FirstName"]=vUser.first_name; + nU["LastName"]=vUser.last_name; + nU["isBot"]=vUser.is_bot; + var nUE=vUL.create(nU); + return nUE; + }; }; From 448049c9e5abb42fe8e41e4a4e1d94725b316077 Mon Sep 17 00:00:00 2001 From: godchronos <72Jf0#EfH*59> Date: Tue, 24 Oct 2017 07:19:09 +0300 Subject: [PATCH 79/88] For recode --- BtcRelaxTelegramBot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index b007c5b..1bdb5b5 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -75,9 +75,9 @@ function getUser(vUser) var vID=vUser.id;   log("Getting user id:"+vID); var isUserExists=false; - for (var UInfo in vUL) + for (i=0;i Date: Tue, 24 Oct 2017 07:47:10 +0300 Subject: [PATCH 80/88] Add unique users --- BtcRelaxTelegramBot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index 1bdb5b5..13c0c06 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -73,9 +73,9 @@ function getUser(vUser) { var vUL=libByName("TelegramUsers"); var vID=vUser.id; -   log("Getting user id:"+vID); +   var vULE=vUL.entries(); var isUserExists=false; - for (i=0;i Date: Tue, 24 Oct 2017 10:11:52 +0000 Subject: [PATCH 81/88] Finalize user adding --- BtcRelaxTelegramBot.js | 78 ++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index 13c0c06..f0e943d 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -18,7 +18,7 @@ function prepareUpdateRequest(vEntry) } else { - cEntry.set("ServerRequest",mU+'getUpdates'); + cEntry.set("ServerRequest",mU+'getUpdates'); }; }; @@ -29,80 +29,78 @@ var vRequest = vEntry.field("ServerRequest"); var result=http().get(vRequest); if(result.code===200) { var json=JSON.parse(result.body); -   vEntry.set("ServerResponse",JSON.stringify(json)); + vEntry.set("ServerResponse",JSON.stringify(json)); var state =json.ok; if (state===true) { - var vUList=json.result; - for (var UInfo in vUList) - { - var uI=vUList[UInfo]; - var vLast=vEntry.field("UpdateId"); - if (vLast!==uI.update_id) - { - processUpdateInfo(vEntry,uI); - }; - }; + var vUList=json.result; + for (var UInfo in vUList) + { + var uI=vUList[UInfo]; + var vLast=vEntry.field("UpdateId"); + if (vLast!==uI.update_id) + { + processUpdateInfo(vEntry,uI); + }; + }; }; }; }; function processUpdateInfo(vEntry, vUpdateInfo) { -   var vUId = vUpdateInfo.update_id; + var vUId = vUpdateInfo.update_id; var vHLib = libByName("TelegramUpdates"); var vUInfo = new Object(); -   if (vUpdateInfo.message !== undefined) + if (vUpdateInfo.message !== undefined) { - vUInfo["UpdateType"]="Message"; -     var vM = vUpdateInfo.message;   - vUInfo["Text"]=vM.text; - var vUF=vM.from; - var vUsr=getUser(vUF); - vUsr.set("TelegramBot",vEntry); + vUInfo["UpdateType"]="Message"; + var vM = vUpdateInfo.message; + vUInfo["Text"]=vM.text; + var vUF=vM.from; + var vUsr=getUser(vUF); + vUsr.set("TelegramBot",vEntry); }; vUInfo["UpdateId"]=vUId; var nUI=vHLib.create(vUInfo); nUI.set("TelegramBot",vEntry); -   var vRI=JSON.stringify(vUpdateInfo); + var vRI=JSON.stringify(vUpdateInfo); nUI.set("RawUpdateInfo",vRI); -   vEntry.set("UpdateId",vUId); + vEntry.set("UpdateId",vUId); }; function getUser(vUser) { var vUL=libByName("TelegramUsers"); var vID=vUser.id; -   var vULE=vUL.entries(); + var vULE=vUL.entries(); + var count=vULE.length; + var isUserExists=false; - for (i=0;i Date: Wed, 25 Oct 2017 14:00:04 +0300 Subject: [PATCH 82/88] First working release --- BtcRelaxTelegramBot.js | 93 +++++++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 32 deletions(-) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index f0e943d..8f29c07 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -18,7 +18,7 @@ function prepareUpdateRequest(vEntry) } else { - cEntry.set("ServerRequest",mU+'getUpdates'); + cEntry.set("ServerRequest",mU+'getUpdates'); }; }; @@ -29,51 +29,78 @@ var vRequest = vEntry.field("ServerRequest"); var result=http().get(vRequest); if(result.code===200) { var json=JSON.parse(result.body); - vEntry.set("ServerResponse",JSON.stringify(json)); +   vEntry.set("ServerResponse",JSON.stringify(json)); var state =json.ok; if (state===true) { - var vUList=json.result; - for (var UInfo in vUList) - { - var uI=vUList[UInfo]; - var vLast=vEntry.field("UpdateId"); - if (vLast!==uI.update_id) - { - processUpdateInfo(vEntry,uI); - }; - }; + var vUList=json.result; + for (var UInfo in vUList) + { + var uI=vUList[UInfo]; + var vLast=vEntry.field("UpdateId"); + if (vLast!==uI.update_id) + { + processUpdateInfo(vEntry,uI); + }; + }; }; }; }; function processUpdateInfo(vEntry, vUpdateInfo) { - var vUId = vUpdateInfo.update_id; +   var vUId = vUpdateInfo.update_id; var vHLib = libByName("TelegramUpdates"); var vUInfo = new Object(); - if (vUpdateInfo.message !== undefined) +   if (vUpdateInfo.message !== undefined) { - vUInfo["UpdateType"]="Message"; - var vM = vUpdateInfo.message; - vUInfo["Text"]=vM.text; - var vUF=vM.from; - var vUsr=getUser(vUF); - vUsr.set("TelegramBot",vEntry); + vUInfo["UpdateType"]="Message"; +     var vM = vUpdateInfo.message;   + vUInfo["Text"]=vM.text; + var vUF=vM.from; + var vUsr=getUser(vUF); + vUsr.set("TelegramBot",vEntry); + var vCO=vM.chat; + var vC=getChat(vCO); + vC.set("TelegramBot",vEntry); }; vUInfo["UpdateId"]=vUId; var nUI=vHLib.create(vUInfo); nUI.set("TelegramBot",vEntry); - var vRI=JSON.stringify(vUpdateInfo); +   var vRI=JSON.stringify(vUpdateInfo); nUI.set("RawUpdateInfo",vRI); - vEntry.set("UpdateId",vUId); +   vEntry.set("UpdateId",vUId); +}; + +function getChat(vChat) +{ + var vCL=libByName("TelegramChats"); + var vCId=vChat.id; + var vCLE=vCL.entries(); + var count=vCLE.length; + for (i=0;i Date: Mon, 30 Oct 2017 13:12:50 +0200 Subject: [PATCH 83/88] Add user to chat --- BtcRelaxTelegramBot.js | 1 + 1 file changed, 1 insertion(+) diff --git a/BtcRelaxTelegramBot.js b/BtcRelaxTelegramBot.js index 8f29c07..e938dc9 100644 --- a/BtcRelaxTelegramBot.js +++ b/BtcRelaxTelegramBot.js @@ -62,6 +62,7 @@ function processUpdateInfo(vEntry, vUpdateInfo) vUsr.set("TelegramBot",vEntry); var vCO=vM.chat; var vC=getChat(vCO); + vC.set("Users",vUsr); vC.set("TelegramBot",vEntry); }; vUInfo["UpdateId"]=vUId; From b99be4eb67a035015ffdf22105fdc3f189222c17 Mon Sep 17 00:00:00 2001 From: "godChronos@tuta.io" Date: Sat, 11 Nov 2017 04:46:55 +0200 Subject: [PATCH 84/88] First build From 2c1d547830bd0341f6fe6518a86b474bfa312dfc Mon Sep 17 00:00:00 2001 From: "godChronos@tuta.io" Date: Sat, 11 Nov 2017 05:21:48 +0200 Subject: [PATCH 85/88] MainMetods From 814f6255198c5c47b9b0c4272e26263633a8b81a Mon Sep 17 00:00:00 2001 From: "godChronos@tuta.io" Date: Tue, 14 Nov 2017 16:40:26 +0200 Subject: [PATCH 86/88] Add token argument From 035dd0aaa7c691631fbf2df8b5e167a63cd513c7 Mon Sep 17 00:00:00 2001 From: "godChronos@tuta.io" Date: Tue, 14 Nov 2017 22:57:03 +0200 Subject: [PATCH 87/88] Validate entry From f5849e4e8077e6f4a152fc84e0f2fbead3635cd9 Mon Sep 17 00:00:00 2001 From: "godChronos@tuta.io" Date: Wed, 15 Nov 2017 15:03:01 +0200 Subject: [PATCH 88/88] BitGanjObject