Fixed requested changes to RethinkDB handler
This commit is contained in:
parent
ba5c6b8d16
commit
cdd0cf3739
1 changed files with 16 additions and 16 deletions
|
@ -1,26 +1,26 @@
|
||||||
var crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
var rethink = require('rethinkdbdash');
|
const rethink = require('rethinkdbdash');
|
||||||
|
|
||||||
var RethinkDBStore = function (options) {
|
var RethinkDBStore = (options) => {
|
||||||
this._options = options;
|
this.client = rethink({
|
||||||
this._options.silent = true;
|
silent: true,
|
||||||
this._options.host = options.host || '127.0.0.1';
|
host: options.host || '127.0.0.1',
|
||||||
this._options.port = options.port || 28015;
|
port: options.port || 28015,
|
||||||
this._options.db = options.db || 'haste';
|
db: options.db || 'haste',
|
||||||
this._options.user = options.user || 'admin';
|
user: options.user || 'admin',
|
||||||
this._options.password = options.password || '';
|
password: options.password || ''
|
||||||
this.client = rethink(this._options);
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
RethinkDBStore.md5 = function (str) {
|
RethinkDBStore.md5 = (str) => {
|
||||||
var md5sum = crypto.createHash('md5');
|
const md5sum = crypto.createHash('md5');
|
||||||
md5sum.update(str);
|
md5sum.update(str);
|
||||||
return md5sum.digest('hex');
|
return md5sum.digest('hex');
|
||||||
};
|
};
|
||||||
|
|
||||||
RethinkDBStore.prototype.set = function (key, data, callback) {
|
RethinkDBStore.prototype.set = (key, data, callback) => {
|
||||||
try {
|
try {
|
||||||
this.client.table('uploads').insert({ id: RethinkDBStore.md5(key), data: data }).run(function (error) {
|
this.client.table('uploads').insert({ id: RethinkDBStore.md5(key), data: data }).run((error) =? {
|
||||||
if (error) return callback(false);
|
if (error) return callback(false);
|
||||||
callback(true);
|
callback(true);
|
||||||
});
|
});
|
||||||
|
@ -29,7 +29,7 @@ RethinkDBStore.prototype.set = function (key, data, callback) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
RethinkDBStore.prototype.get = function (key, callback) {
|
RethinkDBStore.prototype.get = (key, callback) => {
|
||||||
this.client.table('uploads').get(RethinkDBStore.md5(key)).run((error, result) => {
|
this.client.table('uploads').get(RethinkDBStore.md5(key)).run((error, result) => {
|
||||||
if (error || !result) return callback(false);
|
if (error || !result) return callback(false);
|
||||||
callback(result.data);
|
callback(result.data);
|
||||||
|
|
Loading…
Reference in a new issue