diff options
author | Chocobozzz <me@florianbigard.com> | 2018-09-20 11:31:48 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-09-20 11:45:59 +0200 |
commit | f201a749929ec8094a7ba6bcab7b196870ca5a5e (patch) | |
tree | 76c0f5f8a90705b5badb83f64ffdc395e468c1a9 /server/controllers/api | |
parent | 91411dba928678c15a5e99d9795ae061909e397d (diff) | |
download | PeerTube-f201a749929ec8094a7ba6bcab7b196870ca5a5e.tar.gz PeerTube-f201a749929ec8094a7ba6bcab7b196870ca5a5e.tar.zst PeerTube-f201a749929ec8094a7ba6bcab7b196870ca5a5e.zip |
Cache user token
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/users/index.ts | 5 | ||||
-rw-r--r-- | server/controllers/api/users/me.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/video-channel.ts | 10 |
3 files changed, 7 insertions, 10 deletions
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index d1163900b..8b8ebcd23 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -37,6 +37,7 @@ import { UserModel } from '../../../models/account/user' | |||
37 | import { OAuthTokenModel } from '../../../models/oauth/oauth-token' | 37 | import { OAuthTokenModel } from '../../../models/oauth/oauth-token' |
38 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' | 38 | import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' |
39 | import { meRouter } from './me' | 39 | import { meRouter } from './me' |
40 | import { deleteUserToken } from '../../../lib/oauth-model' | ||
40 | 41 | ||
41 | const auditLogger = auditLoggerFactory('users') | 42 | const auditLogger = auditLoggerFactory('users') |
42 | 43 | ||
@@ -267,7 +268,7 @@ async function updateUser (req: express.Request, res: express.Response, next: ex | |||
267 | const user = await userToUpdate.save() | 268 | const user = await userToUpdate.save() |
268 | 269 | ||
269 | // Destroy user token to refresh rights | 270 | // Destroy user token to refresh rights |
270 | if (roleChanged) await OAuthTokenModel.deleteUserToken(userToUpdate.id) | 271 | if (roleChanged) await deleteUserToken(userToUpdate.id) |
271 | 272 | ||
272 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) | 273 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) |
273 | 274 | ||
@@ -330,7 +331,7 @@ async function changeUserBlock (res: express.Response, user: UserModel, block: b | |||
330 | user.blockedReason = reason || null | 331 | user.blockedReason = reason || null |
331 | 332 | ||
332 | await sequelizeTypescript.transaction(async t => { | 333 | await sequelizeTypescript.transaction(async t => { |
333 | await OAuthTokenModel.deleteUserToken(user.id, t) | 334 | await deleteUserToken(user.id, t) |
334 | 335 | ||
335 | await user.save({ transaction: t }) | 336 | await user.save({ transaction: t }) |
336 | }) | 337 | }) |
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts index eba1e7edd..ff3a87b7f 100644 --- a/server/controllers/api/users/me.ts +++ b/server/controllers/api/users/me.ts | |||
@@ -353,7 +353,7 @@ async function updateMyAvatar (req: express.Request, res: express.Response, next | |||
353 | 353 | ||
354 | const userAccount = await AccountModel.load(user.Account.id) | 354 | const userAccount = await AccountModel.load(user.Account.id) |
355 | 355 | ||
356 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount.Actor, userAccount) | 356 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) |
357 | 357 | ||
358 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) | 358 | auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) |
359 | 359 | ||
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index 8fc340224..ff6bbe44c 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts | |||
@@ -56,7 +56,7 @@ videoChannelRouter.post('/:nameWithHost/avatar/pick', | |||
56 | // Check the rights | 56 | // Check the rights |
57 | asyncMiddleware(videoChannelsUpdateValidator), | 57 | asyncMiddleware(videoChannelsUpdateValidator), |
58 | updateAvatarValidator, | 58 | updateAvatarValidator, |
59 | asyncMiddleware(updateVideoChannelAvatar) | 59 | asyncRetryTransactionMiddleware(updateVideoChannelAvatar) |
60 | ) | 60 | ) |
61 | 61 | ||
62 | videoChannelRouter.put('/:nameWithHost', | 62 | videoChannelRouter.put('/:nameWithHost', |
@@ -107,13 +107,9 @@ async function updateVideoChannelAvatar (req: express.Request, res: express.Resp | |||
107 | const videoChannel = res.locals.videoChannel as VideoChannelModel | 107 | const videoChannel = res.locals.videoChannel as VideoChannelModel |
108 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON()) | 108 | const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON()) |
109 | 109 | ||
110 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel.Actor, videoChannel) | 110 | const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel) |
111 | 111 | ||
112 | auditLogger.update( | 112 | auditLogger.update(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannel.toFormattedJSON()), oldVideoChannelAuditKeys) |
113 | getAuditIdFromRes(res), | ||
114 | new VideoChannelAuditView(videoChannel.toFormattedJSON()), | ||
115 | oldVideoChannelAuditKeys | ||
116 | ) | ||
117 | 113 | ||
118 | return res | 114 | return res |
119 | .json({ | 115 | .json({ |