diff --git a/README.md b/README.md index 3f10a26e..1f3280dc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ # Haste -Haste is an open-source pastebin software written in node.js, which is easily installable in any network. It can be backed by either redis or filesystem, and has a very easy adapter interface for other stores. A publicly available version can be found at [hastebin.com](http://hastebin.com) +Haste is an open-source pastebin software written in node.js, which is easily +installable in any network. It can be backed by either redis or filesystem, +and has a very easy adapter interface for other stores. A publicly available +version can be found at [hastebin.com](http://hastebin.com) Major design objectives: @@ -8,11 +11,13 @@ Major design objectives: * Be really simple * Be easy to set up and use -Haste works really well with a little utility called haste-client, allowing you to do things like: +Haste works really well with a little utility called haste-client, allowing you +to do things like: `cat something | haste` -which will output a URL to share containing the contents of `cat something`'s STDOUT +which will output a URL to share containing the contents of `cat something`'s +STDOUT ## Tested Browsers @@ -35,7 +40,8 @@ which will output a URL to share containing the contents of `cat something`'s ST * `maxLength` - maximum length of a paste (default none) * `staticMaxAge` - max age for static assets (86400) * `recompressStatisAssets` - whether or not to compile static js assets (true) -* `documents` - static documents to serve (ex: http://hastebin.com/about.com) in addition to static assets. These will never expire. +* `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) @@ -63,13 +69,15 @@ Generates a random key } ``` -The _optional_ keySpace argument is a string of acceptable characters for the key. +The _optional_ keySpace argument is a string of acceptable characters +for the key. ## Storage ### File -To use file storage (the default) change the storage section in `config.js` to something like: +To use file storage (the default) change the storage section in `config.js` to +something like: ``` json { @@ -97,7 +105,9 @@ Once you've done that, your config section should look like: } ``` -You can also set an `expire` option to the number of seconds to expire keys in. This is off by default, but will constantly kick back expirations on each view or post. +You can also set an `expire` option to the number of seconds to expire keys in. +This is off by default, but will constantly kick back expirations on each view +or post. All of which are optional except `type` with very logical default values. @@ -117,7 +127,9 @@ Once you've done that, your config section should look like: } ``` -You can also set an `expire` option to the number of seconds to expire keys in. This behaves just like the redis expirations, but does not push expirations forward on GETs. +You can also set an `expire` option to the number of seconds to expire keys in. +This behaves just like the redis expirations, but does not push expirations +forward on GETs. All of which are optional except `type` with very logical default values. @@ -132,11 +144,23 @@ John Crepezzi Copyright © 2011 John Crepezzi -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the ‘Software’), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE ### Other components: diff --git a/TODO.md b/TODO.md deleted file mode 100644 index 77f05511..00000000 --- a/TODO.md +++ /dev/null @@ -1 +0,0 @@ -* add feedback for errors to UI - esp. too long diff --git a/about.md b/about.md index 815dccd9..731657aa 100644 --- a/about.md +++ b/about.md @@ -1,33 +1,37 @@ # Haste Sharing code is a good thing, and it should be _really_ easy to do it. -A lot of times, I want to show you something I'm seeing - and that's where we use pastebins. +A lot of times, I want to show you something I'm seeing - and that's where we +use pastebins. Haste is the prettiest, easist to use pastebin ever made. ## Basic Usage -Type what you want me to see, click "Save", and then copy the URL. Send that URL -to someone and they'll see what you see. +Type what you want me to see, click "Save", and then copy the URL. Send that +URL to someone and they'll see what you see. To make a new entry, click "New" (or type 'control + n') ## From the Console -Most of the time I want to show you some text, its coming from my current console session. -We should make it really easy to take code from the console and send it to people. +Most of the time I want to show you some text, its 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 -You can even take this a step further, and cut out the last step of copying the URL with: +You can even take this a step further, and cut out the last step of copying the +URL with: * osx: `cat something | haste | pbcopy` * linux: `cat something | haste | xsel` -After running that, the STDOUT output of `cat something` will show up at a URL which has -been conveniently copied to your clipboard. +After running that, the STDOUT output of `cat something` will show up at a URL +which has been conveniently copied to your clipboard. -That's all there is to that, and you can install it with `gem install haste` right now. +That's all there is to that, and you can install it with `gem install haste` +right now. * osx: you will need to have an up to date version of Xcode * linux: you will need to have rubygems and ruby-devel installed @@ -37,9 +41,10 @@ Pastes will stay for 30 days from their last view. ## Privacy -While the contents of hastebin.com are not directly crawled by any search robot that -obeys "robots.txt", there should be no great expectation of privacy. Post things at your -own risk. Not responsible for any loss of data or removed pastes. +While the contents of hastebin.com are not directly crawled by any search robot +that obeys "robots.txt", there should be no great expectation of privacy. Post +things at your own risk. Not responsible for any loss of data or removed +pastes. ## Open Source diff --git a/lib/document_handler.js b/lib/document_handler.js index 07291e75..0ecc773a 100644 --- a/lib/document_handler.js +++ b/lib/document_handler.js @@ -54,13 +54,15 @@ DocumentHandler.prototype.handlePost = function(request, response) { request.on('data', function(data) { if (!buffer) { response.writeHead(200, { 'content-type': 'application/json' }); - } + } buffer += data.toString(); if (_this.maxLength && buffer.length > _this.maxLength) { cancelled = true; winston.warn('document >maxLength', { maxLength: _this.maxLength }); response.writeHead(400, { 'content-type': 'application/json' }); - response.end(JSON.stringify({ message: 'Document exceeds maximum length.' })); + response.end( + JSON.stringify({ message: 'Document exceeds maximum length.' }) + ); } }); request.on('end', function(end) { @@ -96,7 +98,7 @@ DocumentHandler.prototype.chooseKey = function(callback) { } else { callback(key); } - }); + }); }; DocumentHandler.prototype.acceptableKey = function() { diff --git a/lib/file_document_store.js b/lib/document_stores/file.js similarity index 84% rename from lib/file_document_store.js rename to lib/document_stores/file.js index a0666fd5..d301db41 100644 --- a/lib/file_document_store.js +++ b/lib/document_stores/file.js @@ -19,19 +19,21 @@ FileDocumentStore.md5 = function(str) { return md5sum.digest('hex'); }; -// Save data in a file, key as md5 - since we don't know what we could be passed here +// Save data in a file, key as md5 - since we don't know what we could +// be passed here FileDocumentStore.prototype.set = function(key, data, callback, skipExpire) { try { var _this = this; fs.mkdir(this.basePath, '700', function() { - fs.writeFile(_this.basePath + '/' + _this.md5(key), data, 'utf8', function(err) { + var fn = _this.basePath + '/' + _this.md5(key); + fs.writeFile(fn, data, 'utf8', function(err) { if (err) { callback(false); } else { callback(true); if (_this.expire && !skipExpire) { - winston.warn('file store cannot set expirations on keys'); + winston.warn('file store cannot set expirations on keys'); } } }); @@ -44,14 +46,15 @@ FileDocumentStore.prototype.set = function(key, data, callback, skipExpire) { // Get data from a file from key FileDocumentStore.prototype.get = function(key, callback, skipExpire) { var _this = this; - fs.readFile(this.basePath + '/' + _this..md5(key), 'utf8', function(err, data) { + var fn = this.basePath + '/' + this.md5(key); + fs.readFile(fn, 'utf8', function(err, data) { if (err) { callback(false); } else { callback(data); if (_this.expire && !skipExpire) { - winston.warn('file store cannot set expirations on keys'); + winston.warn('file store cannot set expirations on keys'); } } }); diff --git a/lib/memcached_document_store.js b/lib/document_stores/memcached.js similarity index 87% rename from lib/memcached_document_store.js rename to lib/document_stores/memcached.js index e0ce4054..5aac6734 100644 --- a/lib/memcached_document_store.js +++ b/lib/document_stores/memcached.js @@ -24,7 +24,8 @@ MemcachedDocumentStore.connect = function(options) { }; // Save file in a key -MemcachedDocumentStore.prototype.set = function(key, data, callback, skipExpire) { +MemcachedDocumentStore.prototype.set = +function(key, data, callback, skipExpire) { MemcachedDocumentStore.client.set(key, data, function(err, reply) { err ? callback(false) : callback(true); }, skipExpire ? 0 : this.expire); @@ -36,7 +37,7 @@ MemcachedDocumentStore.prototype.get = function(key, callback, skipExpire) { MemcachedDocumentStore.client.get(key, function(err, reply) { callback(err ? false : reply); if (_this.expire && !skipExpire) { - winston.warn('memcache store does not currently push forward expirations on GET'); + winston.warn('store does not currently push forward expirations on GET'); } }); }; diff --git a/lib/redis_document_store.js b/lib/document_stores/redis.js similarity index 94% rename from lib/redis_document_store.js rename to lib/document_stores/redis.js index 346436f7..22f0e615 100644 --- a/lib/redis_document_store.js +++ b/lib/document_stores/redis.js @@ -23,7 +23,10 @@ RedisDocumentStore.connect = function(options) { RedisDocumentStore.client = redis.createClient(port, host); RedisDocumentStore.client.select(index, function(err, reply) { if (err) { - winston.error('error connecting to redis index ' + index, { error: err.message }); + winston.error( + 'error connecting to redis index ' + index, + { error: err.message } + ); process.exit(1); } else { @@ -67,7 +70,7 @@ RedisDocumentStore.prototype.get = function(key, callback, skipExpire) { _this.setExpiration(key); } callback(err ? false : reply); - }); + }); }; module.exports = RedisDocumentStore; diff --git a/lib/key_generators/random.js b/lib/key_generators/random.js index 517fb7c9..cd35f3d0 100644 --- a/lib/key_generators/random.js +++ b/lib/key_generators/random.js @@ -8,8 +8,10 @@ var RandomKeyGenerator = function(options) { // Generate a random key RandomKeyGenerator.prototype.createKey = function(keyLength) { var text = ''; + var index; for (var i = 0; i < keyLength; i++) { - text += this.keyspace.charAt(Math.floor(Math.random() * this.keyspace.length)); + index = Math.floor(Math.random() * this.keyspace.length); + text += this.keyspace.charAt(index); } return text; }; diff --git a/server.js b/server.js index a46b89b3..1023b7d4 100644 --- a/server.js +++ b/server.js @@ -34,7 +34,7 @@ if (!config.storage) { if (!config.storage.type) { config.storage.type = 'file'; } -var Store = require('./lib/' + config.storage.type + '_document_store'); +var Store = require('./lib/document_stores/' + config.storage.type); var preferredStore = new Store(config.storage); // Compress the static javascript assets @@ -45,8 +45,10 @@ if (config.recompressStaticAssets) { for (var i = 0; i < list.length; i++) { var item = list[i]; var orig_code, ast; - if ((item.indexOf('.js') === item.length - 3) && (item.indexOf('.min.js') === -1)) { - dest = item.substring(0, item.length - 3) + '.min' + item.substring(item.length - 3); + if ((item.indexOf('.js') === item.length - 3) && + (item.indexOf('.min.js') === -1)) { + dest = item.substring(0, item.length - 3) + '.min' + + item.substring(item.length - 3); orig_code = fs.readFileSync('./static/' + item, 'utf8'); ast = jsp.parse(orig_code); ast = pro.ast_mangle(ast); @@ -67,7 +69,10 @@ for (var name in config.documents) { }, true); } else { - winston.warn('failed to load static document', { name: name, path: path }); + winston.warn( + 'failed to load static document', + { name: name, path: path } + ); } }); } @@ -96,14 +101,18 @@ connect.createServer( var key = request.params.id.split('.')[0]; return documentHandler.handleRawGet(key, response, skipExpire); }); - // add documents + // add documents app.post('/documents', function(request, response, next) { return documentHandler.handlePost(request, response); }); // get documents app.get('/documents/:id', function(request, response, next) { var skipExpire = !!config.documents[request.params.id]; - return documentHandler.handleGet(request.params.id, response, skipExpire); + return documentHandler.handleGet( + request.params.id, + response, + skipExpire + ); }); }), // Otherwise, static diff --git a/spec/redis_document_store_spec.js b/spec/redis_document_store_spec.js index 1b06d6b1..8e2faf71 100644 --- a/spec/redis_document_store_spec.js +++ b/spec/redis_document_store_spec.js @@ -1,4 +1,4 @@ -var RedisDocumentStore = require('../lib/redis_document_store'); +var RedisDocumentStore = require('../lib/document_stores/redis'); var winston = require('winston'); winston.remove(winston.transports.Console);