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