mirror of
https://github.com/seejohnrun/haste-server.git
synced 2024-12-25 03:26:59 +00:00
Kick expirations back on view
This commit is contained in:
parent
cd9bf18d29
commit
92e0f579ca
5 changed files with 12 additions and 8 deletions
1
TODO.md
1
TODO.md
|
@ -1,6 +1,5 @@
|
|||
# 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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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…
Reference in a new issue