1 import { registerTSPaths } from '../server/helpers/register-ts-paths'
4 import { WEBSERVER } from '../server/initializers/constants'
5 import { ActorFollowModel } from '../server/models/activitypub/actor-follow'
6 import { VideoModel } from '../server/models/video/video'
7 import { ActorModel } from '../server/models/activitypub/actor'
9 getAccountActivityPubUrl,
10 getVideoActivityPubUrl,
11 getVideoAnnounceActivityPubUrl,
12 getVideoChannelActivityPubUrl,
13 getVideoCommentActivityPubUrl
14 } from '../server/lib/activitypub'
15 import { VideoShareModel } from '../server/models/video/video-share'
16 import { VideoCommentModel } from '../server/models/video/video-comment'
17 import { getServerActor } from '../server/helpers/utils'
18 import { AccountModel } from '../server/models/account/account'
19 import { VideoChannelModel } from '../server/models/video/video-channel'
20 import { VideoStreamingPlaylistModel } from '../server/models/video/video-streaming-playlist'
21 import { initDatabaseModels } from '../server/initializers'
22 import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent'
25 .then(() => process.exit(0))
31 async function run () {
32 await initDatabaseModels(true)
34 const serverAccount = await getServerActor()
37 const res = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
38 const hasFollowing = res.total > 0
40 if (hasFollowing === true) {
41 throw new Error('Cannot update host because you follow other servers!')
45 console.log('Updating actors.')
47 const actors: ActorModel[] = await ActorModel.unscoped().findAll({
50 model: VideoChannelModel.unscoped(),
54 model: AccountModel.unscoped(),
59 for (const actor of actors) {
60 if (actor.isOwned() === false) continue
62 console.log('Updating actor ' + actor.url)
64 const newUrl = actor.Account
65 ? getAccountActivityPubUrl(actor.preferredUsername)
66 : getVideoChannelActivityPubUrl(actor.preferredUsername)
69 actor.inboxUrl = newUrl + '/inbox'
70 actor.outboxUrl = newUrl + '/outbox'
71 actor.sharedInboxUrl = WEBSERVER.URL + '/inbox'
72 actor.followersUrl = newUrl + '/followers'
73 actor.followingUrl = newUrl + '/following'
78 console.log('Updating video shares.')
80 const videoShares: VideoShareModel[] = await VideoShareModel.findAll({
81 include: [ VideoModel.unscoped(), ActorModel.unscoped() ]
83 for (const videoShare of videoShares) {
84 if (videoShare.Video.isOwned() === false) continue
86 console.log('Updating video share ' + videoShare.url)
88 videoShare.url = getVideoAnnounceActivityPubUrl(videoShare.Actor, videoShare.Video)
89 await videoShare.save()
92 console.log('Updating video comments.')
93 const videoComments: VideoCommentModel[] = await VideoCommentModel.findAll({
96 model: VideoModel.unscoped()
99 model: AccountModel.unscoped(),
102 model: ActorModel.unscoped()
108 for (const comment of videoComments) {
109 if (comment.isOwned() === false) continue
111 console.log('Updating comment ' + comment.url)
113 comment.url = getVideoCommentActivityPubUrl(comment.Video, comment)
117 console.log('Updating video and torrent files.')
119 const videos = await VideoModel.listLocal()
120 for (const video of videos) {
121 console.log('Updating video ' + video.uuid)
123 video.url = getVideoActivityPubUrl(video)
126 for (const file of video.VideoFiles) {
127 console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid)
128 await createTorrentAndSetInfoHash(video, file)
131 for (const playlist of video.VideoStreamingPlaylists) {
132 playlist.playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid)
133 playlist.segmentsSha256Url = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid)
135 await playlist.save()