]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/video-channel.ts
Begin moving video channel to actor
[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
C
16 const videoChannelData = {
17 name: videoChannelInfo.name,
18 description: videoChannelInfo.description,
50d6de9c
C
19 accountId: account.id,
20 actorId: actorInstanceCreated.id
72c7248b
C
21 }
22
3fd3ab2d 23 const videoChannel = VideoChannelModel.build(videoChannelData)
e34c85e5 24
72c7248b 25 const options = { transaction: t }
eb080476
C
26 const videoChannelCreated = await videoChannel.save(options)
27
50d6de9c 28 // Do not forget to add Account/Actor information to the created video channel
e4f97bab 29 videoChannelCreated.Account = account
50d6de9c 30 videoChannelCreated.Actor = actorInstanceCreated
eb080476 31
47e0652b 32 // No need to seed this empty video channel to followers
eb080476
C
33 return videoChannelCreated
34}
35
72c7248b
C
36// ---------------------------------------------------------------------------
37
38export {
39445ead 39 createVideoChannel
72c7248b 40}