Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging

pull/1/head
yflory 6 years ago
commit 338b40face

@ -0,0 +1,12 @@
var config;
try {
config = require("../config/config");
if (config.adminEmail === 'i.did.not.read.my.config@cryptpad.fr') {
console.log("You can configure the administrator email (adminEmail) in your config/config.js file");
}
} catch (e) {
console.log("You can customize the configuration by copying config/config.example.js to config/config.js");
config = require("../config/config.example");
}
module.exports = config;

@ -0,0 +1,43 @@
/*jshint esversion: 6 */
var Pins = module.exports;
/*
takes contents of a pinFile (UTF8 string)
and the pin file's name
returns an array of of channel ids which are pinned
throw errors on pin logs with invalid pin data
*/
Pins.calculateFromLog = function (pinFile, fileName) {
var pins = {};
pinFile.split('\n').filter((x)=>(x)).map((l) => JSON.parse(l)).forEach((l) => {
switch (l[0]) {
case 'RESET': {
pins = {};
if (l[1] && l[1].length) { l[1].forEach((x) => { pins[x] = 1; }); }
//jshint -W086
// fallthrough
}
case 'PIN': {
l[1].forEach((x) => { pins[x] = 1; });
break;
}
case 'UNPIN': {
l[1].forEach((x) => { delete pins[x]; });
break;
}
default:
// FIXME logging
// TODO write to the error log
/* Log.error('CORRUPTED_PIN_LOG', {
line: JSON.stringify(l),
fileName: fileName,
}); */
console.error(new Error (JSON.stringify(l) + ' ' + fileName));
}
});
return Object.keys(pins);
};
// TODO refactor to include a streaming version for use in rpc.js as well

