1 import { registerTSPaths } from '../server/helpers/register-ts-paths'
4 import { WEBSERVER } from '../server/initializers/constants'
5 import { ActorFollowModel } from '../server/models/actor/actor-follow'
6 import { VideoModel } from '../server/models/video/video'
7 import { ActorModel } from '../server/models/actor/actor'
9 getLocalAccountActivityPubUrl,
10 getLocalVideoActivityPubUrl,
11 getLocalVideoAnnounceActivityPubUrl,
12 getLocalVideoChannelActivityPubUrl,
13 getLocalVideoCommentActivityPubUrl
14 } from '../server/lib/activitypub/url'
15 import { VideoShareModel } from '../server/models/video/video-share'
16 import { VideoCommentModel } from '../server/models/video/video-comment'
17 import { AccountModel } from '../server/models/account/account'
18 import { VideoChannelModel } from '../server/models/video/video-channel'
19 import { initDatabaseModels } from '../server/initializers/database'
20 import { updateTorrentMetadata } from '@server/helpers/webtorrent'
21 import { getServerActor } from '@server/models/application/application'
24 .then(() => process.exit(0))
30 async function run () {
31 await initDatabaseModels(true)
33 const serverAccount = await getServerActor()
36 const res = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
37 const hasFollowing = res.total > 0
39 if (hasFollowing === true) {
40 throw new Error('Cannot update host because you follow other servers!')
44 console.log('Updating actors.')
46 const actors: ActorModel[] = await ActorModel.unscoped().findAll({
49 model: VideoChannelModel.unscoped(),
53 model: AccountModel.unscoped(),
58 for (const actor of actors) {
59 if (actor.isOwned() === false) continue
61 console.log('Updating actor ' + actor.url)
63 const newUrl = actor.Account
64 ? getLocalAccountActivityPubUrl(actor.preferredUsername)
65 : getLocalVideoChannelActivityPubUrl(actor.preferredUsername)
68 actor.inboxUrl = newUrl + '/inbox'
69 actor.outboxUrl = newUrl + '/outbox'
70 actor.sharedInboxUrl = WEBSERVER.URL + '/inbox'
71 actor.followersUrl = newUrl + '/followers'
72 actor.followingUrl = newUrl + '/following'
77 console.log('Updating video shares.')
79 const videoShares: VideoShareModel[] = await VideoShareModel.findAll({
80 include: [ VideoModel.unscoped(), ActorModel.unscoped() ]
82 for (const videoShare of videoShares) {
83 if (videoShare.Video.isOwned() === false) continue
85 console.log('Updating video share ' + videoShare.url)
87 videoShare.url = getLocalVideoAnnounceActivityPubUrl(videoShare.Actor, videoShare.Video)
88 await videoShare.save()
91 console.log('Updating video comments.')
92 const videoComments: VideoCommentModel[] = await VideoCommentModel.findAll({
95 model: VideoModel.unscoped()
98 model: AccountModel.unscoped(),
101 model: ActorModel.unscoped()
107 for (const comment of videoComments) {
108 if (comment.isOwned() === false) continue
110 console.log('Updating comment ' + comment.url)
112 comment.url = getLocalVideoCommentActivityPubUrl(comment.Video, comment)
116 console.log('Updating video and torrent files.')
118 const ids = await VideoModel.listLocalIds()
119 for (const id of ids) {
120 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(id)
122 console.log('Updating video ' + video.uuid)
124 video.url = getLocalVideoActivityPubUrl(video)
127 for (const file of video.VideoFiles) {
128 console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid)
129 await updateTorrentMetadata(video, file)
134 const playlist = video.getHLSPlaylist()
135 for (const file of (playlist?.VideoFiles || [])) {
136 console.log('Updating fragmented torrent file %s of video %s.', file.resolution, video.uuid)
138 await updateTorrentMetadata(playlist, file)