1 import * as Sequelize from 'sequelize'
3 import { addVideoChannelToFriends } from './friends'
4 import { database as db } from '../initializers'
5 import { logger } from '../helpers'
6 import { AccountInstance } from '../models'
7 import { VideoChannelCreate } from '../../shared/models'
9 async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountInstance, t: Sequelize.Transaction) {
10 const videoChannelData = {
11 name: videoChannelInfo.name,
12 description: videoChannelInfo.description,
17 const videoChannel = db.VideoChannel.build(videoChannelData)
18 const options = { transaction: t }
20 const videoChannelCreated = await videoChannel.save(options)
22 // Do not forget to add Account information to the created video channel
23 videoChannelCreated.Account = account
25 const remoteVideoChannel = videoChannelCreated.toAddRemoteJSON()
27 // Now we'll add the video channel's meta data to our friends
28 await addVideoChannelToFriends(remoteVideoChannel, t)
30 return videoChannelCreated
33 async function fetchVideoChannelByHostAndUUID (podHost: string, uuid: string, t: Sequelize.Transaction) {
35 const videoChannel = await db.VideoChannel.loadByHostAndUUID(podHost, uuid, t)
36 if (!videoChannel) throw new Error('Video channel not found')
40 logger.error('Cannot load video channel from host and uuid.', { error: err.stack, podHost, uuid })
45 // ---------------------------------------------------------------------------
49 fetchVideoChannelByHostAndUUID