Add trim history RPC command

pull/1/head
yflory 5 years ago
parent 6db7fbac0f
commit e6709f03aa

@ -739,6 +739,7 @@ define([
if (data.rtChannel) { chan.push(data.rtChannel); }
if (data.lastVersion) { chan.push(Hash.hrefToHexChannelId(data.lastVersion)); }
var history = common.makeUniversal('history');
var trimChannels = [];
NThen(function (waitFor) {
chan.forEach(function (c) {
common.getFileSize(c, waitFor(function (e, _bytes) {
@ -758,6 +759,7 @@ define([
}, waitFor(function (obj) {
if (obj && obj.error) { return; }
historyBytes = obj.size;
trimChannels = obj.channels;
}));
}).nThen(function () {
if (bytes === 0) { return void cb(void 0, $d); }
@ -806,7 +808,7 @@ define([
spinner.spin();
history.execCommand('TRIM_HISTORY', {
pad: true,
channels: chan.filter(function (c) { return c.length === 32; }),
channels: trimChannels,
teamId: typeof(owned) === "number" && owned
}, function (obj) {
if (obj && obj.error) {
@ -814,7 +816,6 @@ define([
// XXX what are the possible errors?
return;
}
// TODO: obj.warning?
spinner.hide();
$(size).append(h('div.alert.alert-success', Messages.trimHistory_success || 'ok')); // XXX
});

@ -163,13 +163,14 @@ define([
size += obj.size;
res.push({
channel: channel,
lastKnownHash: obj.hash
hash: obj.hash
});
}));
});
}).nThen(function () {
cb({
warning: warning.length ? warning : undefined,
channels: res,
size: size
});
});
@ -185,24 +186,14 @@ define([
var warning = [];
// If account trim history, get the correct channels here
if (data.account) {
channels = getAccountChannels(ctx);
}
nThen(function (waitFor) {
channels.forEach(function (chan) {
chan = chan; // XXX
waitFor = waitFor; // XXX
/*
rpc.trimHistory(chan, waitFor(function (err) {
channels.forEach(function (obj) {
rpc.trimHistory(obj, waitFor(function (err) {
if (err) {
chanWarning = true;
warning.push(err);
return;
}
}));
*/ // XXX TODO
});
}).nThen(function () {
// Only one channel and warning: error

@ -125,6 +125,17 @@ var factory = function (Util, Rpc) {
});
};
exp.trimHistory = function (data, _cb) {
var cb = Util.once(Util.mkAsync(_cb));
if (typeof(data) !== 'object' || !data.channel || !data.hash) {
return void cb('INVALID_ARGUMENTS');
}
rpc.send('TRIM_HISTORY', data, function (e) {
if (e) { return cb(e); }
cb();
});
};
exp.clearOwnedChannel = function (channel, cb) {
if (typeof(channel) !== 'string' || channel.length !== 32) {
return void cb('INVALID_ARGUMENTS');

@ -1221,6 +1221,7 @@ define([
var $button = $(button);
var size;
var channels = [];
nThen(function (waitFor) {
APP.history.execCommand('GET_HISTORY_SIZE', {
account: true,
@ -1230,9 +1231,9 @@ define([
waitFor.abort();
var error = h('div.alert.alert-danger', Messages.trimHistory_error || 'error'); // XXX
$(content).empty().append(error);
// TODO: obj.warning?
return;
}
channels = obj.channels;
size = UIElements.prettySize(Number(obj.size));
}));
}).nThen(function () {
@ -1247,14 +1248,12 @@ define([
$button.remove();
spinner.spin();
APP.history.execCommand('TRIM_HISTORY', {
account: true,
channels: []
channels: channels
}, function (obj) {
if (obj && obj.error) {
// XXX what are the possible errors?
return;
}
// TODO: obj.warning?
spinner.hide();
$(content).append(h('div.alert.alert-success', Messages.trimHistory_success || 'ok')); // XXX
});

Loading…
Cancel
Save