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
1 changed files with 16 additions and 16 deletions

View File

@ -1,26 +1,26 @@
var crypto = require('crypto');
var rethink = require('rethinkdbdash');
const crypto = require('crypto');
const rethink = require('rethinkdbdash');
var RethinkDBStore = function (options) {
this._options = options;
this._options.silent = true;
this._options.host = options.host || '127.0.0.1';
this._options.port = options.port || 28015;
this._options.db = options.db || 'haste';
this._options.user = options.user || 'admin';
this._options.password = options.password || '';
this.client = rethink(this._options);
var RethinkDBStore = (options) => {
this.client = rethink({
silent: true,
host: options.host || '127.0.0.1',
port: options.port || 28015,
db: options.db || 'haste',
user: options.user || 'admin',
password: options.password || ''
});
};
RethinkDBStore.md5 = function (str) {
var md5sum = crypto.createHash('md5');
RethinkDBStore.md5 = (str) => {
const md5sum = crypto.createHash('md5');
md5sum.update(str);
return md5sum.digest('hex');
};
RethinkDBStore.prototype.set = function (key, data, callback) {
RethinkDBStore.prototype.set = (key, data, callback) => {
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);
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) => {
if (error || !result) return callback(false);
callback(result.data);