Federated video streaming platform using ActivityPub and P2P in the web browser with Angular. https://joinpeertube.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

141 lines
4.1 KiB

  1. import { updateTorrentMetadata } from '@server/helpers/webtorrent'
  2. import { getServerActor } from '@server/models/application/application'
  3. import { WEBSERVER } from '../server/initializers/constants'
  4. import { initDatabaseModels } from '../server/initializers/database'
  5. import {
  6. getLocalAccountActivityPubUrl,
  7. getLocalVideoActivityPubUrl,
  8. getLocalVideoAnnounceActivityPubUrl,
  9. getLocalVideoChannelActivityPubUrl,
  10. getLocalVideoCommentActivityPubUrl
  11. } from '../server/lib/activitypub/url'
  12. import { AccountModel } from '../server/models/account/account'
  13. import { ActorModel } from '../server/models/actor/actor'
  14. import { ActorFollowModel } from '../server/models/actor/actor-follow'
  15. import { VideoModel } from '../server/models/video/video'
  16. import { VideoChannelModel } from '../server/models/video/video-channel'
  17. import { VideoCommentModel } from '../server/models/video/video-comment'
  18. import { VideoShareModel } from '../server/models/video/video-share'
  19. run()
  20. .then(() => process.exit(0))
  21. .catch(err => {
  22. console.error(err)
  23. process.exit(-1)
  24. })
  25. async function run () {
  26. await initDatabaseModels(true)
  27. const serverAccount = await getServerActor()
  28. {
  29. const res = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
  30. const hasFollowing = res.total > 0
  31. if (hasFollowing === true) {
  32. throw new Error('Cannot update host because you follow other servers!')
  33. }
  34. }
  35. console.log('Updating actors.')
  36. const actors: ActorModel[] = await ActorModel.unscoped().findAll({
  37. include: [
  38. {
  39. model: VideoChannelModel.unscoped(),
  40. required: false
  41. },
  42. {
  43. model: AccountModel.unscoped(),
  44. required: false
  45. }
  46. ]
  47. })
  48. for (const actor of actors) {
  49. if (actor.isOwned() === false) continue
  50. console.log('Updating actor ' + actor.url)
  51. const newUrl = actor.Account
  52. ? getLocalAccountActivityPubUrl(actor.preferredUsername)
  53. : getLocalVideoChannelActivityPubUrl(actor.preferredUsername)
  54. actor.url = newUrl
  55. actor.inboxUrl = newUrl + '/inbox'
  56. actor.outboxUrl = newUrl + '/outbox'
  57. actor.sharedInboxUrl = WEBSERVER.URL + '/inbox'
  58. actor.followersUrl = newUrl + '/followers'
  59. actor.followingUrl = newUrl + '/following'
  60. await actor.save()
  61. }
  62. console.log('Updating video shares.')
  63. const videoShares: VideoShareModel[] = await VideoShareModel.findAll({
  64. include: [ VideoModel.unscoped(), ActorModel.unscoped() ]
  65. })
  66. for (const videoShare of videoShares) {
  67. if (videoShare.Video.isOwned() === false) continue
  68. console.log('Updating video share ' + videoShare.url)
  69. videoShare.url = getLocalVideoAnnounceActivityPubUrl(videoShare.Actor, videoShare.Video)
  70. await videoShare.save()
  71. }
  72. console.log('Updating video comments.')
  73. const videoComments: VideoCommentModel[] = await VideoCommentModel.findAll({
  74. include: [
  75. {
  76. model: VideoModel.unscoped()
  77. },
  78. {
  79. model: AccountModel.unscoped(),
  80. include: [
  81. {
  82. model: ActorModel.unscoped()
  83. }
  84. ]
  85. }
  86. ]
  87. })
  88. for (const comment of videoComments) {
  89. if (comment.isOwned() === false) continue
  90. console.log('Updating comment ' + comment.url)
  91. comment.url = getLocalVideoCommentActivityPubUrl(comment.Video, comment)
  92. await comment.save()
  93. }
  94. console.log('Updating video and torrent files.')
  95. const ids = await VideoModel.listLocalIds()
  96. for (const id of ids) {
  97. const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id)
  98. console.log('Updating video ' + video.uuid)
  99. video.url = getLocalVideoActivityPubUrl(video)
  100. await video.save()
  101. for (const file of video.VideoFiles) {
  102. console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid)
  103. await updateTorrentMetadata(video, file)
  104. await file.save()
  105. }
  106. const playlist = video.getHLSPlaylist()
  107. for (const file of (playlist?.VideoFiles || [])) {
  108. console.log('Updating fragmented torrent file %s of video %s.', file.resolution, video.uuid)
  109. await updateTorrentMetadata(playlist, file)
  110. await file.save()
  111. }
  112. }
  113. }