- function deleteUser (user, callback) {
- user.destroy().asCallback(callback)
- }
- ], function andFinally (err) {
- if (err) {
- logger.error('Errors when removed the user.', { error: err })
- return next(err)
+ await user.destroy()
+
+ return res.sendStatus(204)
+}
+
+async function updateMe (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const body: UserUpdateMe = req.body
+
+ // FIXME: user is not already a Sequelize instance?
+ const user = res.locals.oauth.token.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
+ if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo
+
+ await user.save()
+
+ return res.sendStatus(204)
+}
+
+async function updateMyAvatar (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const avatarPhysicalFile = req.files['avatarfile'][0]
+ const actor = res.locals.oauth.token.user.Account.Actor
+
+ const avatarDir = CONFIG.STORAGE.AVATARS_DIR
+ const source = join(avatarDir, avatarPhysicalFile.filename)
+ const extension = extname(avatarPhysicalFile.filename)
+ const avatarName = uuidv4() + extension
+ const destination = join(avatarDir, avatarName)
+
+ await sharp(source)
+ .resize(AVATARS_SIZE.width, AVATARS_SIZE.height)
+ .toFile(destination)
+
+ await unlinkPromise(source)
+
+ const { avatar } = await sequelizeTypescript.transaction(async t => {
+ const avatar = await AvatarModel.create({
+ filename: avatarName
+ }, { transaction: t })
+
+ if (actor.Avatar) {
+ await actor.Avatar.destroy({ transaction: t })