]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/video-channel.ts
Begin activitypub
[github/Chocobozzz/PeerTube.git] / server / lib / video-channel.ts
CommitLineData
72c7248b
C
1import * as Sequelize from 'sequelize'
2
3import { addVideoChannelToFriends } from './friends'
4import { database as db } from '../initializers'
eb080476 5import { logger } from '../helpers'
e4f97bab 6import { AccountInstance } from '../models'
72c7248b
C
7import { VideoChannelCreate } from '../../shared/models'
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,
e4f97bab 14 authorId: 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
C
24
25 const remoteVideoChannel = videoChannelCreated.toAddRemoteJSON()
26
27 // Now we'll add the video channel's meta data to our friends
28 await addVideoChannelToFriends(remoteVideoChannel, t)
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}