97924aa9e7350bc01ece116d013c3d6ba5d961e6
[oweals/peertube.git] / server / lib / video-channel.ts
1 import * as Sequelize from 'sequelize'
2 import { VideoChannelCreate } from '../../shared/models'
3 import { AccountModel } from '../models/account/account'
4 import { VideoChannelModel } from '../models/video/video-channel'
5 import { getVideoChannelActivityPubUrl } from './activitypub'
6
7 async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountModel, t: Sequelize.Transaction) {
8   const videoChannelData = {
9     name: videoChannelInfo.name,
10     description: videoChannelInfo.description,
11     remote: false,
12     accountId: account.id
13   }
14
15   const videoChannel = VideoChannelModel.build(videoChannelData)
16   videoChannel.set('url', getVideoChannelActivityPubUrl(videoChannel))
17
18   const options = { transaction: t }
19
20   const videoChannelCreated = await videoChannel.save(options)
21
22   // Do not forget to add Account information to the created video channel
23   videoChannelCreated.Account = account
24
25   // No need to seed this empty video channel to followers
26   return videoChannelCreated
27 }
28
29 // ---------------------------------------------------------------------------
30
31 export {
32   createVideoChannel
33 }