Serving english timeago strings from server instead of round-trip
re-request on failure.
v1.18.x
Julian Lam 9 years ago
parent f1deaa6fa5
commit 621e0d145e

@ -109,17 +109,6 @@
$.getScript(RELATIVE_PATH + '/vendor/jquery/timeago/locales/jquery.timeago.' + languageCode + '-short.js').success(function() {
// Switch back to long-form
translator.toggleTimeagoShorthand();
}).fail(function() {
$.getScript(RELATIVE_PATH + '/vendor/jquery/timeago/locales/jquery.timeago.en-short.js').success(function() {
// Switch back to long-form
translator.toggleTimeagoShorthand();
});
});
}).fail(function() {
$.getScript(RELATIVE_PATH + '/vendor/jquery/timeago/locales/jquery.timeago.en-short.js').success(function() {
// Switch back to long-form
translator.toggleTimeagoShorthand();
$.getScript(RELATIVE_PATH + '/vendor/jquery/timeago/locales/jquery.timeago.en.js');
});
});

@ -5,6 +5,7 @@ var app,
admin: {}
},
async = require('async'),
fs = require('fs'),
path = require('path'),
csrf = require('csurf'),
_ = require('underscore'),
@ -302,6 +303,28 @@ middleware.applyBlacklist = function(req, res, next) {
});
};
middleware.processLanguages = function(req, res, next) {
var fallback = req.path.indexOf('-short') === -1 ? 'jquery.timeago.en.js' : 'jquery.timeago.en-short.js',
localPath = path.join(__dirname, '../../public/vendor/jquery/timeago/locales', req.path),
exists;
try {
exists = fs.accessSync(localPath, fs.F_OK | fs.R_OK);
} catch(e) {
exists = false;
}
if (exists) {
res.status(200).sendFile(localPath, {
maxAge: app.enabled('cache') ? 5184000000 : 0
});
} else {
res.status(200).sendFile(path.join(__dirname, '../../public/vendor/jquery/timeago/locales', fallback), {
maxAge: app.enabled('cache') ? 5184000000 : 0
});
}
};
module.exports = function(webserver) {
app = webserver;
middleware.admin = require('./admin')(webserver);

@ -144,11 +144,10 @@ module.exports = function(app, middleware, hotswapIds) {
}
app.use(middleware.privateUploads);
app.use(relativePath, express.static(path.join(__dirname, '../../', 'public'), {
maxAge: app.enabled('cache') ? 5184000000 : 0
}));
app.use('/vendor/jquery/timeago/locales', middleware.processLanguages);
app.use(controllers.handle404);
app.use(controllers.handleErrors);

Loading…
Cancel
Save