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