take cloudron avatars via multipart
This commit is contained in:
+10
-1
@@ -19,6 +19,7 @@ var assert = require('assert'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
path = require('path'),
|
||||
safe = require('safetydance'),
|
||||
settings = require('../settings.js'),
|
||||
SettingsError = settings.SettingsError;
|
||||
|
||||
@@ -63,7 +64,15 @@ function getCloudronName(req, res, next) {
|
||||
}
|
||||
|
||||
function setCloudronAvatar(req, res, next) {
|
||||
next(new HttpSuccess(200));
|
||||
assert.strictEqual(typeof req.files, 'object');
|
||||
|
||||
if (!req.files.avatar) return next(new HttpError(400, 'avatar must be provided'));
|
||||
var avatar = safe.fs.readFileSync(req.files.avatar.path, 'utf8');
|
||||
|
||||
settings.setCloudronAvatar(avatar, function (error) {
|
||||
if (error) return next(new HttpError(500, error));
|
||||
next(new HttpSuccess(202, {}));
|
||||
});
|
||||
}
|
||||
|
||||
function getCloudronAvatar(req, res) {
|
||||
|
||||
+19
-2
@@ -14,6 +14,8 @@ exports = module.exports = {
|
||||
getCloudronName: getCloudronName,
|
||||
setCloudronName: setCloudronName,
|
||||
|
||||
setCloudronAvatar: setCloudronAvatar,
|
||||
|
||||
getAll: getAll,
|
||||
|
||||
AUTOUPDATE_PATTERN_KEY: 'autoupdate_pattern',
|
||||
@@ -25,8 +27,10 @@ exports = module.exports = {
|
||||
|
||||
var assert = require('assert'),
|
||||
config = require('../config.js'),
|
||||
constants = require('../constants.js'),
|
||||
CronJob = require('cron').CronJob,
|
||||
safeCall = require('safetydance').safeCall,
|
||||
path = require('path'),
|
||||
safe = require('safetydance'),
|
||||
settingsdb = require('./settingsdb.js'),
|
||||
util = require('util');
|
||||
|
||||
@@ -63,7 +67,7 @@ function setAutoupdatePattern(pattern, callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
if (pattern !== 'never') { // check if pattern is valid
|
||||
var job = safeCall(function () { return new CronJob(pattern); });
|
||||
var job = safe.safeCall(function () { return new CronJob(pattern); });
|
||||
if (!job) return callback(new SettingsError(SettingsError.BAD_FIELD, 'Invalid pattern'));
|
||||
}
|
||||
|
||||
@@ -133,6 +137,19 @@ function setCloudronName(name, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function setCloudronAvatar(avatar, callback) {
|
||||
assert.strictEqual(typeof avatar, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
var filePath = path.join(config.baseDir(), constants.CLOUDRON_AVATAR_FILE);
|
||||
|
||||
if (!safe.fs.writeFileSync(filePath, avatar)) {
|
||||
return callback(new SettingsError(SettingsError.INTERNAL_ERROR, safe.error.message));
|
||||
}
|
||||
|
||||
callback(null);
|
||||
}
|
||||
|
||||
function getAll(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user