Allow to unset background image

This commit is contained in:
Johannes Zellner
2022-05-15 12:14:17 +02:00
parent 93bacd00da
commit f3c66056b5
2 changed files with 6 additions and 5 deletions
+5 -4
View File
@@ -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));