diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-04 14:04:02 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-04 14:04:02 +0100 |
commit | a5625b416797fa20f7cccead6201f3faf9427080 (patch) | |
tree | 089ad8155f924385d5f528c96cbcec1b52f56c72 /server/controllers/api | |
parent | 4cb6d4578893db310297d7e118ce2fb7ecb952a3 (diff) | |
download | PeerTube-a5625b416797fa20f7cccead6201f3faf9427080.tar.gz PeerTube-a5625b416797fa20f7cccead6201f3faf9427080.tar.zst PeerTube-a5625b416797fa20f7cccead6201f3faf9427080.zip |
Refresh remote accounts
Diffstat (limited to 'server/controllers/api')
-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 |