Add profile backgroundImage api

This commit is contained in:
Johannes Zellner
2022-05-14 19:41:32 +02:00
parent c5c62ff294
commit 6bd478b8b0
6 changed files with 63 additions and 1 deletions
+26
View File
@@ -6,6 +6,8 @@ exports = module.exports = {
update,
getAvatar,
setAvatar,
getBackgroundImage,
setBackgroundImage,
setPassword,
setTwoFactorAuthenticationSecret,
enableTwoFactorAuthentication,
@@ -107,6 +109,30 @@ async function getAvatar(req, res, next) {
res.send(avatar);
}
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`));
const 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));
next(new HttpSuccess(202, {}));
}
async function getBackgroundImage(req, res, next) {
assert.strictEqual(typeof req.user, 'object');
const [error, backgroundImage] = await safe(users.getBackgroundImage(req.user.id));
if (error) return next(BoxError.toHttpError(error));
res.send(backgroundImage);
}
async function setPassword(req, res, next) {
assert.strictEqual(typeof req.body, 'object');
assert.strictEqual(typeof req.user, 'object');