]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/avatar.ts
remove confirm modal for asset injection in edit-custom-config (#1219)
[github/Chocobozzz/PeerTube.git] / server / lib / avatar.ts
CommitLineData
4bbfc6c6 1import 'multer'
4bbfc6c6
C
2import { sendUpdateActor } from './activitypub/send'
3import { AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../initializers'
4import { updateActorAvatarInstance } from './activitypub'
5import { processImage } from '../helpers/image-utils'
4bbfc6c6
C
6import { AccountModel } from '../models/account/account'
7import { VideoChannelModel } from '../models/video/video-channel'
8import { extname, join } from 'path'
4a534352 9import { retryTransactionWrapper } from '../helpers/database-utils'
4bbfc6c6 10
f201a749 11async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) {
4bbfc6c6 12 const extension = extname(avatarPhysicalFile.filename)
f201a749 13 const avatarName = accountOrChannel.Actor.uuid + extension
4bbfc6c6
C
14 const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
15 await processImage(avatarPhysicalFile, destination, AVATARS_SIZE)
16
4a534352
C
17 return retryTransactionWrapper(() => {
18 return sequelizeTypescript.transaction(async t => {
19 const updatedActor = await updateActorAvatarInstance(accountOrChannel.Actor, avatarName, t)
20 await updatedActor.save({ transaction: t })
4bbfc6c6 21
4a534352 22 await sendUpdateActor(accountOrChannel, t)
4bbfc6c6 23
4a534352
C
24 return updatedActor.Avatar
25 })
4bbfc6c6
C
26 })
27}
28
29export {
30 updateActorAvatarFile
31}