X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Favatar.ts;h=4b6bc318579ffeb4cd29ad01c9b1c83591b3779f;hb=4a534352ad046ca804f1f58ef5afb6e366e202b8;hp=7fdef008c45502dabec9bb298166ccd823b21ae7;hpb=4bbfc6c606c8d3794bae25c64c516120af41f4eb;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/avatar.ts b/server/lib/avatar.ts index 7fdef008c..4b6bc3185 100644 --- a/server/lib/avatar.ts +++ b/server/lib/avatar.ts @@ -1,31 +1,28 @@ import 'multer' -import * as uuidv4 from 'uuid' import { sendUpdateActor } from './activitypub/send' import { AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../initializers' import { updateActorAvatarInstance } from './activitypub' import { processImage } from '../helpers/image-utils' -import { ActorModel } from '../models/activitypub/actor' import { AccountModel } from '../models/account/account' import { VideoChannelModel } from '../models/video/video-channel' import { extname, join } from 'path' +import { retryTransactionWrapper } from '../helpers/database-utils' -async function updateActorAvatarFile ( - avatarPhysicalFile: Express.Multer.File, - actor: ActorModel, - accountOrChannel: AccountModel | VideoChannelModel -) { +async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) { const extension = extname(avatarPhysicalFile.filename) - const avatarName = uuidv4() + extension + const avatarName = accountOrChannel.Actor.uuid + extension const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName) await processImage(avatarPhysicalFile, destination, AVATARS_SIZE) - return sequelizeTypescript.transaction(async t => { - const updatedActor = await updateActorAvatarInstance(actor, avatarName, t) - await updatedActor.save({ transaction: t }) + return retryTransactionWrapper(() => { + return sequelizeTypescript.transaction(async t => { + const updatedActor = await updateActorAvatarInstance(accountOrChannel.Actor, avatarName, t) + await updatedActor.save({ transaction: t }) - await sendUpdateActor(accountOrChannel, t) + await sendUpdateActor(accountOrChannel, t) - return updatedActor.Avatar + return updatedActor.Avatar + }) }) }