Ghost/core/server/controllers/admin.js

56 lines
1.7 KiB
JavaScript
Raw Normal View History

var config = require('../config'),
_ = require('lodash'),
when = require('when'),
api = require('../api'),
errors = require('../errors'),
updateCheck = require('../update-check'),
adminControllers;
2013-05-29 04:10:39 +04:00
adminControllers = {
// Route: index
// Path: /ghost/
// Method: GET
'index': function (req, res) {
/*jslint unparam:true*/
var userData,
// config we need on the frontend
frontConfig = {
2014-06-24 03:24:13 +04:00
apps: config().apps,
fileStorage: config().fileStorage
};
function renderIndex() {
res.render('default', {
user: userData,
config: JSON.stringify(frontConfig)
});
}
updateCheck().then(function () {
return updateCheck.showUpdateNotification();
}).then(function (updateAvailable) {
if (!updateAvailable) {
return when.resolve();
}
var notification = {
type: 'success',
location: 'top',
dismissible: false,
status: 'persistent',
message: 'A new version of Ghost is available! Hot Damn. <a href="https://ghost.org/download">Upgrade now</a>'
};
return api.notifications.browse().then(function (results) {
if (!_.some(results.notifications, { message: notification.message })) {
return api.notifications.add({ notifications: [notification] }, {context: {internal: true}});
}
});
}).finally(function () {
renderIndex();
}).catch(errors.logError);
}
};
2013-05-11 20:44:25 +04:00
module.exports = adminControllers;