aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-29 11:29:23 +0200
committerChocobozzz <me@florianbigard.com>2018-06-29 11:29:23 +0200
commit4bbfc6c606c8d3794bae25c64c516120af41f4eb (patch)
tree8d6012f3c04e55e7325e3f00eb9061776cc7a953 /server/lib
parent3ff5a19b4c988d6c712b7ce63c4cf04f99d047ce (diff)
downloadPeerTube-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.ts34
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 @@
1import 'multer'
2import * as uuidv4 from 'uuid'
3import { sendUpdateActor } from './activitypub/send'
4import { AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../initializers'
5import { updateActorAvatarInstance } from './activitypub'
6import { processImage } from '../helpers/image-utils'
7import { ActorModel } from '../models/activitypub/actor'
8import { AccountModel } from '../models/account/account'
9import { VideoChannelModel } from '../models/video/video-channel'
10import { extname, join } from 'path'
11
12async 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
32export {
33 updateActorAvatarFile
34}