From a570a73e981f07193c52db35f3aa14bd38fb70b1 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 10 Apr 2018 10:38:25 +0200 Subject: [PATCH] Send checkpoints' id to the server to avoid storing duplicates --- www/common/outer/chainpad-netflux-worker.js | 2 +- www/common/sframe-app-framework.js | 2 +- www/common/sframe-chainpad-netflux-outer.js | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/www/common/outer/chainpad-netflux-worker.js b/www/common/outer/chainpad-netflux-worker.js index adb6242de..1ef172172 100644 --- a/www/common/outer/chainpad-netflux-worker.js +++ b/www/common/outer/chainpad-netflux-worker.js @@ -68,7 +68,7 @@ define([], function () { // shim between chainpad and netflux var msgIn = function (peerId, msg) { - return msg.replace(/^cp\|/, ''); + return msg.replace(/^cp\|([A-Za-z0-9+\/=]+\|)?/, ''); }; var msgOut = function (msg) { diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index b7fb0b286..080daaa81 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -443,7 +443,7 @@ define([ patchTransformer: options.patchTransformer || ChainPad.SmartJSONTransformer, // cryptpad debug logging (default is 1) - // logLevel: 2, + logLevel: 2, validateContent: options.validateContent || function (content) { try { JSON.parse(content); diff --git a/www/common/sframe-chainpad-netflux-outer.js b/www/common/sframe-chainpad-netflux-outer.js index 2d592b65d..6b1224422 100644 --- a/www/common/sframe-chainpad-netflux-outer.js +++ b/www/common/sframe-chainpad-netflux-outer.js @@ -53,7 +53,16 @@ define([], function () { if (readOnly) { return; } try { var cmsg = Crypto.encrypt(msg); - if (msg.indexOf('[4') === 0) { cmsg = 'cp|' + cmsg; } + if (msg.indexOf('[4') === 0) { + var id = ''; + if (window.nacl) { + var hash = window.nacl.hash(window.nacl.util.decodeUTF8(msg)); + id = window.nacl.util.encodeBase64(hash.slice(0, 8)) + '|'; + } else { + console.log("Checkpoint sent without an ID. Nacl is missing."); + } + cmsg = 'cp|' + id + cmsg; + } return cmsg; } catch (err) { console.log(msg);