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

51 lines
1.7 KiB
TypeScript
Raw Normal View History

2017-10-24 17:41:09 +00:00
import * as Sequelize from 'sequelize'
2017-11-17 14:52:26 +00:00
import { VideoChannelCreate } from '../../shared/models'
import { VideoModel } from '../models/video/video'
2020-11-20 10:21:08 +00:00
import { VideoChannelModel } from '../models/video/video-channel'
2021-04-06 15:01:35 +00:00
import { MAccountId, MChannelId } from '../types/models'
2020-11-20 10:21:08 +00:00
import { getLocalVideoChannelActivityPubUrl } from './activitypub/url'
2020-04-22 14:07:04 +00:00
import { federateVideoIfNeeded } from './activitypub/videos'
2021-06-03 14:02:29 +00:00
import { buildActorInstance } from './local-actor'
2017-10-24 17:41:09 +00:00
2021-04-06 15:01:35 +00:00
async function createLocalVideoChannel (videoChannelInfo: VideoChannelCreate, account: MAccountId, t: Sequelize.Transaction) {
2020-11-20 10:21:08 +00:00
const url = getLocalVideoChannelActivityPubUrl(videoChannelInfo.name)
2021-05-12 12:09:04 +00:00
const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name)
2017-12-14 16:38:41 +00:00
const actorInstanceCreated = await actorInstance.save({ transaction: t })
2017-10-24 17:41:09 +00:00
const videoChannelData = {
2018-04-26 14:11:38 +00:00
name: videoChannelInfo.displayName,
2017-10-24 17:41:09 +00:00
description: videoChannelInfo.description,
support: videoChannelInfo.support,
2017-12-14 16:38:41 +00:00
accountId: account.id,
actorId: actorInstanceCreated.id
2017-10-24 17:41:09 +00:00
}
2019-08-15 09:53:26 +00:00
const videoChannel = new VideoChannelModel(videoChannelData)
2017-11-14 09:57:56 +00:00
2017-10-24 17:41:09 +00:00
const options = { transaction: t }
2021-04-06 15:01:35 +00:00
const videoChannelCreated = await videoChannel.save(options)
2017-10-25 09:55:06 +00:00
2017-12-14 16:38:41 +00:00
videoChannelCreated.Actor = actorInstanceCreated
2017-10-25 09:55:06 +00:00
2021-04-06 15:01:35 +00:00
// No need to send this empty video channel to followers
2017-10-25 09:55:06 +00:00
return videoChannelCreated
}
2019-08-15 09:53:26 +00:00
async function federateAllVideosOfChannel (videoChannel: MChannelId) {
const videoIds = await VideoModel.getAllIdsFromChannel(videoChannel)
for (const videoId of videoIds) {
2022-06-28 12:57:51 +00:00
const video = await VideoModel.loadFull(videoId)
await federateVideoIfNeeded(video, false)
}
}
2017-10-24 17:41:09 +00:00
// ---------------------------------------------------------------------------
export {
2019-08-20 17:05:31 +00:00
createLocalVideoChannel,
federateAllVideosOfChannel
2017-10-24 17:41:09 +00:00
}