-function removeUser (req: express.Request, res: express.Response, next: express.NextFunction) {
- db.User.loadById(req.params.id)
- .then(user => user.destroy())
- .then(() => res.sendStatus(204))
- .catch(err => {
- logger.error('Errors when removed the user.', err)
- return next(err)
+async function updateMe (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const body: UserUpdateMe = req.body
+
+ 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.displayName !== undefined) user.Account.name = body.displayName
+ 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
+ })
+
+ return res
+ .json({
+ avatar: avatar.toFormattedJSON()