From f201a749929ec8094a7ba6bcab7b196870ca5a5e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 20 Sep 2018 11:31:48 +0200 Subject: Cache user token --- server/controllers/api/users/index.ts | 5 +++-- server/controllers/api/users/me.ts | 2 +- server/controllers/api/video-channel.ts | 10 +++------- 3 files changed, 7 insertions(+), 10 deletions(-) (limited to 'server/controllers') 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' import { OAuthTokenModel } from '../../../models/oauth/oauth-token' import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' import { meRouter } from './me' +import { deleteUserToken } from '../../../lib/oauth-model' const auditLogger = auditLoggerFactory('users') @@ -267,7 +268,7 @@ async function updateUser (req: express.Request, res: express.Response, next: ex const user = await userToUpdate.save() // Destroy user token to refresh rights - if (roleChanged) await OAuthTokenModel.deleteUserToken(userToUpdate.id) + if (roleChanged) await deleteUserToken(userToUpdate.id) auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) @@ -330,7 +331,7 @@ async function changeUserBlock (res: express.Response, user: UserModel, block: b user.blockedReason = reason || null await sequelizeTypescript.transaction(async t => { - await OAuthTokenModel.deleteUserToken(user.id, t) + await deleteUserToken(user.id, t) await user.save({ transaction: t }) }) 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 const userAccount = await AccountModel.load(user.Account.id) - const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount.Actor, userAccount) + const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount) auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView) 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', // Check the rights asyncMiddleware(videoChannelsUpdateValidator), updateAvatarValidator, - asyncMiddleware(updateVideoChannelAvatar) + asyncRetryTransactionMiddleware(updateVideoChannelAvatar) ) videoChannelRouter.put('/:nameWithHost', @@ -107,13 +107,9 @@ async function updateVideoChannelAvatar (req: express.Request, res: express.Resp const videoChannel = res.locals.videoChannel as VideoChannelModel const oldVideoChannelAuditKeys = new VideoChannelAuditView(videoChannel.toFormattedJSON()) - const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel.Actor, videoChannel) + const avatar = await updateActorAvatarFile(avatarPhysicalFile, videoChannel) - auditLogger.update( - getAuditIdFromRes(res), - new VideoChannelAuditView(videoChannel.toFormattedJSON()), - oldVideoChannelAuditKeys - ) + auditLogger.update(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannel.toFormattedJSON()), oldVideoChannelAuditKeys) return res .json({ -- cgit v1.2.3