|
|
@ -28,7 +28,8 @@ var createLineHandler = Pins.createLineHandler = function (ref, errorHandler) {
|
|
|
|
// it's a weird API but it's faster than unpinning manually
|
|
|
|
// it's a weird API but it's faster than unpinning manually
|
|
|
|
var pins = ref.pins = {};
|
|
|
|
var pins = ref.pins = {};
|
|
|
|
ref.index = 0;
|
|
|
|
ref.index = 0;
|
|
|
|
ref.latest = 0;
|
|
|
|
ref.latest = 0; // the latest message (timestamp in ms)
|
|
|
|
|
|
|
|
ref.surplus = 0; // how many lines exist behind a reset
|
|
|
|
return function (line) {
|
|
|
|
return function (line) {
|
|
|
|
ref.index++;
|
|
|
|
ref.index++;
|
|
|
|
if (!Boolean(line)) { return; }
|
|
|
|
if (!Boolean(line)) { return; }
|
|
|
@ -52,6 +53,7 @@ var createLineHandler = Pins.createLineHandler = function (ref, errorHandler) {
|
|
|
|
case 'RESET': {
|
|
|
|
case 'RESET': {
|
|
|
|
pins = ref.pins = {};
|
|
|
|
pins = ref.pins = {};
|
|
|
|
if (l[1] && l[1].length) { l[1].forEach((x) => { ref.pins[x] = 1; }); }
|
|
|
|
if (l[1] && l[1].length) { l[1].forEach((x) => { ref.pins[x] = 1; }); }
|
|
|
|
|
|
|
|
ref.surplus = ref.index;
|
|
|
|
//jshint -W086
|
|
|
|
//jshint -W086
|
|
|
|
// fallthrough
|
|
|
|
// fallthrough
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -90,9 +92,14 @@ Pins.calculateFromLog = function (pinFile, fileName) {
|
|
|
|
pins/A+/A+hyhrQLrgYixOomZYxpuEhwfiVzKk1bBp+arH-zbgo=.ndjson
|
|
|
|
pins/A+/A+hyhrQLrgYixOomZYxpuEhwfiVzKk1bBp+arH-zbgo=.ndjson
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getSafeKeyFromPath = function (path) {
|
|
|
|
|
|
|
|
return path.replace(/^.*\//, '').replace(/\.ndjson/, '');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Pins.list = function (done, config) {
|
|
|
|
Pins.list = function (done, config) {
|
|
|
|
const pinPath = config.pinPath || './data/pins';
|
|
|
|
const pinPath = config.pinPath || './data/pins';
|
|
|
|
const plan = Plan(5);
|
|
|
|
const plan = Plan(config.workers || 5);
|
|
|
|
|
|
|
|
const handler = config.handler || function () {};
|
|
|
|
|
|
|
|
|
|
|
|
// TODO externalize this via optional handlers?
|
|
|
|
// TODO externalize this via optional handlers?
|
|
|
|
const stats = {
|
|
|
|
const stats = {
|
|
|
@ -106,8 +113,12 @@ Pins.list = function (done, config) {
|
|
|
|
console.log(label, info);
|
|
|
|
console.log(label, info);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const pinned = {};
|
|
|
|
|
|
|
|
|
|
|
|
// TODO replace this with lib-readline?
|
|
|
|
// TODO replace this with lib-readline?
|
|
|
|
const streamFile = function (path, cb) {
|
|
|
|
const streamFile = function (path, cb) {
|
|
|
|
|
|
|
|
const id = getSafeKeyFromPath(path);
|
|
|
|
|
|
|
|
|
|
|
|
return void Fs.readFile(path, 'utf8', function (err, body) {
|
|
|
|
return void Fs.readFile(path, 'utf8', function (err, body) {
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
const ref = {};
|
|
|
|
const ref = {};
|
|
|
@ -115,6 +126,7 @@ Pins.list = function (done, config) {
|
|
|
|
var lines = body.split('\n');
|
|
|
|
var lines = body.split('\n');
|
|
|
|
stats.lines += lines.length;
|
|
|
|
stats.lines += lines.length;
|
|
|
|
lines.forEach(pinHandler);
|
|
|
|
lines.forEach(pinHandler);
|
|
|
|
|
|
|
|
handler(ref, id, pinned);
|
|
|
|
cb(void 0, ref);
|
|
|
|
cb(void 0, ref);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -130,8 +142,6 @@ Pins.list = function (done, config) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const pinned = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scanDirectory(pinPath, function (err, paths) {
|
|
|
|
scanDirectory(pinPath, function (err, paths) {
|
|
|
|
if (err) { return; } // XXX
|
|
|
|
if (err) { return; } // XXX
|
|
|
|
paths.forEach(function (path) {
|
|
|
|
paths.forEach(function (path) {
|
|
|
|