video-channel.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import * as Sequelize from 'sequelize'
  2. import { VideoChannelCreate } from '@peertube/peertube-models'
  3. import { VideoChannelModel } from '../models/video/video-channel.js'
  4. import { VideoModel } from '../models/video/video.js'
  5. import { MAccountId, MChannelId } from '../types/models/index.js'
  6. import { getLocalVideoChannelActivityPubUrl } from './activitypub/url.js'
  7. import { federateVideoIfNeeded } from './activitypub/videos/index.js'
  8. import { buildActorInstance } from './local-actor.js'
  9. async function createLocalVideoChannel (videoChannelInfo: VideoChannelCreate, account: MAccountId, t: Sequelize.Transaction) {
  10. const url = getLocalVideoChannelActivityPubUrl(videoChannelInfo.name)
  11. const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name)
  12. const actorInstanceCreated = await actorInstance.save({ transaction: t })
  13. const videoChannelData = {
  14. name: videoChannelInfo.displayName,
  15. description: videoChannelInfo.description,
  16. support: videoChannelInfo.support,
  17. accountId: account.id,
  18. actorId: actorInstanceCreated.id
  19. }
  20. const videoChannel = new VideoChannelModel(videoChannelData)
  21. const options = { transaction: t }
  22. const videoChannelCreated = await videoChannel.save(options)
  23. videoChannelCreated.Actor = actorInstanceCreated
  24. // No need to send this empty video channel to followers
  25. return videoChannelCreated
  26. }
  27. async function federateAllVideosOfChannel (videoChannel: MChannelId) {
  28. const videoIds = await VideoModel.getAllIdsFromChannel(videoChannel)
  29. for (const videoId of videoIds) {
  30. const video = await VideoModel.loadFull(videoId)
  31. await federateVideoIfNeeded(video, false)
  32. }
  33. }
  34. // ---------------------------------------------------------------------------
  35. export {
  36. createLocalVideoChannel,
  37. federateAllVideosOfChannel
  38. }