aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-04 14:04:02 +0100
committerChocobozzz <me@florianbigard.com>2018-01-04 14:04:02 +0100
commita5625b416797fa20f7cccead6201f3faf9427080 (patch)
tree089ad8155f924385d5f528c96cbcec1b52f56c72 /server/controllers/api
parent4cb6d4578893db310297d7e118ce2fb7ecb952a3 (diff)
downloadPeerTube-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.ts24
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'
8import { logger } from '../../helpers/logger' 8import { logger } from '../../helpers/logger'
9import { createReqFiles, getFormattedObjects } from '../../helpers/utils' 9import { createReqFiles, getFormattedObjects } from '../../helpers/utils'
10import { AVATAR_MIMETYPE_EXT, AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../../initializers' 10import { AVATAR_MIMETYPE_EXT, AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../../initializers'
11import { updateActorAvatarInstance } from '../../lib/activitypub'
11import { sendUpdateUser } from '../../lib/activitypub/send' 12import { sendUpdateUser } from '../../lib/activitypub/send'
12import { createUserAccountAndChannel } from '../../lib/user' 13import { createUserAccountAndChannel } from '../../lib/user'
13import { 14import {
@@ -18,7 +19,6 @@ import {
18import { usersUpdateMyAvatarValidator, videosSortValidator } from '../../middlewares/validators' 19import { usersUpdateMyAvatarValidator, videosSortValidator } from '../../middlewares/validators'
19import { AccountVideoRateModel } from '../../models/account/account-video-rate' 20import { AccountVideoRateModel } from '../../models/account/account-video-rate'
20import { UserModel } from '../../models/account/user' 21import { UserModel } from '../../models/account/user'
21import { AvatarModel } from '../../models/avatar/avatar'
22import { VideoModel } from '../../models/video/video' 22import { VideoModel } from '../../models/video/video'
23 23
24const reqAvatarFile = createReqFiles('avatarfile', CONFIG.STORAGE.AVATARS_DIR, AVATAR_MIMETYPE_EXT) 24const 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