]>
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' |
4bbfc6c6 | 10 | |
f201a749 | 11 | async 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 | ||
29 | export { | |
30 | updateActorAvatarFile | |
31 | } |