]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - scripts/update-host.ts
Stop using tsconfig register
[github/Chocobozzz/PeerTube.git] / scripts / update-host.ts
index d2fb19c76352fcf9819d049acb7b053e278115d7..bb54290a45c410a24c6bd3f1f7b0fe96d49dff34 100755 (executable)
@@ -1,25 +1,21 @@
-import { registerTSPaths } from '../server/helpers/register-ts-paths'
-registerTSPaths()
-
+import { updateTorrentMetadata } from '@server/helpers/webtorrent'
+import { getServerActor } from '@server/models/application/application'
 import { WEBSERVER } from '../server/initializers/constants'
-import { ActorFollowModel } from '../server/models/activitypub/actor-follow'
-import { VideoModel } from '../server/models/video/video'
-import { ActorModel } from '../server/models/activitypub/actor'
+import { initDatabaseModels } from '../server/initializers/database'
 import {
-  getAccountActivityPubUrl,
-  getVideoActivityPubUrl,
-  getVideoAnnounceActivityPubUrl,
-  getVideoChannelActivityPubUrl,
-  getVideoCommentActivityPubUrl
+  getLocalAccountActivityPubUrl,
+  getLocalVideoActivityPubUrl,
+  getLocalVideoAnnounceActivityPubUrl,
+  getLocalVideoChannelActivityPubUrl,
+  getLocalVideoCommentActivityPubUrl
 } from '../server/lib/activitypub/url'
-import { VideoShareModel } from '../server/models/video/video-share'
-import { VideoCommentModel } from '../server/models/video/video-comment'
 import { AccountModel } from '../server/models/account/account'
+import { ActorModel } from '../server/models/actor/actor'
+import { ActorFollowModel } from '../server/models/actor/actor-follow'
+import { VideoModel } from '../server/models/video/video'
 import { VideoChannelModel } from '../server/models/video/video-channel'
-import { VideoStreamingPlaylistModel } from '../server/models/video/video-streaming-playlist'
-import { initDatabaseModels } from '../server/initializers/database'
-import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
-import { getServerActor } from '@server/models/application/application'
+import { VideoCommentModel } from '../server/models/video/video-comment'
+import { VideoShareModel } from '../server/models/video/video-share'
 
 run()
   .then(() => process.exit(0))
@@ -62,8 +58,8 @@ async function run () {
     console.log('Updating actor ' + actor.url)
 
     const newUrl = actor.Account
-      ? getAccountActivityPubUrl(actor.preferredUsername)
-      : getVideoChannelActivityPubUrl(actor.preferredUsername)
+      ? getLocalAccountActivityPubUrl(actor.preferredUsername)
+      : getLocalVideoChannelActivityPubUrl(actor.preferredUsername)
 
     actor.url = newUrl
     actor.inboxUrl = newUrl + '/inbox'
@@ -85,7 +81,7 @@ async function run () {
 
     console.log('Updating video share ' + videoShare.url)
 
-    videoShare.url = getVideoAnnounceActivityPubUrl(videoShare.Actor, videoShare.Video)
+    videoShare.url = getLocalVideoAnnounceActivityPubUrl(videoShare.Actor, videoShare.Video)
     await videoShare.save()
   }
 
@@ -110,29 +106,35 @@ async function run () {
 
     console.log('Updating comment ' + comment.url)
 
-    comment.url = getVideoCommentActivityPubUrl(comment.Video, comment)
+    comment.url = getLocalVideoCommentActivityPubUrl(comment.Video, comment)
     await comment.save()
   }
 
   console.log('Updating video and torrent files.')
 
-  const videos = await VideoModel.listLocal()
-  for (const video of videos) {
+  const ids = await VideoModel.listLocalIds()
+  for (const id of ids) {
+    const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id)
+
     console.log('Updating video ' + video.uuid)
 
-    video.url = getVideoActivityPubUrl(video)
+    video.url = getLocalVideoActivityPubUrl(video)
     await video.save()
 
     for (const file of video.VideoFiles) {
       console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid)
-      await createTorrentAndSetInfoHash(video, file)
+      await updateTorrentMetadata(video, file)
+
+      await file.save()
     }
 
-    for (const playlist of video.VideoStreamingPlaylists) {
-      playlist.playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid)
-      playlist.segmentsSha256Url = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid, video.isLive)
+    const playlist = video.getHLSPlaylist()
+    for (const file of (playlist?.VideoFiles || [])) {
+      console.log('Updating fragmented torrent file %s of video %s.', file.resolution, video.uuid)
+
+      await updateTorrentMetadata(playlist, file)
 
-      await playlist.save()
+      await file.save()
     }
   }
 }