+async function updateMyAvatar (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const avatarPhysicalFile = req.files['avatarfile'][0]
+ const user = res.locals.oauth.token.user
+ const actor = user.Account.Actor
+
+ const extension = extname(avatarPhysicalFile.filename)
+ const avatarName = uuidv4() + extension
+ const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
+ await processImage(avatarPhysicalFile, destination, AVATARS_SIZE)
+
+ const avatar = await sequelizeTypescript.transaction(async t => {
+ const updatedActor = await updateActorAvatarInstance(actor, avatarName, t)
+ await updatedActor.save({ transaction: t })
+
+ await sendUpdateActor(user.Account, t)
+
+ return updatedActor.Avatar
+ })
+
+ return res
+ .json({
+ avatar: avatar.toFormattedJSON()
+ })
+ .end()
+}
+