remove alternative storage adaptors from core

pull/1/head
ansuz 8 years ago
parent 349b6799e0
commit b46f74cd78

@ -1,56 +0,0 @@
/*
As the log statement says, this module does nothing to persist your data
across sessions. If your process crashes for any reason, all pads will die.
This might be useful if you want to debug other parts of the codebase, if
you want to test out cryptpad without installing mongodb locally, or if
you don't want to rely on a remote db like the one at mongolab.com.
Maybe you just like the idea of a forgetful pad? To use this module, edit
config.js to include a directive `storage: './storage/amnesia'
Enjoy!
*/
module.exports.create = function(conf, cb){
console.log("Loading amnesiadb. This is a horrible idea in production,"+
" as data *will not* persist\n");
var db=[],
index=0;
if (conf.removeChannels) {
console.log("Server is set to remove channels %sms after the last remaining client leaves.", conf.channelRemovalTimeout);
}
cb({
message: function(channelName, content, cb){
var val = {
id:index++,
chan: channelName,
msg: content,
time: new Date().getTime(),
};
db.push(val);
if (cb) { cb(); }
},
getMessages: function(channelName, handler, cb){
db.sort(function(a,b){
return a.id - b.id;
});
db.filter(function(val){
return val.chan === channelName;
}).forEach(function(doc){
handler(doc.msg);
});
if (cb) { cb(); }
},
removeChannel: function (channelName, cb) {
var err = false;
db = db.filter(function (msg) {
return msg.chan !== channelName;
});
cb(err);
},
});
};

@ -1,51 +0,0 @@
var kad=require("kad");
var levelup=require("levelup");
/*
THiS FILE IS NOT PRODUCTION READY
DON'T USE IT!
*/
module.exports.create=function(conf,cb){
var dht= kad({
address:conf.kadAddress,
port:conf.kadPort,
storage:levelup(conf.kadStore),
seeds:conf.kadSeeds,
transport: kad.transports.UDP,
});
var getIndex=function(cName,f){
dht.get(cName+'=>index',function(e,out){
e && console.error(e) || f(Number(out));
});
};
cb({
message:function(cName, content, cb){
getIndex(cName, function(index){
index+=1;
dht.put(cName+'=>index', ''+index,function(e){
e && console.error("ERROR updating index (%s): %s",index,e) ||
console.log("PUT SUCCESS: %s", cName+'=>index')
});
dht.put(cName+'=>'+index, content, function(e){
e && console.error("ERROR updating value at %s: %s",cName+'=>'+index,e)||
console.log("PUT SUCCESS: %s", cName+'=>index')
cb();
});
});
},
getMessages: function(cName, cb){
getIndex(cName, function(index){
for(var i=index;i>=0;i--){
dht.get(cName+'=>'+i,function(e,out){
if(e) return console.error("DHT GET ERROR: %s",e);
console.log("GET SUCCESS: %s", cName+'=>index')
cb(out);
});
}
});
},
});
};

@ -1,73 +0,0 @@
var Level = require("level");
var nThen = require('nthen');
var getIndex = function(db, cName, cb) {
db.get(cName+'=>index', function(e, out){
if (e) {
if (e.notFound) {
cb(-1);
} else {
throw e;
}
return;
}
cb(parseInt(out));
});
};
var insert = function (db, channelName, content, cb) {
var index;
var doIt = function () {
db.locked = true;
nThen(function (waitFor) {
getIndex(db, channelName, waitFor(function (i) { index = i+1; }));
}).nThen(function (waitFor) {
db.put(channelName+'=>'+index, content, waitFor(function (e) { if (e) { throw e; } }));
}).nThen(function (waitFor) {
db.put(channelName+'=>index', ''+index, waitFor(function (e) { if (e) { throw e; } }));
}).nThen(function (waitFor) {
db.locked = false;
if (!db.queue.length) { return; }
db.queue.shift()();
}).nThen(cb);
};
if (db.locked) {
db.queue.push(doIt);
} else {
doIt();
}
};
var getMessages = function (db, channelName, msgHandler, cb) {
var index;
nThen(function (waitFor) {
getIndex(db, channelName, waitFor(function (i) {
index = i;
}));
}).nThen(function (waitFor) {
var again = function (i) {
db.get(channelName + '=>' + i, waitFor(function (e, out) {
if (e) { throw e; }
msgHandler(out);
if (i < index) { again(i+1); }
else if (cb) { cb(); }
}));
};
if (index > -1) { again(0); }
else if (cb) { cb(); }
});
};
module.exports.create = function (conf, cb) {
var db = Level(conf.levelPath || './test.level.db');
db.locked = false;
db.queue = [];
cb({
message: function (channelName, content, cb) {
insert(db, channelName, content, cb);
},
getMessages: function (channelName, msgHandler, cb) {
getMessages(db, channelName, msgHandler, cb);
}
});
};

@ -1,61 +0,0 @@
/*
* Copyright 2014 XWiki SAS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var MongoClient = require('mongodb').MongoClient;
var MONGO_URI = "mongodb://demo_user:demo_password@ds027769.mongolab.com:27769/demo_database";
var COLLECTION_NAME = 'cryptpad';
var insert = function (coll, channelName, content, cb) {
var val = {chan: channelName, msg:content, time: (new Date()).getTime()};
coll.insertOne(val, {}, function (err, r) {
console.log(r);
if (err || (r.insertedCount !== 1)) {
console.log('failed to insert ' + err);
return;
}
cb();
});
};
var getMessages = function (coll, channelName, cb) {
// find entries with a matching channelname
coll.find({chan:channelName})
// sort by _id, ascending
.sort( { _id: 1 } )
// iterate over entries
.forEach(function (doc) {
cb(doc.msg);
}, function (err) {
if (!err) { return; }
console.log('error ' + err);
});
};
module.exports.create = function (conf, cb) {
MongoClient.connect(conf.mongoUri, function(err, db) {
var coll = db.collection(conf.mongoCollectionName);
if (err) { throw err; }
cb({
message: function (channelName, content, cb) {
insert(coll, channelName, content, cb);
},
getMessages: function (channelName, msgHandler) {
getMessages(coll, channelName, msgHandler);
}
});
});
};

@ -1,58 +0,0 @@
var Knex = require("knex");
var getMessages = function (knex, channel, msgHandler, cb) {
return knex('messages')
.where({
channel: channel,
})
.select('*')
.then(function (rows) {
rows.forEach(function (row) {
msgHandler(row.content);
});
cb();
})
.catch(function (e) {
console.error(e);
cb();
});
};
var insert = function (knex, channel, content, cb) {
knex.table('messages').insert({
channel: channel,
content: content,
})
.then(function () {
cb();
});
};
module.exports.create = function (conf, cb) {
var knex = Knex({
dialect: 'sqlite3',
connection: conf.dbConnection,
useNullAsDefault: true,
});
knex.schema.hasTable('messages').then(function (exists) {
if (exists) { return; }
return knex.schema.createTable('messages', function (table) {
table.increments('id');
table.string('content');
table.string('channel');
table.timestamps();
});
})
.then(function () {
cb({
message: function (channelName, content, cb) {
insert(knex, channelName, content, cb);
},
getMessages: function (channelName, msgHandler, cb) {
getMessages(knex, channelName, msgHandler, cb);
},
});
});
};
Loading…
Cancel
Save