Loading README.md +27 −1 Original line number Diff line number Diff line Loading @@ -38,6 +38,32 @@ which will output a URL to share containing the contents of `cat something`'s ST * `documents` - static documents to serve (ex: http://hastebin.com/about.com) in addition to static assets. These will never expire. * `storage` - storage options (see below) * `logging` - logging preferences * `keyGenerator` - key generator options (see below) ## Key Generation ### Phonetic Attempts to generate phonetic keys, similar to `pwgen` ``` json { "type": "phonetic" } ``` ### Random Generates a random key ``` json { "type": "random", "keyspace": "abcdef" } ``` The _optional_ keySpace argument is a string of acceptable characters for the key. ## Storage Loading config.js +4 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,10 @@ } ], "keyGenerator": { "type": "phonetic" }, "storage": { "type": "redis", "host": "localhost", Loading lib/document_handler.js +2 −11 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ var DocumentHandler = function(options) { this.keyLength = options.keyLength || DocumentHandler.defaultKeyLength; this.maxLength = options.maxLength; // none by default this.store = options.store; this.keyGenerator = options.keyGenerator; }; DocumentHandler.defaultKeyLength = 10; Loading Loading @@ -87,7 +88,7 @@ DocumentHandler.prototype.handlePost = function(request, response) { // Get a random key that hasn't been already used DocumentHandler.prototype.chooseKey = function(callback) { var key = this.randomKey(); var key = this.keyGenerator.createKey(this.keyLength); var _this = this; this.store.get(key, function(ret) { if (ret) { Loading @@ -98,14 +99,4 @@ DocumentHandler.prototype.chooseKey = function(callback) { }); }; // Generate a random key DocumentHandler.prototype.randomKey = function() { var text = ''; var keyspace = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; for (var i = 0; i < this.keyLength; i++) { text += keyspace.charAt(Math.floor(Math.random() * keyspace.length)); } return text; }; module.exports = DocumentHandler; lib/key_generators/phonetic.js 0 → 100644 +32 −0 Original line number Diff line number Diff line // Draws inspiration from pwgen and http://tools.arantius.com/password var PhoneticKeyGenerator = function(options) { // No options }; // Generate a phonetic key PhoneticKeyGenerator.prototype.createKey = function(keyLength) { var text = ''; for (var i = 0; i < keyLength; i++) { text += (i % 2 == 0) ? this.randConsonant() : this.randVowel(); } return text; }; PhoneticKeyGenerator.consonants = 'bcdfghjklmnpqrstvwxy'; PhoneticKeyGenerator.vowels = 'aeiou'; // Get an random vowel PhoneticKeyGenerator.prototype.randVowel = function() { return PhoneticKeyGenerator.vowels[ Math.floor(Math.random() * PhoneticKeyGenerator.vowels.length) ]; }; // Get an random consonant PhoneticKeyGenerator.prototype.randConsonant = function() { return PhoneticKeyGenerator.consonants[ Math.floor(Math.random() * PhoneticKeyGenerator.consonants.length) ]; }; module.exports = PhoneticKeyGenerator; lib/key_generators/random.js 0 → 100644 +14 −0 Original line number Diff line number Diff line var RandomKeyGenerator = function(options) { this.keyspace = options.keyspace || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; }; // Generate a random key RandomKeyGenerator.prototype.createKey = function(keyLength) { var text = ''; for (var i = 0; i < keyLength; i++) { text += this.keyspace.charAt(Math.floor(Math.random() * this.keyspace.length)); } return text; }; module.exports = RandomKeyGenerator; Loading
README.md +27 −1 Original line number Diff line number Diff line Loading @@ -38,6 +38,32 @@ which will output a URL to share containing the contents of `cat something`'s ST * `documents` - static documents to serve (ex: http://hastebin.com/about.com) in addition to static assets. These will never expire. * `storage` - storage options (see below) * `logging` - logging preferences * `keyGenerator` - key generator options (see below) ## Key Generation ### Phonetic Attempts to generate phonetic keys, similar to `pwgen` ``` json { "type": "phonetic" } ``` ### Random Generates a random key ``` json { "type": "random", "keyspace": "abcdef" } ``` The _optional_ keySpace argument is a string of acceptable characters for the key. ## Storage Loading
config.js +4 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,10 @@ } ], "keyGenerator": { "type": "phonetic" }, "storage": { "type": "redis", "host": "localhost", Loading
lib/document_handler.js +2 −11 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ var DocumentHandler = function(options) { this.keyLength = options.keyLength || DocumentHandler.defaultKeyLength; this.maxLength = options.maxLength; // none by default this.store = options.store; this.keyGenerator = options.keyGenerator; }; DocumentHandler.defaultKeyLength = 10; Loading Loading @@ -87,7 +88,7 @@ DocumentHandler.prototype.handlePost = function(request, response) { // Get a random key that hasn't been already used DocumentHandler.prototype.chooseKey = function(callback) { var key = this.randomKey(); var key = this.keyGenerator.createKey(this.keyLength); var _this = this; this.store.get(key, function(ret) { if (ret) { Loading @@ -98,14 +99,4 @@ DocumentHandler.prototype.chooseKey = function(callback) { }); }; // Generate a random key DocumentHandler.prototype.randomKey = function() { var text = ''; var keyspace = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; for (var i = 0; i < this.keyLength; i++) { text += keyspace.charAt(Math.floor(Math.random() * keyspace.length)); } return text; }; module.exports = DocumentHandler;
lib/key_generators/phonetic.js 0 → 100644 +32 −0 Original line number Diff line number Diff line // Draws inspiration from pwgen and http://tools.arantius.com/password var PhoneticKeyGenerator = function(options) { // No options }; // Generate a phonetic key PhoneticKeyGenerator.prototype.createKey = function(keyLength) { var text = ''; for (var i = 0; i < keyLength; i++) { text += (i % 2 == 0) ? this.randConsonant() : this.randVowel(); } return text; }; PhoneticKeyGenerator.consonants = 'bcdfghjklmnpqrstvwxy'; PhoneticKeyGenerator.vowels = 'aeiou'; // Get an random vowel PhoneticKeyGenerator.prototype.randVowel = function() { return PhoneticKeyGenerator.vowels[ Math.floor(Math.random() * PhoneticKeyGenerator.vowels.length) ]; }; // Get an random consonant PhoneticKeyGenerator.prototype.randConsonant = function() { return PhoneticKeyGenerator.consonants[ Math.floor(Math.random() * PhoneticKeyGenerator.consonants.length) ]; }; module.exports = PhoneticKeyGenerator;
lib/key_generators/random.js 0 → 100644 +14 −0 Original line number Diff line number Diff line var RandomKeyGenerator = function(options) { this.keyspace = options.keyspace || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; }; // Generate a random key RandomKeyGenerator.prototype.createKey = function(keyLength) { var text = ''; for (var i = 0; i < keyLength; i++) { text += this.keyspace.charAt(Math.floor(Math.random() * this.keyspace.length)); } return text; }; module.exports = RandomKeyGenerator;