1
0
Fork 0
peertube/server/lib/video-channel.ts

53 lines
1.9 KiB
TypeScript
Raw Normal View History

2017-10-24 13:41:09 -04:00
import * as Sequelize from 'sequelize'
2017-12-14 11:38:41 -05:00
import * as uuidv4 from 'uuid/v4'
2017-11-17 09:52:26 -05:00
import { VideoChannelCreate } from '../../shared/models'
2017-12-12 11:53:50 -05:00
import { AccountModel } from '../models/account/account'
import { VideoChannelModel } from '../models/video/video-channel'
import { buildActorInstance, federateVideoIfNeeded, getVideoChannelActivityPubUrl } from './activitypub'
import { VideoModel } from '../models/video/video'
2017-10-24 13:41:09 -04:00
2017-12-12 11:53:50 -05:00
async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountModel, t: Sequelize.Transaction) {
2017-12-14 11:38:41 -05:00
const uuid = uuidv4()
2018-08-17 09:45:42 -04:00
const url = getVideoChannelActivityPubUrl(videoChannelInfo.name)
const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name, uuid)
2017-12-14 11:38:41 -05:00
const actorInstanceCreated = await actorInstance.save({ transaction: t })
2017-10-24 13:41:09 -04:00
const videoChannelData = {
2018-04-26 10:11:38 -04:00
name: videoChannelInfo.displayName,
2017-10-24 13:41:09 -04:00
description: videoChannelInfo.description,
support: videoChannelInfo.support,
2017-12-14 11:38:41 -05:00
accountId: account.id,
actorId: actorInstanceCreated.id
2017-10-24 13:41:09 -04:00
}
2017-12-12 11:53:50 -05:00
const videoChannel = VideoChannelModel.build(videoChannelData)
2017-11-14 04:57:56 -05:00
2017-10-24 13:41:09 -04:00
const options = { transaction: t }
2017-10-25 05:55:06 -04:00
const videoChannelCreated = await videoChannel.save(options)
2017-12-14 11:38:41 -05:00
// Do not forget to add Account/Actor information to the created video channel
2017-11-09 11:51:58 -05:00
videoChannelCreated.Account = account
2017-12-14 11:38:41 -05:00
videoChannelCreated.Actor = actorInstanceCreated
2017-10-25 05:55:06 -04:00
2017-11-16 12:40:50 -05:00
// No need to seed this empty video channel to followers
2017-10-25 05:55:06 -04:00
return videoChannelCreated
}
async function federateAllVideosOfChannel (videoChannel: VideoChannelModel) {
const videoIds = await VideoModel.getAllIdsFromChannel(videoChannel)
for (const videoId of videoIds) {
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
await federateVideoIfNeeded(video, false)
}
}
2017-10-24 13:41:09 -04:00
// ---------------------------------------------------------------------------
export {
createVideoChannel,
federateAllVideosOfChannel
2017-10-24 13:41:09 -04:00
}