diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-29 11:29:23 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-29 11:29:23 +0200 |
commit | 4bbfc6c606c8d3794bae25c64c516120af41f4eb (patch) | |
tree | 8d6012f3c04e55e7325e3f00eb9061776cc7a953 /server/lib | |
parent | 3ff5a19b4c988d6c712b7ce63c4cf04f99d047ce (diff) | |
download | PeerTube-4bbfc6c606c8d3794bae25c64c516120af41f4eb.tar.gz PeerTube-4bbfc6c606c8d3794bae25c64c516120af41f4eb.tar.zst PeerTube-4bbfc6c606c8d3794bae25c64c516120af41f4eb.zip |
API: Add ability to update video channel avatar
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/avatar.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/server/lib/avatar.ts b/server/lib/avatar.ts new file mode 100644 index 000000000..7fdef008c --- /dev/null +++ b/server/lib/avatar.ts | |||
@@ -0,0 +1,34 @@ | |||
1 | import 'multer' | ||
2 | import * as uuidv4 from 'uuid' | ||
3 | import { sendUpdateActor } from './activitypub/send' | ||
4 | import { AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../initializers' | ||
5 | import { updateActorAvatarInstance } from './activitypub' | ||
6 | import { processImage } from '../helpers/image-utils' | ||
7 | import { ActorModel } from '../models/activitypub/actor' | ||
8 | import { AccountModel } from '../models/account/account' | ||
9 | import { VideoChannelModel } from '../models/video/video-channel' | ||
10 | import { extname, join } from 'path' | ||
11 | |||
12 | async function updateActorAvatarFile ( | ||
13 | avatarPhysicalFile: Express.Multer.File, | ||
14 | actor: ActorModel, | ||
15 | accountOrChannel: AccountModel | VideoChannelModel | ||
16 | ) { | ||
17 | const extension = extname(avatarPhysicalFile.filename) | ||
18 | const avatarName = uuidv4() + extension | ||
19 | const destination = join(CONFIG.STORAGE.AVATARS_DIR, avatarName) | ||
20 | await processImage(avatarPhysicalFile, destination, AVATARS_SIZE) | ||
21 | |||
22 | return sequelizeTypescript.transaction(async t => { | ||
23 | const updatedActor = await updateActorAvatarInstance(actor, avatarName, t) | ||
24 | await updatedActor.save({ transaction: t }) | ||
25 | |||
26 | await sendUpdateActor(accountOrChannel, t) | ||
27 | |||
28 | return updatedActor.Avatar | ||
29 | }) | ||
30 | } | ||
31 | |||
32 | export { | ||
33 | updateActorAvatarFile | ||
34 | } | ||