Merge branch 'master' of https://github.com/seejohnrun/haste-server
This commit is contained in:
		
							
								
								
									
										26
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								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](https://github.com/seejohnrun/haste-server/issues/191) for status updates.
 | 
			
		||||
 | 
			
		||||
### Redis
 | 
			
		||||
 | 
			
		||||
@@ -174,6 +176,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>
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								about.md
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								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:
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										39
									
								
								lib/document_stores/rethinkdb.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								lib/document_stores/rethinkdb.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
const crypto = require('crypto');
 | 
			
		||||
const rethink = require('rethinkdbdash');
 | 
			
		||||
 | 
			
		||||
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 = (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;
 | 
			
		||||
		Reference in New Issue
	
	Block a user