2013-12-06 09:51:35 +01:00
|
|
|
var config = require('../config'),
|
2013-09-24 12:46:30 +02:00
|
|
|
path = require('path'),
|
2013-11-21 21:17:38 -06:00
|
|
|
when = require('when'),
|
2014-05-09 12:11:29 +02:00
|
|
|
errors = require('../errors'),
|
2013-11-07 16:00:39 +00:00
|
|
|
storage = require('../storage'),
|
2014-01-03 15:50:03 +00:00
|
|
|
updateCheck = require('../update-check'),
|
2014-07-01 00:26:08 +01:00
|
|
|
adminControllers;
|
2013-05-29 01:10:39 +01:00
|
|
|
|
2013-06-25 12:43:15 +01:00
|
|
|
adminControllers = {
|
2014-07-01 00:26:08 +01:00
|
|
|
// Route: index
|
|
|
|
// Path: /ghost/
|
|
|
|
// Method: GET
|
2014-02-26 23:15:31 +00:00
|
|
|
'index': function (req, res) {
|
|
|
|
/*jslint unparam:true*/
|
2014-06-23 17:01:43 +01:00
|
|
|
var userData,
|
2014-07-01 00:26:08 +01:00
|
|
|
// config we need on the frontend
|
2014-06-23 17:01:43 +01:00
|
|
|
frontConfig = {
|
2014-06-24 00:24:13 +01:00
|
|
|
apps: config().apps,
|
|
|
|
fileStorage: config().fileStorage
|
2014-06-23 17:01:43 +01:00
|
|
|
};
|
2014-05-09 00:00:10 -05:00
|
|
|
|
2014-02-25 10:51:12 +00:00
|
|
|
function renderIndex() {
|
2014-07-01 00:26:08 +01:00
|
|
|
res.render('default', {
|
|
|
|
user: userData,
|
|
|
|
config: JSON.stringify(frontConfig)
|
2014-02-25 10:51:12 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
when.join(
|
|
|
|
updateCheck(res),
|
|
|
|
when(renderIndex())
|
|
|
|
// an error here should just get logged
|
|
|
|
).otherwise(errors.logError);
|
|
|
|
},
|
|
|
|
// Route: upload
|
|
|
|
// Path: /ghost/upload/
|
|
|
|
// Method: POST
|
|
|
|
'upload': function (req, res) {
|
2013-09-28 14:54:26 +01:00
|
|
|
var type = req.files.uploadimage.type,
|
2013-08-13 21:04:07 +01:00
|
|
|
ext = path.extname(req.files.uploadimage.name).toLowerCase(),
|
2013-11-07 16:00:39 +00:00
|
|
|
store = storage.get_storage();
|
2013-09-28 14:54:26 +01:00
|
|
|
|
2013-11-12 11:37:54 -07:00
|
|
|
if ((type !== 'image/jpeg' && type !== 'image/png' && type !== 'image/gif' && type !== 'image/svg+xml')
|
|
|
|
|| (ext !== '.jpg' && ext !== '.jpeg' && ext !== '.png' && ext !== '.gif' && ext !== '.svg' && ext !== '.svgz')) {
|
2013-09-28 14:54:26 +01:00
|
|
|
return res.send(415, 'Unsupported Media Type');
|
|
|
|
}
|
2013-08-05 18:31:29 +01:00
|
|
|
|
2013-11-07 16:00:39 +00:00
|
|
|
store
|
|
|
|
.save(req.files.uploadimage)
|
2013-09-28 14:54:26 +01:00
|
|
|
.then(function (url) {
|
2013-11-07 16:00:39 +00:00
|
|
|
return res.send(url);
|
2013-09-28 14:54:26 +01:00
|
|
|
})
|
|
|
|
.otherwise(function (e) {
|
2014-01-11 13:40:21 +00:00
|
|
|
errors.logError(e);
|
|
|
|
return res.send(500, e.message);
|
2013-08-05 18:31:29 +01:00
|
|
|
});
|
2013-06-25 12:43:15 +01:00
|
|
|
}
|
|
|
|
};
|
2013-05-11 17:44:25 +01:00
|
|
|
|
2013-08-09 02:22:49 +01:00
|
|
|
module.exports = adminControllers;
|