Allow to unset background image
This commit is contained in:
@@ -112,11 +112,12 @@ async function getAvatar(req, res, next) {
|
||||
async function setBackgroundImage(req, res, next) {
|
||||
assert.strictEqual(typeof req.user, 'object');
|
||||
|
||||
console.log(req.files.backgroundImage)
|
||||
if (!req.files || !req.files.backgroundImage) return next(new HttpError(400, `backgroundImage must be a file`));
|
||||
let backgroundImage = null;
|
||||
|
||||
const backgroundImage = safe.fs.readFileSync(req.files.backgroundImage.path);
|
||||
if (!backgroundImage) return next(BoxError.toHttpError(new BoxError(BoxError.FS_ERROR, safe.error.message)));
|
||||
if (req.files && req.files.backgroundImage) {
|
||||
backgroundImage = safe.fs.readFileSync(req.files.backgroundImage.path);
|
||||
if (!backgroundImage) return next(BoxError.toHttpError(new BoxError(BoxError.FS_ERROR, safe.error.message)));
|
||||
}
|
||||
|
||||
const [error] = await safe(users.setBackgroundImage(req.user.id, backgroundImage));
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
Reference in New Issue
Block a user