From dc0f151a7f0de6fc5480077e096e5ed87e0e573d Mon Sep 17 00:00:00 2001 From: Jacob Gunther Date: Sun, 15 Apr 2018 23:16:08 -0500 Subject: [PATCH 1/5] Fixed bug in RethinkDB document store and use classes --- lib/document_stores/rethinkdb.js | 70 +++++++++++++++++--------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/lib/document_stores/rethinkdb.js b/lib/document_stores/rethinkdb.js index b7ee7ae..431c2ab 100644 --- a/lib/document_stores/rethinkdb.js +++ b/lib/document_stores/rethinkdb.js @@ -1,39 +1,45 @@ const crypto = require('crypto'); const rethink = require('rethinkdbdash'); +const winston = require('winston'); -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 || '' - }); -}; +class RethinkDBStore { + constructor(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 = (str) => { + set(key, data, callback) { + this.client.table('pastes').insert({ id: RethinkDBStore.md5(key), data: data }).run((error) => { + if (error) { + callback(false); + winston.error('failed to insert to table', error); + return; + } + callback(true); + }); + } + + get(key, callback) { + this.client.table('pastes').get(RethinkDBStore.md5(key)).run((error, result) => { + if (error || !result) { + callback(false); + winston.error('failed to insert to table', error); + return; + } + callback(result.data); + }); + } +} + +module.exports = RethinkDBStore; +module.exports.md5 = (str) => { const md5sum = crypto.createHash('md5'); md5sum.update(str); return md5sum.digest('hex'); -}; - -RethinkDBStore.prototype.set = (key, data, callback) => { - try { - this.client.table('uploads').insert({ id: RethinkDBStore.md5(key), data: data }).run((error) => { - if (error) return callback(false); - callback(true); - }); - } catch (err) { - callback(false); - } -}; - -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); - }); -}; - -module.exports = RethinkDBStore; +}; \ No newline at end of file From 830dc1bc43b92ec3146a60e3b5c5d6da3540ee1f Mon Sep 17 00:00:00 2001 From: Jacob Gunther Date: Sun, 15 Apr 2018 23:16:39 -0500 Subject: [PATCH 2/5] Use uploads table --- lib/document_stores/rethinkdb.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/document_stores/rethinkdb.js b/lib/document_stores/rethinkdb.js index 431c2ab..04c5b6f 100644 --- a/lib/document_stores/rethinkdb.js +++ b/lib/document_stores/rethinkdb.js @@ -15,7 +15,7 @@ class RethinkDBStore { } set(key, data, callback) { - this.client.table('pastes').insert({ id: RethinkDBStore.md5(key), data: data }).run((error) => { + this.client.table('uploads').insert({ id: RethinkDBStore.md5(key), data: data }).run((error) => { if (error) { callback(false); winston.error('failed to insert to table', error); @@ -26,7 +26,7 @@ class RethinkDBStore { } get(key, callback) { - this.client.table('pastes').get(RethinkDBStore.md5(key)).run((error, result) => { + this.client.table('uploads').get(RethinkDBStore.md5(key)).run((error, result) => { if (error || !result) { callback(false); winston.error('failed to insert to table', error); From cd3bf26dbe8ed58f87af1b72a56320cbbd8efc36 Mon Sep 17 00:00:00 2001 From: Jacob Gunther <16949253+PassTheMayo@users.noreply.github.com> Date: Mon, 16 Apr 2018 10:52:53 -0500 Subject: [PATCH 3/5] Use local method for md5 --- lib/document_stores/rethinkdb.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/document_stores/rethinkdb.js b/lib/document_stores/rethinkdb.js index 04c5b6f..f945fa1 100644 --- a/lib/document_stores/rethinkdb.js +++ b/lib/document_stores/rethinkdb.js @@ -2,6 +2,12 @@ const crypto = require('crypto'); const rethink = require('rethinkdbdash'); const winston = require('winston'); +const md5 = (str) => { + const md5sum = crypto.createHash('md5'); + md5sum.update(str); + return md5sum.digest('hex'); +}; + class RethinkDBStore { constructor(options) { this.client = rethink({ @@ -15,7 +21,7 @@ class RethinkDBStore { } set(key, data, callback) { - this.client.table('uploads').insert({ id: RethinkDBStore.md5(key), data: data }).run((error) => { + this.client.table('uploads').insert({ id: md5(key), data: data }).run((error) => { if (error) { callback(false); winston.error('failed to insert to table', error); @@ -26,7 +32,7 @@ class RethinkDBStore { } get(key, callback) { - this.client.table('uploads').get(RethinkDBStore.md5(key)).run((error, result) => { + this.client.table('uploads').get(md5(key)).run((error, result) => { if (error || !result) { callback(false); winston.error('failed to insert to table', error); @@ -38,8 +44,3 @@ class RethinkDBStore { } module.exports = RethinkDBStore; -module.exports.md5 = (str) => { - const md5sum = crypto.createHash('md5'); - md5sum.update(str); - return md5sum.digest('hex'); -}; \ No newline at end of file From 5f6fefa7a6e702d82b8cc36df7ea183400bc0501 Mon Sep 17 00:00:00 2001 From: Jacob Gunther <16949253+PassTheMayo@users.noreply.github.com> Date: Mon, 30 Apr 2018 16:40:28 -0500 Subject: [PATCH 4/5] Fixed unnecessary logging when document not found --- lib/document_stores/rethinkdb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/document_stores/rethinkdb.js b/lib/document_stores/rethinkdb.js index f945fa1..ca825af 100644 --- a/lib/document_stores/rethinkdb.js +++ b/lib/document_stores/rethinkdb.js @@ -35,7 +35,7 @@ class RethinkDBStore { this.client.table('uploads').get(md5(key)).run((error, result) => { if (error || !result) { callback(false); - winston.error('failed to insert to table', error); + if (error) winston.error('failed to insert to table', error); return; } callback(result.data); From b087ac8dd1c752f8036f7685ab24ec0b9375aa60 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Thu, 12 Jul 2018 14:25:27 -0400 Subject: [PATCH 5/5] Added charset to raw content type Closes #230 --- lib/document_handler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/document_handler.js b/lib/document_handler.js index e5a6b56..83eb141 100644 --- a/lib/document_handler.js +++ b/lib/document_handler.js @@ -36,7 +36,7 @@ DocumentHandler.prototype.handleRawGet = function(key, response, skipExpire) { this.store.get(key, function(ret) { if (ret) { winston.verbose('retrieved raw document', { key: key }); - response.writeHead(200, { 'content-type': 'text/plain' }); + response.writeHead(200, { 'content-type': 'text/plain; charset=UTF-8' }); response.end(ret); } else {