]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/avatar.ts
Only duplicate public videos
[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'
9
f201a749 10async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) {
4bbfc6c6 11 const extension = extname(avatarPhysicalFile.filename)
f201a749 12 const avatarName = accountOrChannel.Actor.uuid + extension
4bbfc6c6
C
13 const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
14 await processImage(avatarPhysicalFile, destination, AVATARS_SIZE)
15
16 return sequelizeTypescript.transaction(async t => {
f201a749 17 const updatedActor = await updateActorAvatarInstance(accountOrChannel.Actor, avatarName, t)
4bbfc6c6
C
18 await updatedActor.save({ transaction: t })
19
20 await sendUpdateActor(accountOrChannel, t)
21
22 return updatedActor.Avatar
23 })
24}
25
26export {
27 updateActorAvatarFile
28}