mirror of https://github.com/xwiki-labs/cryptpad
Send checkpoints' id to the server to avoid storing duplicates
This commit is contained in:
parent
2381dd0e39
commit
a570a73e98
|
@ -68,7 +68,7 @@ define([], function () {
|
||||||
|
|
||||||
// shim between chainpad and netflux
|
// shim between chainpad and netflux
|
||||||
var msgIn = function (peerId, msg) {
|
var msgIn = function (peerId, msg) {
|
||||||
return msg.replace(/^cp\|/, '');
|
return msg.replace(/^cp\|([A-Za-z0-9+\/=]+\|)?/, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
var msgOut = function (msg) {
|
var msgOut = function (msg) {
|
||||||
|
|
|
@ -443,7 +443,7 @@ define([
|
||||||
patchTransformer: options.patchTransformer || ChainPad.SmartJSONTransformer,
|
patchTransformer: options.patchTransformer || ChainPad.SmartJSONTransformer,
|
||||||
|
|
||||||
// cryptpad debug logging (default is 1)
|
// cryptpad debug logging (default is 1)
|
||||||
// logLevel: 2,
|
logLevel: 2,
|
||||||
validateContent: options.validateContent || function (content) {
|
validateContent: options.validateContent || function (content) {
|
||||||
try {
|
try {
|
||||||
JSON.parse(content);
|
JSON.parse(content);
|
||||||
|
|
|
@ -53,7 +53,16 @@ define([], function () {
|
||||||
if (readOnly) { return; }
|
if (readOnly) { return; }
|
||||||
try {
|
try {
|
||||||
var cmsg = Crypto.encrypt(msg);
|
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;
|
return cmsg;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
|
|
Loading…
Reference in New Issue