]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/video-channel.ts
Add video channel management
[github/Chocobozzz/PeerTube.git] / server / lib / video-channel.ts
CommitLineData
72c7248b 1import * as Sequelize from 'sequelize'
50d6de9c 2import * as uuidv4 from 'uuid/v4'
79d5caf9 3import { VideoChannelCreate } from '../../shared/models'
3fd3ab2d
C
4import { AccountModel } from '../models/account/account'
5import { VideoChannelModel } from '../models/video/video-channel'
50d6de9c 6import { buildActorInstance, getVideoChannelActivityPubUrl } from './activitypub'
72c7248b 7
3fd3ab2d 8async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountModel, t: Sequelize.Transaction) {
50d6de9c
C
9 const uuid = uuidv4()
10 const url = getVideoChannelActivityPubUrl(uuid)
11 // We use the name as uuid
12 const actorInstance = buildActorInstance('Group', url, uuid, uuid)
13
14 const actorInstanceCreated = await actorInstance.save({ transaction: t })
15
72c7248b 16 const videoChannelData = {
08c1efbe 17 name: videoChannelInfo.displayName,
72c7248b 18 description: videoChannelInfo.description,
2422c46b 19 support: videoChannelInfo.support,
50d6de9c
C
20 accountId: account.id,
21 actorId: actorInstanceCreated.id
72c7248b
C
22 }
23
3fd3ab2d 24 const videoChannel = VideoChannelModel.build(videoChannelData)
e34c85e5 25
72c7248b 26 const options = { transaction: t }
eb080476
C
27 const videoChannelCreated = await videoChannel.save(options)
28
50d6de9c 29 // Do not forget to add Account/Actor information to the created video channel
e4f97bab 30 videoChannelCreated.Account = account
50d6de9c 31 videoChannelCreated.Actor = actorInstanceCreated
eb080476 32
47e0652b 33 // No need to seed this empty video channel to followers
eb080476
C
34 return videoChannelCreated
35}
36
72c7248b
C
37// ---------------------------------------------------------------------------
38
39export {
39445ead 40 createVideoChannel
72c7248b 41}