Loading TODO.md +0 −1 Original line number Diff line number Diff line # TODO for OSS * tests * fix that chrome bug where it loads the doc twice * kick expiration back by increment on each view * Add file extensions ourselves to push state * add feedback for errors to UI - esp. too long lib/document_handler.js +2 −2 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ var DocumentHandler = function(options) { }; // Handle retrieving a document DocumentHandler.prototype.handleGet = function(key, response) { DocumentHandler.prototype.handleGet = function(key, response, skipExpire) { this.store.get(key, function(ret) { if (ret) { winston.verbose('retrieved document', { key: key }); Loading @@ -23,7 +23,7 @@ DocumentHandler.prototype.handleGet = function(key, response) { response.writeHead(404, { 'content-type': 'application/json' }); response.end(JSON.stringify({ message: 'document not found' })); } }); }, skipExpire); }; // Handle adding a new Document Loading lib/file_document_store.js +2 −2 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ var FileDocumentStore = function(options) { }; // 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) { FileDocumentStore.prototype.set = function(key, data, callback, setExpire) { try { var _this = this; fs.mkdir(this.basePath, '700', function() { Loading @@ -31,7 +31,7 @@ FileDocumentStore.prototype.set = function(key, data, callback) { }; // Get data from a file from key FileDocumentStore.prototype.get = function(key, callback) { FileDocumentStore.prototype.get = function(key, callback, setExpire) { fs.readFile(this.basePath + '/' + hashlib.md5(key), 'utf8', function(err, data) { if (err) { callback(false); Loading lib/redis_document_store.js +6 −2 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ RedisDocumentStore.prototype.set = function(key, data, callback, skipExpire) { RedisDocumentStore.prototype.setExpiration = function(key) { if (this.expire) { RedisDocumentStore.client.expire(key, this.expire, function(err, reply) { if (err || !reply) { if (err) { winston.error('failed to set expiry on key: ' + key); } }); Loading @@ -61,8 +61,12 @@ RedisDocumentStore.prototype.setExpiration = function(key) { }; // Get a file from a key RedisDocumentStore.prototype.get = function(key, callback) { RedisDocumentStore.prototype.get = function(key, callback, skipExpire) { var _this = this; RedisDocumentStore.client.get(key, function(err, reply) { if (!err && !skipExpire) { _this.setExpiration(key); } callback(err ? false : reply); }); }; Loading server.js +2 −1 Original line number Diff line number Diff line Loading @@ -89,7 +89,8 @@ connect.createServer( }); // get documents app.get('/documents/:id', function(request, response, next) { return documentHandler.handleGet(request.params.id, response); var skipExpire = !!config.documents[request.params.id]; return documentHandler.handleGet(request.params.id, response, skipExpire); }); }), // Otherwise, static Loading Loading
TODO.md +0 −1 Original line number Diff line number Diff line # TODO for OSS * tests * fix that chrome bug where it loads the doc twice * kick expiration back by increment on each view * Add file extensions ourselves to push state * add feedback for errors to UI - esp. too long
lib/document_handler.js +2 −2 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ var DocumentHandler = function(options) { }; // Handle retrieving a document DocumentHandler.prototype.handleGet = function(key, response) { DocumentHandler.prototype.handleGet = function(key, response, skipExpire) { this.store.get(key, function(ret) { if (ret) { winston.verbose('retrieved document', { key: key }); Loading @@ -23,7 +23,7 @@ DocumentHandler.prototype.handleGet = function(key, response) { response.writeHead(404, { 'content-type': 'application/json' }); response.end(JSON.stringify({ message: 'document not found' })); } }); }, skipExpire); }; // Handle adding a new Document Loading
lib/file_document_store.js +2 −2 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ var FileDocumentStore = function(options) { }; // 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) { FileDocumentStore.prototype.set = function(key, data, callback, setExpire) { try { var _this = this; fs.mkdir(this.basePath, '700', function() { Loading @@ -31,7 +31,7 @@ FileDocumentStore.prototype.set = function(key, data, callback) { }; // Get data from a file from key FileDocumentStore.prototype.get = function(key, callback) { FileDocumentStore.prototype.get = function(key, callback, setExpire) { fs.readFile(this.basePath + '/' + hashlib.md5(key), 'utf8', function(err, data) { if (err) { callback(false); Loading
lib/redis_document_store.js +6 −2 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ RedisDocumentStore.prototype.set = function(key, data, callback, skipExpire) { RedisDocumentStore.prototype.setExpiration = function(key) { if (this.expire) { RedisDocumentStore.client.expire(key, this.expire, function(err, reply) { if (err || !reply) { if (err) { winston.error('failed to set expiry on key: ' + key); } }); Loading @@ -61,8 +61,12 @@ RedisDocumentStore.prototype.setExpiration = function(key) { }; // Get a file from a key RedisDocumentStore.prototype.get = function(key, callback) { RedisDocumentStore.prototype.get = function(key, callback, skipExpire) { var _this = this; RedisDocumentStore.client.get(key, function(err, reply) { if (!err && !skipExpire) { _this.setExpiration(key); } callback(err ? false : reply); }); }; Loading
server.js +2 −1 Original line number Diff line number Diff line Loading @@ -89,7 +89,8 @@ connect.createServer( }); // get documents app.get('/documents/:id', function(request, response, next) { return documentHandler.handleGet(request.params.id, response); var skipExpire = !!config.documents[request.params.id]; return documentHandler.handleGet(request.params.id, response, skipExpire); }); }), // Otherwise, static Loading