]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/video-channel.ts
Make it compile at least
[github/Chocobozzz/PeerTube.git] / server / lib / video-channel.ts
CommitLineData
72c7248b
C
1import * as Sequelize from 'sequelize'
2
72c7248b 3import { database as db } from '../initializers'
eb080476 4import { logger } from '../helpers'
e4f97bab 5import { AccountInstance } from '../models'
72c7248b 6import { VideoChannelCreate } from '../../shared/models'
571389d4 7import { sendCreateVideoChannel } from './activitypub/send-request'
72c7248b 8
e4f97bab 9async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountInstance, t: Sequelize.Transaction) {
72c7248b
C
10 const videoChannelData = {
11 name: videoChannelInfo.name,
12 description: videoChannelInfo.description,
13 remote: false,
38fa2065 14 accountId: account.id
72c7248b
C
15 }
16
17 const videoChannel = db.VideoChannel.build(videoChannelData)
18 const options = { transaction: t }
19
eb080476
C
20 const videoChannelCreated = await videoChannel.save(options)
21
e4f97bab
C
22 // Do not forget to add Account information to the created video channel
23 videoChannelCreated.Account = account
eb080476 24
571389d4 25 sendCreateVideoChannel(videoChannelCreated, t)
eb080476
C
26
27 return videoChannelCreated
28}
29
30async function fetchVideoChannelByHostAndUUID (podHost: string, uuid: string, t: Sequelize.Transaction) {
31 try {
32 const videoChannel = await db.VideoChannel.loadByHostAndUUID(podHost, uuid, t)
33 if (!videoChannel) throw new Error('Video channel not found')
34
35 return videoChannel
36 } catch (err) {
37 logger.error('Cannot load video channel from host and uuid.', { error: err.stack, podHost, uuid })
38 throw err
39 }
72c7248b
C
40}
41
42// ---------------------------------------------------------------------------
43
44export {
eb080476
C
45 createVideoChannel,
46 fetchVideoChannelByHostAndUUID
72c7248b 47}