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
+20 -1
View File
@@ -48,6 +48,9 @@ exports = module.exports = {
setAvatar,
getAvatar,
getBackgroundImage,
setBackgroundImage,
AP_MAIL: 'mail',
AP_WEBADMIN: 'webadmin',
@@ -61,7 +64,7 @@ exports = module.exports = {
const ORDERED_ROLES = [ exports.ROLE_USER, exports.ROLE_USER_MANAGER, exports.ROLE_MAIL_MANAGER, exports.ROLE_ADMIN, exports.ROLE_OWNER ];
// the avatar field is special and not added here to reduce response sizes
// the avatar and backgroundImage fields are special and not added here to reduce response sizes
const USERS_FIELDS = [ 'id', 'username', 'email', 'fallbackEmail', 'password', 'salt', 'creationTime', 'inviteToken', 'resetToken', 'displayName',
'twoFactorAuthenticationEnabled', 'twoFactorAuthenticationSecret', 'active', 'source', 'role', 'resetTokenCreationTime', 'loginLocationsJson' ].join(',');
@@ -903,3 +906,19 @@ async function setAvatar(id, avatar) {
const result = await database.query('UPDATE users SET avatar=? WHERE id = ?', [ avatar, id ]);
if (result.length === 0) throw new BoxError(BoxError.NOT_FOUND, 'User not found');
}
async function getBackgroundImage(id) {
assert.strictEqual(typeof id, 'string');
const result = await database.query('SELECT backgroundImage FROM users WHERE id = ?', [ id ]);
if (result.length === 0) throw new BoxError(BoxError.NOT_FOUND, 'User not found');
return result[0].backgroundImage;
}
async function setBackgroundImage(id, backgroundImage) {
assert.strictEqual(typeof id, 'string');
assert(Buffer.isBuffer(backgroundImage));
const result = await database.query('UPDATE users SET backgroundImage=? WHERE id = ?', [ backgroundImage, id ]);
if (result.length === 0) throw new BoxError(BoxError.NOT_FOUND, 'User not found');
}