mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-18 04:27:56 +01:00
closes #4617
Serving english timeago strings from server instead of round-trip re-request on failure.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user