2023-10-20 22:35:26 +08:00
|
|
|
// SPDX-FileCopyrightText: 2023 XWiki CryptPad Team <contact@cryptpad.org> and contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2018-04-04 18:06:59 +08:00
|
|
|
const Fs = require('fs');
|
|
|
|
const nThen = require('nthen');
|
2019-09-27 19:32:57 +08:00
|
|
|
const Nacl = require('tweetnacl/nacl-fast');
|
2019-04-12 23:16:32 +08:00
|
|
|
const Path = require('path');
|
2019-04-17 20:46:46 +08:00
|
|
|
const Pins = require('../lib/pins');
|
2019-04-17 19:48:39 +08:00
|
|
|
const Config = require('../lib/load-config');
|
2018-04-04 18:06:59 +08:00
|
|
|
|
|
|
|
var escapeKeyCharacters = function (key) {
|
|
|
|
return key && key.replace && key.replace(/\//g, '-');
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const dataIdx = process.argv.indexOf('--data');
|
|
|
|
let edPublic;
|
|
|
|
if (dataIdx === -1) {
|
|
|
|
const hasEdPublic = process.argv.indexOf('--ed');
|
|
|
|
if (hasEdPublic === -1) { return void console.error("Missing ed argument"); }
|
|
|
|
edPublic = escapeKeyCharacters(process.argv[hasEdPublic+1]);
|
|
|
|
} else {
|
|
|
|
const deleteData = JSON.parse(process.argv[dataIdx+1]);
|
|
|
|
if (!deleteData.toSign || !deleteData.proof) { return void console.error("Invalid arguments"); }
|
|
|
|
// Check sig
|
|
|
|
const ed = Nacl.util.decodeBase64(deleteData.toSign.edPublic);
|
|
|
|
const signed = Nacl.util.decodeUTF8(JSON.stringify(deleteData.toSign));
|
|
|
|
const proof = Nacl.util.decodeBase64(deleteData.proof);
|
|
|
|
if (!Nacl.sign.detached.verify(signed, proof, ed)) { return void console.error("Invalid signature"); }
|
|
|
|
edPublic = escapeKeyCharacters(deleteData.toSign.edPublic);
|
|
|
|
}
|
|
|
|
|
|
|
|
let data = [];
|
|
|
|
let pinned = [];
|
|
|
|
|
|
|
|
nThen((waitFor) => {
|
2019-04-12 23:16:32 +08:00
|
|
|
var pinPath = Config.pinPath || './pins';
|
|
|
|
|
|
|
|
let f = Path.join(pinPath, edPublic.slice(0, 2), edPublic + '.ndjson');
|
2018-04-04 18:06:59 +08:00
|
|
|
Fs.readFile(f, waitFor((err, content) => {
|
|
|
|
if (err) { throw err; }
|
2019-04-17 20:46:46 +08:00
|
|
|
pinned = Pins.calculateFromLog(content.toString('utf8'), f);
|
2018-04-04 18:06:59 +08:00
|
|
|
}));
|
|
|
|
}).nThen((waitFor) => {
|
2020-02-14 06:46:10 +08:00
|
|
|
Pins.list(waitFor((err, d) => {
|
2018-04-04 18:06:59 +08:00
|
|
|
data = Object.keys(d);
|
|
|
|
}), {
|
|
|
|
exclude: [edPublic + '.ndjson']
|
|
|
|
});
|
|
|
|
}).nThen(() => {
|
|
|
|
console.log('Pads pinned by this user and not pinned by anybody else:');
|
|
|
|
pinned.forEach((p) => {
|
|
|
|
if (data.indexOf(p) === -1) {
|
|
|
|
console.log(p);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|