Ghost/core/server/controllers/admin.js
Sebastian Gierlinger 2957b0175e Move image upload to API
closes #3252
- added `/ghost/api/v0.1/uploads/` endpoint
- removed upload method from `controller/admin.js`
- moved removal of temporary files from storage to endpoint (needed to
account for failed uploads)
- changed and moved tests
- Oversight: I think that we use `.otherwise()` and `.catch()` a bit
too extensive and mask the real error objects. We probably need an
error handling strategy at some point in the future.
2014-07-15 12:40:14 +02:00

56 lines
1.7 KiB
JavaScript

var config = require('../config'),
_ = require('lodash'),
when = require('when'),
api = require('../api'),
errors = require('../errors'),
updateCheck = require('../update-check'),
adminControllers;
adminControllers = {
// Route: index
// Path: /ghost/
// Method: GET
'index': function (req, res) {
/*jslint unparam:true*/
var userData,
// config we need on the frontend
frontConfig = {
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] });
}
});
}).finally(function () {
renderIndex();
}).catch(errors.logError);
}
};
module.exports = adminControllers;