Commit 92e0f579 authored by John Crepezzi's avatar John Crepezzi
Browse files

Kick expirations back on view

parent cd9bf18d
Loading
Loading
Loading
Loading
+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
+2 −2
Original line number Diff line number Diff line
@@ -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 });
@@ -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
+2 −2
Original line number Diff line number Diff line
@@ -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() {
@@ -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);
+6 −2
Original line number Diff line number Diff line
@@ -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);
      }
    });
@@ -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);
  }); 
};
+2 −1
Original line number Diff line number Diff line
@@ -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