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