]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/video-channel.ts
Merge remote-tracking branch 'weblate/develop' into develop
[github/Chocobozzz/PeerTube.git] / server / lib / video-channel.ts
1 import * as Sequelize from 'sequelize'
2 import { VideoChannelCreate } from '../../shared/models'
3 import { VideoModel } from '../models/video/video'
4 import { VideoChannelModel } from '../models/video/video-channel'
5 import { MAccountId, MChannelId } from '../types/models'
6 import { getLocalVideoChannelActivityPubUrl } from './activitypub/url'
7 import { federateVideoIfNeeded } from './activitypub/videos'
8 import { buildActorInstance } from './local-actor'
9
10 async function createLocalVideoChannel (videoChannelInfo: VideoChannelCreate, account: MAccountId, t: Sequelize.Transaction) {
11 const url = getLocalVideoChannelActivityPubUrl(videoChannelInfo.name)
12 const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name)
13
14 const actorInstanceCreated = await actorInstance.save({ transaction: t })
15
16 const videoChannelData = {
17 name: videoChannelInfo.displayName,
18 description: videoChannelInfo.description,
19 support: videoChannelInfo.support,
20 accountId: account.id,
21 actorId: actorInstanceCreated.id
22 }
23
24 const videoChannel = new VideoChannelModel(videoChannelData)
25
26 const options = { transaction: t }
27 const videoChannelCreated = await videoChannel.save(options)
28
29 videoChannelCreated.Actor = actorInstanceCreated
30
31 // No need to send this empty video channel to followers
32 return videoChannelCreated
33 }
34
35 async function federateAllVideosOfChannel (videoChannel: MChannelId) {
36 const videoIds = await VideoModel.getAllIdsFromChannel(videoChannel)
37
38 for (const videoId of videoIds) {
39 const video = await VideoModel.loadFull(videoId)
40
41 await federateVideoIfNeeded(video, false)
42 }
43 }
44
45 // ---------------------------------------------------------------------------
46
47 export {
48 createLocalVideoChannel,
49 federateAllVideosOfChannel
50 }