]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/avatar.ts
Fix playlist more button with long video names
[github/Chocobozzz/PeerTube.git] / server / lib / avatar.ts
CommitLineData
4bbfc6c6 1import 'multer'
4bbfc6c6 2import { sendUpdateActor } from './activitypub/send'
74dc3bca 3import { AVATARS_SIZE } from '../initializers/constants'
4bbfc6c6
C
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'
ecf3f060 10import * as uuidv4 from 'uuid/v4'
6dd9de95 11import { CONFIG } from '../initializers/config'
74dc3bca 12import { sequelizeTypescript } from '../initializers/database'
4bbfc6c6 13
f201a749 14async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) {
4bbfc6c6 15 const extension = extname(avatarPhysicalFile.filename)
ecf3f060 16 const avatarName = uuidv4() + extension
4bbfc6c6 17 const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName)
2fb5b3a5 18 await processImage(avatarPhysicalFile.path, destination, AVATARS_SIZE)
4bbfc6c6 19
4a534352
C
20 return retryTransactionWrapper(() => {
21 return sequelizeTypescript.transaction(async t => {
22 const updatedActor = await updateActorAvatarInstance(accountOrChannel.Actor, avatarName, t)
23 await updatedActor.save({ transaction: t })
4bbfc6c6 24
4a534352 25 await sendUpdateActor(accountOrChannel, t)
4bbfc6c6 26
4a534352
C
27 return updatedActor.Avatar
28 })
4bbfc6c6
C
29 })
30}
31
32export {
33 updateActorAvatarFile
34}