diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/users.ts | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index ef2b63f51..d8ecbdbe2 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -8,6 +8,7 @@ import { retryTransactionWrapper } from '../../helpers/database-utils' | |||
8 | import { logger } from '../../helpers/logger' | 8 | import { logger } from '../../helpers/logger' |
9 | import { createReqFiles, getFormattedObjects } from '../../helpers/utils' | 9 | import { createReqFiles, getFormattedObjects } from '../../helpers/utils' |
10 | import { AVATAR_MIMETYPE_EXT, AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../../initializers' | 10 | import { AVATAR_MIMETYPE_EXT, AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../../initializers' |
11 | import { updateActorAvatarInstance } from '../../lib/activitypub' | ||
11 | import { sendUpdateUser } from '../../lib/activitypub/send' | 12 | import { sendUpdateUser } from '../../lib/activitypub/send' |
12 | import { createUserAccountAndChannel } from '../../lib/user' | 13 | import { createUserAccountAndChannel } from '../../lib/user' |
13 | import { | 14 | import { |
@@ -18,7 +19,6 @@ import { | |||
18 | import { usersUpdateMyAvatarValidator, videosSortValidator } from '../../middlewares/validators' | 19 | import { usersUpdateMyAvatarValidator, videosSortValidator } from '../../middlewares/validators' |
19 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' | 20 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' |
20 | import { UserModel } from '../../models/account/user' | 21 | import { UserModel } from '../../models/account/user' |
21 | import { AvatarModel } from '../../models/avatar/avatar' | ||
22 | import { VideoModel } from '../../models/video/video' | 22 | import { VideoModel } from '../../models/video/video' |
23 | 23 | ||
24 | const reqAvatarFile = createReqFiles('avatarfile', CONFIG.STORAGE.AVATARS_DIR, AVATAR_MIMETYPE_EXT) | 24 | const reqAvatarFile = createReqFiles('avatarfile', CONFIG.STORAGE.AVATARS_DIR, AVATAR_MIMETYPE_EXT) |
@@ -248,26 +248,12 @@ async function updateMyAvatar (req: express.Request, res: express.Response, next | |||
248 | 248 | ||
249 | await unlinkPromise(source) | 249 | await unlinkPromise(source) |
250 | 250 | ||
251 | const { avatar } = await sequelizeTypescript.transaction(async t => { | 251 | const avatar = await sequelizeTypescript.transaction(async t => { |
252 | const avatar = await AvatarModel.create({ | 252 | await updateActorAvatarInstance(actor, avatarName, t) |
253 | filename: avatarName | ||
254 | }, { transaction: t }) | ||
255 | 253 | ||
256 | if (actor.Avatar) { | 254 | await sendUpdateUser(user, t) |
257 | try { | ||
258 | await actor.Avatar.destroy({ transaction: t }) | ||
259 | } catch (err) { | ||
260 | logger.error('Cannot remove old avatar of user %s.', user.username, err) | ||
261 | } | ||
262 | } | ||
263 | 255 | ||
264 | actor.set('avatarId', avatar.id) | 256 | return avatar |
265 | actor.Avatar = avatar | ||
266 | await actor.save({ transaction: t }) | ||
267 | |||
268 | await sendUpdateUser(user, undefined) | ||
269 | |||
270 | return { actor, avatar } | ||
271 | }) | 257 | }) |
272 | 258 | ||
273 | return res | 259 | return res |