1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2024-11-23 09:50:17 +01:00

Added RethinkDB storage option & fixed config to use proper JSON

This commit is contained in:
PassTheMayo 2017-12-09 18:34:00 -06:00
parent cfef588283
commit ba5c6b8d16
5 changed files with 99 additions and 49 deletions

View file

@ -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 <john.crepezzi@gmail.com>
@ -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

View file

@ -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"
}
}

36
config.json Normal file
View file

@ -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"
}
}

View file

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

View file

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