1 import { CONFIG, initDatabaseModels } from '../server/initializers'
2 import { ActorFollowModel } from '../server/models/activitypub/actor-follow'
3 import { VideoModel } from '../server/models/video/video'
4 import { ActorModel } from '../server/models/activitypub/actor'
6 getAccountActivityPubUrl,
7 getVideoAnnounceActivityPubUrl,
8 getVideoActivityPubUrl, getVideoChannelActivityPubUrl,
9 getVideoCommentActivityPubUrl
10 } from '../server/lib/activitypub'
11 import { VideoShareModel } from '../server/models/video/video-share'
12 import { VideoCommentModel } from '../server/models/video/video-comment'
13 import { getServerActor } from '../server/helpers/utils'
14 import { AccountModel } from '../server/models/account/account'
15 import { VideoChannelModel } from '../server/models/video/video-channel'
16 import { VideoStreamingPlaylistModel } from '../server/models/video/video-streaming-playlist'
19 .then(() => process.exit(0))
25 async function run () {
26 await initDatabaseModels(true)
28 const serverAccount = await getServerActor()
31 const res = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
32 const hasFollowing = res.total > 0
34 if (hasFollowing === true) {
35 throw new Error('Cannot update host because you follow other servers!')
39 console.log('Updating actors.')
41 const actors: ActorModel[] = await ActorModel.unscoped().findAll({
44 model: VideoChannelModel.unscoped(),
48 model: AccountModel.unscoped(),
53 for (const actor of actors) {
54 if (actor.isOwned() === false) continue
56 console.log('Updating actor ' + actor.url)
58 const newUrl = actor.Account
59 ? getAccountActivityPubUrl(actor.preferredUsername)
60 : getVideoChannelActivityPubUrl(actor.preferredUsername)
63 actor.inboxUrl = newUrl + '/inbox'
64 actor.outboxUrl = newUrl + '/outbox'
65 actor.sharedInboxUrl = CONFIG.WEBSERVER.URL + '/inbox'
66 actor.followersUrl = newUrl + '/followers'
67 actor.followingUrl = newUrl + '/following'
72 console.log('Updating video shares.')
74 const videoShares: VideoShareModel[] = await VideoShareModel.findAll({
75 include: [ VideoModel.unscoped(), ActorModel.unscoped() ]
77 for (const videoShare of videoShares) {
78 if (videoShare.Video.isOwned() === false) continue
80 console.log('Updating video share ' + videoShare.url)
82 videoShare.url = getVideoAnnounceActivityPubUrl(videoShare.Actor, videoShare.Video)
83 await videoShare.save()
86 console.log('Updating video comments.')
87 const videoComments: VideoCommentModel[] = await VideoCommentModel.findAll({
90 model: VideoModel.unscoped()
93 model: AccountModel.unscoped(),
96 model: ActorModel.unscoped()
102 for (const comment of videoComments) {
103 if (comment.isOwned() === false) continue
105 console.log('Updating comment ' + comment.url)
107 comment.url = getVideoCommentActivityPubUrl(comment.Video, comment)
111 console.log('Updating video and torrent files.')
113 const videos = await VideoModel.listLocal()
114 for (const video of videos) {
115 console.log('Updating video ' + video.uuid)
117 video.url = getVideoActivityPubUrl(video)
120 for (const file of video.VideoFiles) {
121 console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid)
122 await video.createTorrentAndSetInfoHash(file)
125 for (const playlist of video.VideoStreamingPlaylists) {
126 playlist.playlistUrl = CONFIG.WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid)
127 playlist.segmentsSha256Url = CONFIG.WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid)
129 await playlist.save()