video-channel.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import * as Sequelize from 'sequelize'
  2. import * as uuidv4 from 'uuid/v4'
  3. import { VideoChannelCreate } from '../../shared/models'
  4. import { AccountModel } from '../models/account/account'
  5. import { VideoChannelModel } from '../models/video/video-channel'
  6. import { buildActorInstance, federateVideoIfNeeded, getVideoChannelActivityPubUrl } from './activitypub'
  7. import { VideoModel } from '../models/video/video'
  8. async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account: AccountModel, t: Sequelize.Transaction) {
  9. const uuid = uuidv4()
  10. const url = getVideoChannelActivityPubUrl(videoChannelInfo.name)
  11. const actorInstance = buildActorInstance('Group', url, videoChannelInfo.name, uuid)
  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 = VideoChannelModel.build(videoChannelData)
  21. const options = { transaction: t }
  22. const videoChannelCreated = await videoChannel.save(options)
  23. // Do not forget to add Account/Actor information to the created video channel
  24. videoChannelCreated.Account = account
  25. videoChannelCreated.Actor = actorInstanceCreated
  26. // No need to seed this empty video channel to followers
  27. return videoChannelCreated
  28. }
  29. async function federateAllVideosOfChannel (videoChannel: VideoChannelModel) {
  30. const videoIds = await VideoModel.getAllIdsFromChannel(videoChannel)
  31. for (const videoId of videoIds) {
  32. const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(videoId)
  33. await federateVideoIfNeeded(video, false)
  34. }
  35. }
  36. // ---------------------------------------------------------------------------
  37. export {
  38. createVideoChannel,
  39. federateAllVideosOfChannel
  40. }