Remove deleted pads from the drive

pull/1/head
yflory 7 years ago
parent e50b99d5f7
commit 9a317018e2

@ -6,7 +6,7 @@ define([
], function (Util, Messages, Crypto) { ], function (Util, Messages, Crypto) {
var Nacl = window.nacl; var Nacl = window.nacl;
var Hash = {}; var Hash = window.CryptPad_Hash = {};
var uint8ArrayToHex = Util.uint8ArrayToHex; var uint8ArrayToHex = Util.uint8ArrayToHex;
var hexToBase64 = Util.hexToBase64; var hexToBase64 = Util.hexToBase64;

@ -1,6 +1,6 @@
(function (window) { (function (window) {
define([], function () { define([], function () {
var Util = {}; var Util = window.CryptPad_Util = {};
// If once is true, after the event has been fired, any further handlers which are // If once is true, after the event has been fired, any further handlers which are
// registered will fire immediately, and this type of event cannot be fired twice. // registered will fire immediately, and this type of event cannot be fired twice.

@ -196,6 +196,13 @@ define([
postMessage("CLEAR_OWNED_CHANNEL", channel, cb); postMessage("CLEAR_OWNED_CHANNEL", channel, cb);
}; };
common.getDeletedPads = function (cb) {
postMessage("GET_DELETED_PADS", null, function (obj) {
if (obj && obj.error) { return void cb(obj.error); }
cb(null, obj);
});
};
common.uploadComplete = function (cb) { common.uploadComplete = function (cb) {
postMessage("UPLOAD_COMPLETE", null, function (obj) { postMessage("UPLOAD_COMPLETE", null, function (obj) {
if (obj && obj.error) { return void cb(obj.error); } if (obj && obj.error) { return void cb(obj.error); }

@ -94,9 +94,27 @@ define([
return list; return list;
}; };
var getCanonicalChannelList = function () { var getExpirableChannelList = function () {
return Util.deduplicateString(getUserChannelList()).sort(); var list = [];
store.userObject.getFiles([store.userObject.FILES_DATA]).forEach(function (id) {
var data = store.userObject.getFileData(id);
var edPublic = store.proxy.edPublic;
// Push channels owned by someone else or channel that should have expired
// because of the expiration time
if ((data.owners && data.owners.indexOf(edPublic) === -1) ||
data.expire < (+new Date())) {
list.push(Hash.hrefToHexChannelId(data.href));
}
});
return list;
};
var getCanonicalChannelList = function (expirable) {
var list = expirable ? getExpirableChannelList() : getUserChannelList();
return Util.deduplicateString(list).sort();
}; };
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
/////////////////////// RPC ////////////////////////////////////// /////////////////////// RPC //////////////////////////////////////
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
@ -172,6 +190,37 @@ define([
}); });
}; };
var arePinsSynced = function (cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
var list = getCanonicalChannelList(false);
var local = Hash.hashChannelList(list);
store.rpc.getServerHash(function (e, hash) {
if (e) { return void cb(e); }
cb(null, hash === local);
});
};
var resetPins = function (cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
var list = getCanonicalChannelList(false);
store.rpc.reset(list, function (e, hash) {
if (e) { return void cb(e); }
cb(null, hash);
});
};
Store.getDeletedPads = function (data, cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
//var list = getCanonicalChannelList(true);
// TODO: rpc to get the deleted pads here and send this list in the callback
cb([]);
};
Store.uploadComplete = function (data, cb) { Store.uploadComplete = function (data, cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); } if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
store.rpc.uploadComplete(function (err, res) { store.rpc.uploadComplete(function (err, res) {
@ -196,27 +245,6 @@ define([
}); });
}; };
var arePinsSynced = function (cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
var list = getCanonicalChannelList();
var local = Hash.hashChannelList(list);
store.rpc.getServerHash(function (e, hash) {
if (e) { return void cb(e); }
cb(null, hash === local);
});
};
var resetPins = function (cb) {
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
var list = getCanonicalChannelList();
store.rpc.reset(list, function (e, hash) {
if (e) { return void cb(e); }
cb(null, hash);
});
};
Store.uploadChunk = function (data, cb) { Store.uploadChunk = function (data, cb) {
store.rpc.send.unauthenticated('UPLOAD', data.chunk, function (e, msg) { store.rpc.send.unauthenticated('UPLOAD', data.chunk, function (e, msg) {
cb({ cb({
@ -579,6 +607,8 @@ define([
contains = true; contains = true;
pad.atime = +new Date(); pad.atime = +new Date();
pad.title = title; pad.title = title;
pad.owners = owners;
pad.expire = expire;
// If the href is different, it means we have a stronger one // If the href is different, it means we have a stronger one
if (href !== pad.href) { isStronger = true; } if (href !== pad.href) { isStronger = true; }

@ -57,27 +57,11 @@ 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\|/, '');
/*try {
var decryptedMsg = Crypto.decrypt(msg, validateKey);
return decryptedMsg;
} catch (err) {
console.error(err);
return msg;
}*/
}; };
var msgOut = function (msg) { var msgOut = function (msg) {
if (readOnly) { return; } if (readOnly) { return; }
return msg; return msg;
/*try {
var cmsg = Crypto.encrypt(msg);
if (msg.indexOf('[4') === 0) { cmsg = 'cp|' + cmsg; }
return cmsg;
} catch (err) {
console.log(msg);
throw err;
}*/
}; };
var onMsg = function(peer, msg, wc, network, direct) { var onMsg = function(peer, msg, wc, network, direct) {
@ -93,7 +77,9 @@ define([], function () {
if (parsed.channel === wc.id && !validateKey) { if (parsed.channel === wc.id && !validateKey) {
validateKey = parsed.validateKey; validateKey = parsed.validateKey;
} }
if (parsed.channel === wc.id) {
padData = parsed; padData = parsed;
}
// We have to return even if it is not the current channel: // We have to return even if it is not the current channel:
// we don't want to continue with other channels messages here // we don't want to continue with other channels messages here
return; return;

@ -49,6 +49,9 @@ define([
case 'UNPIN_PADS': { case 'UNPIN_PADS': {
Store.unpinPads(data, cb); break; Store.unpinPads(data, cb); break;
} }
case 'GET_DELETED_PADS': {
Store.getDeletedPads(data, cb); break;
}
case 'GET_PINNED_USAGE': { case 'GET_PINNED_USAGE': {
Store.getPinnedUsage(data, cb); break; Store.getPinnedUsage(data, cb); break;
} }

@ -201,6 +201,8 @@ define({
// Inner drive needs to send command and receive updates from the async store // Inner drive needs to send command and receive updates from the async store
'Q_DRIVE_USEROBJECT': true, 'Q_DRIVE_USEROBJECT': true,
'Q_DRIVE_GETOBJECT': true, 'Q_DRIVE_GETOBJECT': true,
// Get the pads deleted from the server by other users to remove them from the drive
'Q_DRIVE_GETDELETED': true,
// Store's userObject need to send log messages to inner to display them in the UI // Store's userObject need to send log messages to inner to display them in the UI
'EV_DRIVE_LOG': true, 'EV_DRIVE_LOG': true,
// Refresh the drive when the drive has changed ('change' or 'remove' events) // Refresh the drive when the drive has changed ('change' or 'remove' events)

@ -380,6 +380,18 @@ define([
var trashpaths = _findFileInTrash([TRASH], file); var trashpaths = _findFileInTrash([TRASH], file);
return rootpaths.concat(templatepaths, trashpaths); return rootpaths.concat(templatepaths, trashpaths);
}; };
// Get drive ids of files from their channel ids
exp.findChannels = function (channels) {
var allFilesList = files[FILES_DATA];
var channels64 = channels.slice().map(Util.hexToBase64);
return getFiles([FILES_DATA]).filter(function (k) {
var data = allFilesList[k];
var parsed = Hash.parsePadUrl(data.href);
return parsed.hashData && channels64.indexOf(parsed.hashData.channel) !== -1;
});
};
exp.search = function (value) { exp.search = function (value) {
if (typeof(value) !== "string") { return []; } if (typeof(value) !== "string") { return []; }
value = value.trim(); value = value.trim();

@ -2975,6 +2975,14 @@ define([
refresh(); refresh();
UI.removeLoadingScreen(); UI.removeLoadingScreen();
sframeChan.query('Q_DRIVE_GETDELETED', null, function (err, data) {
var ids = filesOp.findChannels(data);
ids.forEach(function (id) {
var paths = filesOp.findFile(id);
filesOp.delete(paths, refresh);
});
});
}; };
var setHistory = function (bool, update) { var setHistory = function (bool, update) {
@ -3091,7 +3099,6 @@ define([
throw new Error("Corrupted drive"); throw new Error("Corrupted drive");
} }
andThen(common, proxy); andThen(common, proxy);
UI.removeLoadingScreen();
var onDisconnect = APP.onDisconnect = function (noAlert) { var onDisconnect = APP.onDisconnect = function (noAlert) {
setEditable(false); setEditable(false);

@ -56,6 +56,12 @@ define([
cb(obj); cb(obj);
}); });
}); });
sframeChan.on('Q_DRIVE_GETDELETED', function (data, cb) {
Cryptpad.getDeletedPads(function (err, obj) {
if (err) { return void console.error(err); }
cb(obj);
});
});
Cryptpad.onNetworkDisconnect.reg(function () { Cryptpad.onNetworkDisconnect.reg(function () {
sframeChan.event('EV_NETWORK_DISCONNECT'); sframeChan.event('EV_NETWORK_DISCONNECT');
}); });

Loading…
Cancel
Save