- // FIXME: user is not already a Sequelize instance?
- db.User.loadByUsername(res.locals.oauth.token.user.username)
- .then(user => {
- if (body.password !== undefined) user.password = body.password
- if (body.email !== undefined) user.email = body.email
- if (body.displayNSFW !== undefined) user.displayNSFW = body.displayNSFW
+ const user: UserModel = res.locals.oauth.token.user
+
+ if (body.password !== undefined) user.password = body.password
+ if (body.email !== undefined) user.email = body.email
+ if (body.nsfwPolicy !== undefined) user.nsfwPolicy = body.nsfwPolicy
+ if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo
+
+ await sequelizeTypescript.transaction(async t => {
+ await user.save({ transaction: t })
+
+ if (body.description !== undefined) user.Account.description = body.description
+ await user.Account.save({ transaction: t })
+
+ await sendUpdateActor(user.Account, t)
+ })
+
+ return res.sendStatus(204)
+}
+
+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
+ })