You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
8 years ago
|
define([
|
||
|
'/common/cryptpad-common.js',
|
||
|
'/common/rpc.js',
|
||
|
|
||
|
'/bower_components/tweetnacl/nacl-fast.min.js'
|
||
|
], function (Cryptpad, Rpc) {
|
||
|
|
||
|
var Nacl = window.nacl;
|
||
|
|
||
|
var deduplicate = function (array) {
|
||
|
var a = array.slice();
|
||
|
for(var i=0; i<a.length; i++) {
|
||
|
for(var j=i+1; j<a.length; j++) {
|
||
|
if(a[i] === a[j]) { a.splice(j--, 1); }
|
||
|
}
|
||
|
}
|
||
|
return a;
|
||
|
};
|
||
|
|
||
|
var create = function (network, ed) {
|
||
|
var exp = {};
|
||
|
var rpc = Rpc.create(network, ed);
|
||
|
|
||
|
var checkHash = exp.checkHash = function (fileList) {
|
||
|
//var fileList = fo.getFilesDataFiles();
|
||
|
var channelIdList = [];
|
||
|
fileList.forEach(function (href) {
|
||
|
var parsedHref = Cryptpad.parsePadUrl(href);
|
||
|
if (!parsedHref || !parsedHref.hash) { return; }
|
||
|
var parsedHash = Cryptpad.parseHash(parsedHref.hash);
|
||
|
if (!parsedHash || !parsedHash.channel) { return; }
|
||
|
channelIdList.push(Cryptpad.base64ToHex(parsedHash.channel));
|
||
|
});
|
||
|
var uniqueList = deduplicate(channelIdList).sort();
|
||
|
|
||
|
/*
|
||
|
1. every time you want to pin or unpid a pad you send a message to the server
|
||
|
2. the server sends back a hash of the sorted list of your pinned pads
|
||
|
3. you hash your sorted list of pinned pads that you should have according to your drive
|
||
|
4. compare them, if same
|
||
|
AWESOME
|
||
|
if they are not
|
||
|
UNPIN all, send all
|
||
|
|
||
|
*/
|
||
|
|
||
|
var hash = Nacl.util.encodeBase64(Nacl.hash(Nacl.util.decodeUTF8( JSON.stringify(uniqueList) )));
|
||
|
|
||
|
console.log(hash);
|
||
|
return hash;
|
||
|
};
|
||
|
|
||
|
return exp;
|
||
|
};
|
||
|
|
||
|
return { create: create };
|
||
|
});
|