Add profile backgroundImage api
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user