Last modification is more specific (when possible).

pull/468/head
Chad Weider 2012-02-05 15:01:51 -08:00
parent 3da1464ae0
commit a5006255b7
1 changed files with 26 additions and 3 deletions

View File

@ -54,7 +54,7 @@ exports.minifyJS = function(req, res, next)
var filename = req.params['filename']; var filename = req.params['filename'];
res.header("Content-Type","text/javascript"); res.header("Content-Type","text/javascript");
lastModifiedDate(function (date) { lastModifiedDateOf(filename, function (error, date) {
date = new Date(date); date = new Date(date);
res.setHeader('last-modified', date.toUTCString()); res.setHeader('last-modified', date.toUTCString());
res.setHeader('date', (new Date()).toUTCString()); res.setHeader('date', (new Date()).toUTCString());
@ -161,7 +161,30 @@ function getAceFile(callback) {
}); });
} }
function lastModifiedDate(callback) { function lastModifiedDateOf(filename, callback) {
if (filename == 'ace.js') {
lastModifiedDateOfEverything(callback);
} else {
fs.stat(JS_DIR + filename, function (error, stats) {
if (error) {
if (error.code == "ENOENT") { // Stat the directory instead.
fs.stat(JS_DIR, function (error, stats) {
if (error) {
callback(error);
} else {
callback(null, stats.mtime.getTime());
}
});
} else {
callback(error);
}
} else {
callback(null, stats.mtime.getTime());
}
});
}
}
function lastModifiedDateOfEverything(callback) {
var folders2check = [CSS_DIR, JS_DIR]; var folders2check = [CSS_DIR, JS_DIR];
var latestModification = 0; var latestModification = 0;
//go trough this two folders //go trough this two folders
@ -197,7 +220,7 @@ function lastModifiedDate(callback) {
}, callback); }, callback);
}); });
}, function () { }, function () {
callback(latestModification); callback(null, latestModification);
}); });
} }