1 import { WEBSERVER } from '../server/initializers/constants'
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 getVideoActivityPubUrl,
8 getVideoAnnounceActivityPubUrl,
9 getVideoChannelActivityPubUrl,
10 getVideoCommentActivityPubUrl
11 } from '../server/lib/activitypub'
12 import { VideoShareModel } from '../server/models/video/video-share'
13 import { VideoCommentModel } from '../server/models/video/video-comment'
14 import { getServerActor } from '../server/helpers/utils'
15 import { AccountModel } from '../server/models/account/account'
16 import { VideoChannelModel } from '../server/models/video/video-channel'
17 import { VideoStreamingPlaylistModel } from '../server/models/video/video-streaming-playlist'
18 import { initDatabaseModels } from '../server/initializers'
21 .then(() => process.exit(0))
27 async function run () {
28 await initDatabaseModels(true)
30 const serverAccount = await getServerActor()
33 const res = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
34 const hasFollowing = res.total > 0
36 if (hasFollowing === true) {
37 throw new Error('Cannot update host because you follow other servers!')
41 console.log('Updating actors.')
43 const actors: ActorModel[] = await ActorModel.unscoped().findAll({
46 model: VideoChannelModel.unscoped(),
50 model: AccountModel.unscoped(),
55 for (const actor of actors) {
56 if (actor.isOwned() === false) continue
58 console.log('Updating actor ' + actor.url)
60 const newUrl = actor.Account
61 ? getAccountActivityPubUrl(actor.preferredUsername)
62 : getVideoChannelActivityPubUrl(actor.preferredUsername)
65 actor.inboxUrl = newUrl + '/inbox'
66 actor.outboxUrl = newUrl + '/outbox'
67 actor.sharedInboxUrl = WEBSERVER.URL + '/inbox'
68 actor.followersUrl = newUrl + '/followers'
69 actor.followingUrl = newUrl + '/following'
74 console.log('Updating video shares.')
76 const videoShares: VideoShareModel[] = await VideoShareModel.findAll({
77 include: [ VideoModel.unscoped(), ActorModel.unscoped() ]
79 for (const videoShare of videoShares) {
80 if (videoShare.Video.isOwned() === false) continue
82 console.log('Updating video share ' + videoShare.url)
84 videoShare.url = getVideoAnnounceActivityPubUrl(videoShare.Actor, videoShare.Video)
85 await videoShare.save()
88 console.log('Updating video comments.')
89 const videoComments: VideoCommentModel[] = await VideoCommentModel.findAll({
92 model: VideoModel.unscoped()
95 model: AccountModel.unscoped(),
98 model: ActorModel.unscoped()
104 for (const comment of videoComments) {
105 if (comment.isOwned() === false) continue
107 console.log('Updating comment ' + comment.url)
109 comment.url = getVideoCommentActivityPubUrl(comment.Video, comment)
113 console.log('Updating video and torrent files.')
115 const videos = await VideoModel.listLocal()
116 for (const video of videos) {
117 console.log('Updating video ' + video.uuid)
119 video.url = getVideoActivityPubUrl(video)
122 for (const file of video.VideoFiles) {
123 console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid)
124 await video.createTorrentAndSetInfoHash(file)
127 for (const playlist of video.VideoStreamingPlaylists) {
128 playlist.playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid)
129 playlist.segmentsSha256Url = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid)
131 await playlist.save()