@ -4,31 +4,8 @@ const nThen = require('nthen');
const Pinned = require('./pinned'); const Pinned = require('./pinned');
const Nacl = require('tweetnacl'); const Nacl = require('tweetnacl');
const Path = require('path'); const Path = require('path');
const Config = require('./load-config'); const Pins = require('../lib/pins');
const Config = require('../lib/load-config');
const hashesFromPinFile = (pinFile, fileName) => {
var pins = {};
pinFile.split('\n').filter((x)=>(x)).map((l) => JSON.parse(l)).forEach((l) => {
switch (l[0]) {
case 'RESET': {
pins = {};
if (l[1] && l[1].length) { l[1].forEach((x) => { pins[x] = 1; }); }
//jshint -W086
// fallthrough
}
case 'PIN': {
l[1].forEach((x) => { pins[x] = 1; });
break;
}
case 'UNPIN': {
l[1].forEach((x) => { delete pins[x]; });
break;
}
default: throw new Error(JSON.stringify(l) + ' ' + fileName);
}
});
return Object.keys(pins);
};
var escapeKeyCharacters = function (key) { var escapeKeyCharacters = function (key) {
return key && key.replace && key.replace(/\//g, '-'); return key && key.replace && key.replace(/\//g, '-');
@ -61,7 +38,7 @@ nThen((waitFor) => {
let f = Path.join(pinPath, edPublic.slice(0, 2), edPublic + '.ndjson'); let f = Path.join(pinPath, edPublic.slice(0, 2), edPublic + '.ndjson');
Fs.readFile(f, waitFor((err, content) => { Fs.readFile(f, waitFor((err, content) => {
if (err) { throw err; } if (err) { throw err; }
pinned = hashesFromPinFile(content.toString('utf8'), f); pinned = Pins.calculateFromLog(content.toString('utf8'), f);
})); }));
}).nThen((waitFor) => { }).nThen((waitFor) => {
Pinned.load(waitFor((d) => { Pinned.load(waitFor((d) => {

@ -1,6 +1,6 @@
/* globals Buffer */ /* globals Buffer */
var Https = require('https'); var Https = require('https');
var Config = require("../config/config.js"); var Config = require("../lib/load-config");
var Package = require("../package.json"); var Package = require("../package.json");
var body = JSON.stringify({ var body = JSON.stringify({

@ -3,12 +3,7 @@ const Fs = require("fs");
const nThen = require("nthen"); const nThen = require("nthen");
const Saferphore = require("saferphore"); const Saferphore = require("saferphore");
const PinnedData = require('./pinneddata'); const PinnedData = require('./pinneddata');
let config; const config = require("../lib/load-config");
try {
config = require('./config/config');
} catch (e) {
config = require('./config/config.example');
}
if (!config.inactiveTime || typeof(config.inactiveTime) !== "number") { return; } if (!config.inactiveTime || typeof(config.inactiveTime) !== "number") { return; }

@ -3,7 +3,7 @@ var Path = require("path");
var nThen = require("nthen"); var nThen = require("nthen");
var config = require("./load-config"); var config = require("../lib/load-config");
var FileStorage = require('../' + config.storage || './storage/file'); var FileStorage = require('../' + config.storage || './storage/file');
var root = Path.resolve('../' + config.taskPath || './tasks'); var root = Path.resolve('../' + config.taskPath || './tasks');

@ -1,7 +0,0 @@
var config;
try {
config = require("../config/config");
} catch (e) {
config = require("../config/config.example");
}
module.exports = config;

@ -4,6 +4,7 @@ const Path = require("path");
const Semaphore = require('saferphore'); const Semaphore = require('saferphore');
const Once = require("../lib/once"); const Once = require("../lib/once");
const nThen = require('nthen'); const nThen = require('nthen');
const Pins = require("../lib/pins");
const sema = Semaphore.create(20); const sema = Semaphore.create(20);
@ -11,38 +12,6 @@ let dirList;
const fileList = []; const fileList = [];
const pinned = {}; const pinned = {};
// FIXME this seems to be duplicated in a few places.
// make it a library and put it in ./lib/
const checkPinStatus = (pinFile, fileName) => {
var pins = {};
pinFile.split('\n').filter((x)=>(x)).map((l) => JSON.parse(l)).forEach((l) => {
switch (l[0]) {
case 'RESET': {
pins = {};
if (l[1] && l[1].length) { l[1].forEach((x) => { pins[x] = 1; }); }
//jshint -W086
// fallthrough
}
case 'PIN': {
l[1].forEach((x) => { pins[x] = 1; });
break;
}
case 'UNPIN': {
l[1].forEach((x) => { delete pins[x]; });
break;
}
default:
// TODO write to the error log
/* Log.error('CORRUPTED_PIN_LOG', {
line: JSON.stringify(l),
fileName: fileName,
}); */
console.error(new Error (JSON.stringify(l) + ' ' + fileName));
}
});
return Object.keys(pins);
};
module.exports.load = function (cb, config) { module.exports.load = function (cb, config) {
var pinPath = config.pinPath || './pins'; var pinPath = config.pinPath || './pins';
var done = Once(cb); var done = Once(cb);
@ -84,7 +53,7 @@ module.exports.load = function (cb, config) {
waitFor.abort(); waitFor.abort();
return void done(err); return void done(err);
} }
const hashes = checkPinStatus(content.toString('utf8'), f); const hashes = Pins.calculateFromLog(content.toString('utf8'), f);
hashes.forEach((x) => { hashes.forEach((x) => {
(pinned[x] = pinned[x] || {})[f.replace(/.*\/([^/]*).ndjson$/, (x, y)=>y)] = 1; (pinned[x] = pinned[x] || {})[f.replace(/.*\/([^/]*).ndjson$/, (x, y)=>y)] = 1;
}); });
@ -106,6 +75,6 @@ if (!module.parent) {
console.log(x + ' ' + JSON.stringify(data[x])); console.log(x + ' ' + JSON.stringify(data[x]));
}); });
}, { }, {
pinPath: require("../config/config").pinPath pinPath: require("../lib/load-config").pinPath
}); });
} }

@ -3,36 +3,7 @@ const Fs = require('fs');
const Semaphore = require('saferphore'); const Semaphore = require('saferphore');
const nThen = require('nthen'); const nThen = require('nthen');
const Path = require('path'); const Path = require('path');
const Pins = require('../lib/pins');
/*
takes contents of a pinFile (UTF8 string)
and the pin file's name
returns an array of of channel ids which are pinned
throw errors on pin logs with invalid pin data
*/
const hashesFromPinFile = (pinFile, fileName) => {
var pins = {};
pinFile.split('\n').filter((x)=>(x)).map((l) => JSON.parse(l)).forEach((l) => {
switch (l[0]) {
case 'RESET': {
pins = {};
if (l[1] && l[1].length) { l[1].forEach((x) => { pins[x] = 1; }); }
break;
}
case 'PIN': {
l[1].forEach((x) => { pins[x] = 1; });
break;
}
case 'UNPIN': {
l[1].forEach((x) => { delete pins[x]; });
break;
}
default: throw new Error(JSON.stringify(l) + ' ' + fileName);
}
});
return Object.keys(pins);
};
/* /*
takes an array of pinned file names takes an array of pinned file names
@ -152,7 +123,7 @@ module.exports.load = function (config, cb) {
Fs.readFile(f, waitFor(returnAfter((err, content) => { Fs.readFile(f, waitFor(returnAfter((err, content) => {
if (err) { throw err; } if (err) { throw err; }
// get the list of channels pinned by this log // get the list of channels pinned by this log
const hashes = hashesFromPinFile(content.toString('utf8'), f); const hashes = Pins.calculateFromLog(content.toString('utf8'), f);
if (config.unpinned) { if (config.unpinned) {
hashes.forEach((x) => { pinned[x] = 1; }); hashes.forEach((x) => { pinned[x] = 1; });
} else { } else {

@ -11,17 +11,7 @@ var Package = require('./package.json');
var Path = require("path"); var Path = require("path");
var nThen = require("nthen"); var nThen = require("nthen");
var config; var config = require("./lib/load-config");
try {
config = require('./config/config');
} catch (e) {
console.log("You can customize the configuration by copying config/config.example.js to config/config.js");
config = require('./config/config.example');
}
if (config.adminEmail === 'i.did.not.read.my.config@cryptpad.fr') {
console.log("You can configure the administrator email (adminEmail) in your config/config.js file");
}
var websocketPort = config.websocketPort || config.httpPort; var websocketPort = config.websocketPort || config.httpPort;
var useSecureWebsockets = config.useSecureWebsockets || false; var useSecureWebsockets = config.useSecureWebsockets || false;

Loading…
Cancel
Save