- const imageSize = type === ActorImageType.AVATAR
- ? ACTOR_IMAGES_SIZE.AVATARS
- : ACTOR_IMAGES_SIZE.BANNERS
-
- const extension = extname(imagePhysicalFile.filename)
-
- const imageName = uuidv4() + extension
- const destination = join(CONFIG.STORAGE.ACTOR_IMAGES, imageName)
- await processImage(imagePhysicalFile.path, destination, imageSize)
-
- return retryTransactionWrapper(() => {
- return sequelizeTypescript.transaction(async t => {
- const actorImageInfo = {
- name: imageName,
- fileUrl: null,
- height: imageSize.height,
- width: imageSize.width,
- onDisk: true
- }
-
- const updatedActor = await updateActorImageInstance(accountOrChannel.Actor, type, actorImageInfo, t)
- await updatedActor.save({ transaction: t })
-
- await sendUpdateActor(accountOrChannel, t)
-
- return type === ActorImageType.AVATAR
- ? updatedActor.Avatar
- : updatedActor.Banner
- })
- })
+ const processImageSize = async (imageSize: { width: number, height: number }) => {
+ const extension = getLowercaseExtension(imagePhysicalFile.filename)
+
+ const imageName = buildUUID() + extension
+ const destination = join(CONFIG.STORAGE.ACTOR_IMAGES, imageName)
+ await processImageFromWorker({ path: imagePhysicalFile.path, destination, newSize: imageSize, keepOriginal: true })
+
+ return {
+ imageName,
+ imageSize
+ }
+ }
+
+ const processedImages = await Promise.all(ACTOR_IMAGES_SIZE[type].map(processImageSize))
+ await remove(imagePhysicalFile.path)
+
+ return retryTransactionWrapper(() => sequelizeTypescript.transaction(async t => {
+ const actorImagesInfo = processedImages.map(({ imageName, imageSize }) => ({
+ name: imageName,
+ fileUrl: null,
+ height: imageSize.height,
+ width: imageSize.width,
+ onDisk: true
+ }))
+
+ const updatedActor = await updateActorImages(accountOrChannel.Actor, type, actorImagesInfo, t)
+ await updatedActor.save({ transaction: t })
+
+ await sendUpdateActor(accountOrChannel, t)
+
+ return type === ActorImageType.AVATAR
+ ? updatedActor.Avatars
+ : updatedActor.Banners
+ }))