1 import * as Sequelize from 'sequelize'
3 import { database as db } from '../initializers'
4 import { logger } from '../helpers'
5 import { AccountInstance } from '../models'
6 import { VideoChannelCreate } from '../../shared/models'
7 import { sendCreateVideoChannel } from './activitypub/send-request'
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 sendCreateVideoChannel(videoChannelCreated, t)
27 return videoChannelCreated
30 async function fetchVideoChannelByHostAndUUID (podHost: string, uuid: string, t: Sequelize.Transaction) {
32 const videoChannel = await db.VideoChannel.loadByHostAndUUID(podHost, uuid, t)
33 if (!videoChannel) throw new Error('Video channel not found')
37 logger.error('Cannot load video channel from host and uuid.', { error: err.stack, podHost, uuid })
42 // ---------------------------------------------------------------------------
46 fetchVideoChannelByHostAndUUID