From ba5c6b8d16cd19afda2b79219216a3d4bc1cb446 Mon Sep 17 00:00:00 2001 From: PassTheMayo Date: Sat, 9 Dec 2017 18:34:00 -0600 Subject: [PATCH 1/9] Added RethinkDB storage option & fixed config to use proper JSON --- README.md | 24 +++++++++++++++- config.js | 47 -------------------------------- config.json | 36 ++++++++++++++++++++++++ lib/document_stores/rethinkdb.js | 39 ++++++++++++++++++++++++++ server.js | 2 +- 5 files changed, 99 insertions(+), 49 deletions(-) delete mode 100644 config.js create mode 100644 config.json create mode 100644 lib/document_stores/rethinkdb.js diff --git a/README.md b/README.md index 23c3ca1..1a112c4 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,28 @@ forward on GETs. All of which are optional except `type` with very logical default values. +### RethinkDB + +To use the RethinkDB storage system, you must install the `rethinkdbdash` package via npm + +`npm install rethinkdbdash` + +Once you've done that, your config section should look like this: + +``` json +{ + "type": "rethinkdb", + "host": "127.0.0.1", + "port": 28015, + "db": "haste" +} +``` + +In order for this to work, the database must be pre-created before the script is ran. +Also, you must create an `uploads` table, which will store all the data for uploads. + +You can optionally add the `user` and `password` properties to use a user system. + ## Author John Crepezzi @@ -206,4 +228,4 @@ SOFTWARE * jQuery: MIT/GPL license * highlight.js: Copyright © 2006, Ivan Sagalaev -* highlightjs-coffeescript: WTFPL - Copyright © 2011, Dmytrii Nagirniak +* highlightjs-coffeescript: WTFPL - Copyright © 2011, Dmytrii Nagirniak \ No newline at end of file diff --git a/config.js b/config.js deleted file mode 100644 index 52ad004..0000000 --- a/config.js +++ /dev/null @@ -1,47 +0,0 @@ -{ - - "host": "0.0.0.0", - "port": 7777, - - "keyLength": 10, - - "maxLength": 400000, - - "staticMaxAge": 86400, - - "recompressStaticAssets": true, - - "logging": [ - { - "level": "verbose", - "type": "Console", - "colorize": true - } - ], - - "keyGenerator": { - "type": "phonetic" - }, - - "rateLimits": { - "categories": { - "normal": { - "totalRequests": 500, - "every": 60000 - } - } - }, - - "storage": { - "type": "redis", - "host": "0.0.0.0", - "port": 6379, - "db": 2, - "expire": 2592000 - }, - - "documents": { - "about": "./about.md" - } - -} diff --git a/config.json b/config.json new file mode 100644 index 0000000..6a23c5e --- /dev/null +++ b/config.json @@ -0,0 +1,36 @@ +{ + "host": "0.0.0.0", + "port": 7777, + "keyLength": 10, + "maxLength": 400000, + "staticMaxAge": 86400, + "recompressStaticAssets": true, + "logging": [ + { + "level": "verbose", + "type": "Console", + "colorize": true + } + ], + "keyGenerator": { + "type": "phonetic" + }, + "rateLimits": { + "categories": { + "normal": { + "totalRequests": 500, + "every": 60000 + } + } + }, + "storage": { + "type": "redis", + "host": "0.0.0.0", + "port": 6379, + "db": 2, + "expire": 2592000 + }, + "documents": { + "about": "./about.md" + } +} \ No newline at end of file diff --git a/lib/document_stores/rethinkdb.js b/lib/document_stores/rethinkdb.js new file mode 100644 index 0000000..fdfadff --- /dev/null +++ b/lib/document_stores/rethinkdb.js @@ -0,0 +1,39 @@ +var crypto = require('crypto'); +var 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); +}; + +RethinkDBStore.md5 = function (str) { + var md5sum = crypto.createHash('md5'); + md5sum.update(str); + return md5sum.digest('hex'); +}; + +RethinkDBStore.prototype.set = function (key, data, callback) { + try { + this.client.table('uploads').insert({ id: RethinkDBStore.md5(key), data: data }).run(function (error) { + if (error) return callback(false); + callback(true); + }); + } catch (err) { + callback(false); + } +}; + +RethinkDBStore.prototype.get = function (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; diff --git a/server.js b/server.js index 57bd3da..65d844b 100644 --- a/server.js +++ b/server.js @@ -11,7 +11,7 @@ var connect_rate_limit = require('connect-ratelimit'); var DocumentHandler = require('./lib/document_handler'); // Load the configuration and set some defaults -var config = JSON.parse(fs.readFileSync('./config.js', 'utf8')); +var config = require('./config.json'); config.port = process.env.PORT || config.port || 7777; config.host = process.env.HOST || config.host || 'localhost'; From cdd0cf373902e87606f24524057c560fcf2c3827 Mon Sep 17 00:00:00 2001 From: Jacob Gunther <16949253+PassTheMayo@users.noreply.github.com> Date: Mon, 11 Dec 2017 09:27:44 -0600 Subject: [PATCH 2/9] Fixed requested changes to RethinkDB handler --- lib/document_stores/rethinkdb.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/document_stores/rethinkdb.js b/lib/document_stores/rethinkdb.js index fdfadff..3fa60dc 100644 --- a/lib/document_stores/rethinkdb.js +++ b/lib/document_stores/rethinkdb.js @@ -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); From 1f9fdd205d60ecba3cd3b4af6fafad7ae1e7e796 Mon Sep 17 00:00:00 2001 From: Jacob Gunther <16949253+PassTheMayo@users.noreply.github.com> Date: Mon, 11 Dec 2017 09:28:27 -0600 Subject: [PATCH 3/9] Undid changes to server.js --- server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.js b/server.js index 65d844b..57bd3da 100644 --- a/server.js +++ b/server.js @@ -11,7 +11,7 @@ var connect_rate_limit = require('connect-ratelimit'); var DocumentHandler = require('./lib/document_handler'); // Load the configuration and set some defaults -var config = require('./config.json'); +var config = JSON.parse(fs.readFileSync('./config.js', 'utf8')); config.port = process.env.PORT || config.port || 7777; config.host = process.env.HOST || config.host || 'localhost'; From 0d8aec8d61d2e133312fe05e4ed704f92c959dda Mon Sep 17 00:00:00 2001 From: Jacob Gunther <16949253+PassTheMayo@users.noreply.github.com> Date: Mon, 11 Dec 2017 09:44:23 -0600 Subject: [PATCH 4/9] Oops, forgot to fix that file name --- config.json => config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename config.json => config.js (99%) diff --git a/config.json b/config.js similarity index 99% rename from config.json rename to config.js index 6a23c5e..70e81d8 100644 --- a/config.json +++ b/config.js @@ -33,4 +33,4 @@ "documents": { "about": "./about.md" } -} \ No newline at end of file +} From b31d143bcdb721cdbdbf8d3950d687fee9a5ad86 Mon Sep 17 00:00:00 2001 From: Jacob Gunther <16949253+PassTheMayo@users.noreply.github.com> Date: Mon, 11 Dec 2017 09:45:37 -0600 Subject: [PATCH 5/9] Revert config.js to previous state --- config.js | 79 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/config.js b/config.js index 70e81d8..52ad004 100644 --- a/config.js +++ b/config.js @@ -1,36 +1,47 @@ { - "host": "0.0.0.0", - "port": 7777, - "keyLength": 10, - "maxLength": 400000, - "staticMaxAge": 86400, - "recompressStaticAssets": true, - "logging": [ - { - "level": "verbose", - "type": "Console", - "colorize": true - } - ], - "keyGenerator": { - "type": "phonetic" - }, - "rateLimits": { - "categories": { - "normal": { - "totalRequests": 500, - "every": 60000 - } - } - }, - "storage": { - "type": "redis", - "host": "0.0.0.0", - "port": 6379, - "db": 2, - "expire": 2592000 - }, - "documents": { - "about": "./about.md" - } + + "host": "0.0.0.0", + "port": 7777, + + "keyLength": 10, + + "maxLength": 400000, + + "staticMaxAge": 86400, + + "recompressStaticAssets": true, + + "logging": [ + { + "level": "verbose", + "type": "Console", + "colorize": true + } + ], + + "keyGenerator": { + "type": "phonetic" + }, + + "rateLimits": { + "categories": { + "normal": { + "totalRequests": 500, + "every": 60000 + } + } + }, + + "storage": { + "type": "redis", + "host": "0.0.0.0", + "port": 6379, + "db": 2, + "expire": 2592000 + }, + + "documents": { + "about": "./about.md" + } + } From ff0fccd6c2c48f15749695d8c42c9e5e70337ac7 Mon Sep 17 00:00:00 2001 From: Jacob Gunther <16949253+PassTheMayo@users.noreply.github.com> Date: Mon, 11 Dec 2017 09:50:50 -0600 Subject: [PATCH 6/9] Oh noes! I didn't even notice that I had a typo... --- 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 3fa60dc..b7ee7ae 100644 --- a/lib/document_stores/rethinkdb.js +++ b/lib/document_stores/rethinkdb.js @@ -20,7 +20,7 @@ RethinkDBStore.md5 = (str) => { RethinkDBStore.prototype.set = (key, data, callback) => { try { - this.client.table('uploads').insert({ id: RethinkDBStore.md5(key), data: data }).run((error) =? { + this.client.table('uploads').insert({ id: RethinkDBStore.md5(key), data: data }).run((error) => { if (error) return callback(false); callback(true); }); From d9a53d3e6e417baec1f77950a51331d0b1fb9b5f Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 29 Dec 2017 20:42:11 +0100 Subject: [PATCH 7/9] Add note about paste expiration, cosmetic fixes. --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a112c4..2aebfa5 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,9 @@ something like: } ``` -Where `path` represents where you want the files stored +where `path` represents where you want the files stored. + +File storage currently does not support paste expiration, you can follow [#191](/../../issues/191) for status updates. ### Redis @@ -228,4 +230,4 @@ SOFTWARE * jQuery: MIT/GPL license * highlight.js: Copyright © 2006, Ivan Sagalaev -* highlightjs-coffeescript: WTFPL - Copyright © 2011, Dmytrii Nagirniak \ No newline at end of file +* highlightjs-coffeescript: WTFPL - Copyright © 2011, Dmytrii Nagirniak From 4d572a2ec0b8eb528243d713e14aaa320ade5bc2 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 30 Dec 2017 17:11:29 +0100 Subject: [PATCH 8/9] convert relative path to absolute --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2aebfa5..f01c68b 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ something like: where `path` represents where you want the files stored. -File storage currently does not support paste expiration, you can follow [#191](/../../issues/191) for status updates. +File storage currently does not support paste expiration, you can follow [#191](https://github.com/seejohnrun/haste-server/issues/191) for status updates. ### Redis From f5fbc8d19e52b82c0a1b91a4675eef2da4b6e555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Mon, 22 Jan 2018 14:51:15 +0100 Subject: [PATCH 9/9] Change to HTTPS in about.md Please also change the repo URL here on GitHub --- about.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/about.md b/about.md index 53cc39a..c446934 100644 --- a/about.md +++ b/about.md @@ -19,7 +19,7 @@ Most of the time I want to show you some text, it's coming from my current console session. We should make it really easy to take code from the console and send it to people. -`cat something | haste` # http://hastebin.com/1238193 +`cat something | haste` # https://hastebin.com/1238193 You can even take this a step further, and cut out the last step of copying the URL with: