Make gravatar support explicit only
This commit is contained in:
+8
-14
@@ -6,7 +6,6 @@ exports = module.exports = {
|
||||
update,
|
||||
getAvatar,
|
||||
setAvatar,
|
||||
clearAvatar,
|
||||
changePassword,
|
||||
setTwoFactorAuthenticationSecret,
|
||||
enableTwoFactorAuthentication,
|
||||
@@ -16,6 +15,7 @@ exports = module.exports = {
|
||||
const assert = require('assert'),
|
||||
auditSource = require('../auditsource.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
constants = require('../constants.js'),
|
||||
HttpError = require('connect-lastmile').HttpError,
|
||||
HttpSuccess = require('connect-lastmile').HttpSuccess,
|
||||
safe = require('safetydance'),
|
||||
@@ -75,10 +75,14 @@ function update(req, res, next) {
|
||||
async function setAvatar(req, res, next) {
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
if (!req.files.avatar) return next(new HttpError(400, 'avatar is missing'));
|
||||
let avatar = req.body.avatar;
|
||||
|
||||
const avatar = safe.fs.readFileSync(req.files.avatar.path);
|
||||
if (!avatar) return next(BoxError.toHttpError(new BoxError(BoxError.FS_ERROR, safe.error.message)));
|
||||
if (req.files && req.files.avatar) {
|
||||
avatar = safe.fs.readFileSync(req.files.avatar.path);
|
||||
if (!avatar) return next(BoxError.toHttpError(new BoxError(BoxError.FS_ERROR, safe.error.message)));
|
||||
} else if (avatar !== constants.AVATAR_GRAVATAR && avatar !== constants.AVATAR_NONE) {
|
||||
return next(new HttpError(400, `avatar must be a file, ${constants.AVATAR_GRAVATAR} or ${constants.AVATAR_NONE}`));
|
||||
}
|
||||
|
||||
const [error] = await safe(users.setAvatar(req.user.id, avatar));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
@@ -86,21 +90,11 @@ async function setAvatar(req, res, next) {
|
||||
next(new HttpSuccess(202, {}));
|
||||
}
|
||||
|
||||
async function clearAvatar(req, res, next) {
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
const [error] = await safe(users.setAvatar(req.user.id, null));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(202, {}));
|
||||
}
|
||||
|
||||
async function getAvatar(req, res, next) {
|
||||
assert.strictEqual(typeof req.params.identifier, 'string');
|
||||
|
||||
const [error, avatar] = await safe(users.getAvatar(req.params.identifier));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
if (!avatar) return next(new HttpError(404, 'User not found'));
|
||||
|
||||
res.send(avatar);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user