Fix avatar transaction retry

pull/1104/merge
Chocobozzz 2018-09-26 10:15:50 +02:00
parent 39ba2e8e3a
commit 4a534352ad
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
2 changed files with 9 additions and 6 deletions

View File

@ -56,7 +56,7 @@ videoChannelRouter.post('/:nameWithHost/avatar/pick',
// Check the rights // Check the rights
asyncMiddleware(videoChannelsUpdateValidator), asyncMiddleware(videoChannelsUpdateValidator),
updateAvatarValidator, updateAvatarValidator,
asyncRetryTransactionMiddleware(updateVideoChannelAvatar) asyncMiddleware(updateVideoChannelAvatar)
) )
videoChannelRouter.put('/:nameWithHost', videoChannelRouter.put('/:nameWithHost',

View File

@ -6,6 +6,7 @@ import { processImage } from '../helpers/image-utils'
import { AccountModel } from '../models/account/account' import { AccountModel } from '../models/account/account'
import { VideoChannelModel } from '../models/video/video-channel' import { VideoChannelModel } from '../models/video/video-channel'
import { extname, join } from 'path' import { extname, join } from 'path'
import { retryTransactionWrapper } from '../helpers/database-utils'
async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) { async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) {
const extension = extname(avatarPhysicalFile.filename) const extension = extname(avatarPhysicalFile.filename)
@ -13,6 +14,7 @@ async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, a
const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName) const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
await processImage(avatarPhysicalFile, destination, AVATARS_SIZE) await processImage(avatarPhysicalFile, destination, AVATARS_SIZE)
return retryTransactionWrapper(() => {
return sequelizeTypescript.transaction(async t => { return sequelizeTypescript.transaction(async t => {
const updatedActor = await updateActorAvatarInstance(accountOrChannel.Actor, avatarName, t) const updatedActor = await updateActorAvatarInstance(accountOrChannel.Actor, avatarName, t)
await updatedActor.save({ transaction: t }) await updatedActor.save({ transaction: t })
@ -21,6 +23,7 @@ async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, a
return updatedActor.Avatar return updatedActor.Avatar
}) })
})
} }
export { export {