Fixed requested changes to RethinkDB handler

This commit is contained in:
Jacob Gunther 2017-12-11 09:27:44 -06:00 committed by GitHub
parent ba5c6b8d16
commit cdd0cf3739
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);