1 import * as Sequelize from 'sequelize'
2 import { VideoChannelCreate } from '../../shared/models'
3 import { logger } from '../helpers'
4 import { database as db } from '../initializers'
5 import { AccountInstance } from '../models'
6 import { getVideoChannelActivityPubUrl } from '../helpers/activitypub'
8 async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountInstance, t: Sequelize.Transaction) {
9 const videoChannelData = {
10 name: videoChannelInfo.name,
11 description: videoChannelInfo.description,
16 const videoChannel = db.VideoChannel.build(videoChannelData)
17 videoChannel.set('url', getVideoChannelActivityPubUrl(videoChannel))
19 const options = { transaction: t }
21 const videoChannelCreated = await videoChannel.save(options)
23 // Do not forget to add Account information to the created video channel
24 videoChannelCreated.Account = account
26 // No need to seed this empty video channel to followers
27 return videoChannelCreated
30 async function fetchVideoChannelByHostAndUUID (serverHost: string, uuid: string, t: Sequelize.Transaction) {
32 const videoChannel = await db.VideoChannel.loadByHostAndUUID(serverHost, 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, serverHost, uuid })
42 // ---------------------------------------------------------------------------
46 fetchVideoChannelByHostAndUUID