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'
8 import { getActivityPubUrl, shareVideoChannelByServer } from '../helpers/activitypub'
10 async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountInstance, t: Sequelize.Transaction) {
11 const videoChannelData = {
12 name: videoChannelInfo.name,
13 description: videoChannelInfo.description,
18 const videoChannel = db.VideoChannel.build(videoChannelData)
19 videoChannel.set('url', getActivityPubUrl('videoChannel', videoChannel.uuid))
21 const options = { transaction: t }
23 const videoChannelCreated = await videoChannel.save(options)
25 // Do not forget to add Account information to the created video channel
26 videoChannelCreated.Account = account
28 await sendCreateVideoChannel(videoChannelCreated, t)
29 await shareVideoChannelByServer(videoChannelCreated, t)
31 return videoChannelCreated
34 async function fetchVideoChannelByHostAndUUID (serverHost: string, uuid: string, t: Sequelize.Transaction) {
36 const videoChannel = await db.VideoChannel.loadByHostAndUUID(serverHost, uuid, t)
37 if (!videoChannel) throw new Error('Video channel not found')
41 logger.error('Cannot load video channel from host and uuid.', { error: err.stack, serverHost, uuid })
46 // ---------------------------------------------------------------------------
50 fetchVideoChannelByHostAndUUID