]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/video-channel.ts
Rename request timeout
[github/Chocobozzz/PeerTube.git] / server / lib / video-channel.ts
CommitLineData
72c7248b 1import * as Sequelize from 'sequelize'
bdd428a6 2import { v4 as uuidv4 } from 'uuid'
79d5caf9 3import { VideoChannelCreate } from '../../shared/models'
7d14d4d2 4import { VideoModel } from '../models/video/video'
de94ac86 5import { VideoChannelModel } from '../models/video/video-channel'
26d6bf65 6import { MAccountId, MChannelDefault, MChannelId } from '../types/models'
de94ac86
C
7import { buildActorInstance } from './activitypub/actor'
8import { getLocalVideoChannelActivityPubUrl } from './activitypub/url'
7fed6375 9import { federateVideoIfNeeded } from './activitypub/videos'
72c7248b 10
a1587156 11type CustomVideoChannelModelAccount <T extends MAccountId> = MChannelDefault & { Account?: T }
453e83ea 12
1ca9f7c3 13async function createLocalVideoChannel <T extends MAccountId> (
453e83ea
C
14 videoChannelInfo: VideoChannelCreate,
15 account: T,
16 t: Sequelize.Transaction
17): Promise<CustomVideoChannelModelAccount<T>> {
50d6de9c 18 const uuid = uuidv4()
de94ac86 19 const url = getLocalVideoChannelActivityPubUrl(videoChannelInfo.name)
8a19bee1 20 const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name, uuid)
50d6de9c
C
21
22 const actorInstanceCreated = await actorInstance.save({ transaction: t })
23
72c7248b 24 const videoChannelData = {
08c1efbe 25 name: videoChannelInfo.displayName,
72c7248b 26 description: videoChannelInfo.description,
2422c46b 27 support: videoChannelInfo.support,
50d6de9c
C
28 accountId: account.id,
29 actorId: actorInstanceCreated.id
72c7248b
C
30 }
31
453e83ea 32 const videoChannel = new VideoChannelModel(videoChannelData)
e34c85e5 33
72c7248b 34 const options = { transaction: t }
1ca9f7c3 35 const videoChannelCreated: CustomVideoChannelModelAccount<T> = await videoChannel.save(options) as MChannelDefault
eb080476 36
50d6de9c 37 // Do not forget to add Account/Actor information to the created video channel
e4f97bab 38 videoChannelCreated.Account = account
50d6de9c 39 videoChannelCreated.Actor = actorInstanceCreated
eb080476 40
47e0652b 41 // No need to seed this empty video channel to followers
eb080476
C
42 return videoChannelCreated
43}
44
453e83ea 45async function federateAllVideosOfChannel (videoChannel: MChannelId) {
7d14d4d2
C
46 const videoIds = await VideoModel.getAllIdsFromChannel(videoChannel)
47
48 for (const videoId of videoIds) {
49 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
50
51 await federateVideoIfNeeded(video, false)
52 }
53}
54
72c7248b
C
55// ---------------------------------------------------------------------------
56
57export {
1ca9f7c3 58 createLocalVideoChannel,
7d14d4d2 59 federateAllVideosOfChannel
72c7248b 60}