]>
Commit | Line | Data |
---|---|---|
4bbfc6c6 | 1 | import 'multer' |
4bbfc6c6 C |
2 | import { sendUpdateActor } from './activitypub/send' |
3 | import { AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../initializers' | |
4 | import { updateActorAvatarInstance } from './activitypub' | |
5 | import { processImage } from '../helpers/image-utils' | |
4bbfc6c6 C |
6 | import { AccountModel } from '../models/account/account' |
7 | import { VideoChannelModel } from '../models/video/video-channel' | |
8 | import { extname, join } from 'path' | |
4a534352 | 9 | import { retryTransactionWrapper } from '../helpers/database-utils' |
ecf3f060 | 10 | import * as uuidv4 from 'uuid/v4' |
4bbfc6c6 | 11 | |
f201a749 | 12 | async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) { |
4bbfc6c6 | 13 | const extension = extname(avatarPhysicalFile.filename) |
ecf3f060 | 14 | const avatarName = uuidv4() + extension |
4bbfc6c6 C |
15 | const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName) |
16 | await processImage(avatarPhysicalFile, destination, AVATARS_SIZE) | |
17 | ||
4a534352 C |
18 | return retryTransactionWrapper(() => { |
19 | return sequelizeTypescript.transaction(async t => { | |
20 | const updatedActor = await updateActorAvatarInstance(accountOrChannel.Actor, avatarName, t) | |
21 | await updatedActor.save({ transaction: t }) | |
4bbfc6c6 | 22 | |
4a534352 | 23 | await sendUpdateActor(accountOrChannel, t) |
4bbfc6c6 | 24 | |
4a534352 C |
25 | return updatedActor.Avatar |
26 | }) | |
4bbfc6c6 C |
27 | }) |
28 | } | |
29 | ||
30 | export { | |
31 | updateActorAvatarFile | |
32 | } |