Send avatarType explicitly in profile

This commit is contained in:
Johannes Zellner
2024-01-29 13:35:54 +01:00
parent 35eb17a922
commit b03240ccb8
3 changed files with 15 additions and 9 deletions
+10 -1
View File
@@ -45,6 +45,14 @@ async function get(req, res, next) {
const [error, backgroundImage] = await safe(users.getBackgroundImage(req.user.id));
if (error) return next(BoxError.toHttpError(error));
const [avatarError, avatar] = await safe(users.getAvatar(req.user.id));
if (avatarError) return next(BoxError.toHttpError(error));
let avatarType;
if (avatar.equals(constants.AVATAR_GRAVATAR)) avatarType = constants.AVATAR_GRAVATAR;
else if (avatar.equals(constants.AVATAR_NONE)) avatarType = constants.AVATAR_NONE;
else avatarType = constants.AVATAR_CUSTOM;
const { fqdn:dashboardFqdn } = await dashboard.getLocation();
next(new HttpSuccess(200, {
@@ -57,7 +65,8 @@ async function get(req, res, next) {
role: req.user.role,
source: req.user.source,
hasBackgroundImage: !!backgroundImage,
avatarUrl: `https://${dashboardFqdn}/api/v1/profile/avatar/${req.user.id}`
avatarUrl: `https://${dashboardFqdn}/api/v1/profile/avatar/${req.user.id}`,
avatarType: avatarType.toString() // this is a Buffer
}));
}