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 getAnnounceActivityPubUrl,
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'
18 .then(() => process.exit(0))
24 async function run () {
25 await initDatabaseModels(true)
27 const serverAccount = await getServerActor()
30 const res = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
31 const hasFollowing = res.total > 0
33 if (hasFollowing === true) {
34 throw new Error('Cannot update host because you follow other servers!')
38 console.log('Updating actors.')
40 const actors: ActorModel[] = await ActorModel.unscoped().findAll({
43 model: VideoChannelModel.unscoped(),
47 model: AccountModel.unscoped(),
52 for (const actor of actors) {
53 if (actor.isOwned() === false) continue
55 console.log('Updating actor ' + actor.url)
57 const newUrl = actor.Account
58 ? getAccountActivityPubUrl(actor.preferredUsername)
59 : getVideoChannelActivityPubUrl(actor.preferredUsername)
62 actor.inboxUrl = newUrl + '/inbox'
63 actor.outboxUrl = newUrl + '/outbox'
64 actor.sharedInboxUrl = CONFIG.WEBSERVER.URL + '/inbox'
65 actor.followersUrl = newUrl + '/followers'
66 actor.followingUrl = newUrl + '/following'
71 console.log('Updating video shares.')
73 const videoShares: VideoShareModel[] = await VideoShareModel.findAll({
74 include: [ VideoModel.unscoped(), ActorModel.unscoped() ]
76 for (const videoShare of videoShares) {
77 if (videoShare.Video.isOwned() === false) continue
79 console.log('Updating video share ' + videoShare.url)
81 videoShare.url = getAnnounceActivityPubUrl(videoShare.Video.url, videoShare.Actor)
82 await videoShare.save()
85 console.log('Updating video comments.')
86 const videoComments: VideoCommentModel[] = await VideoCommentModel.findAll({
89 model: VideoModel.unscoped()
92 model: AccountModel.unscoped(),
95 model: ActorModel.unscoped()
101 for (const comment of videoComments) {
102 if (comment.isOwned() === false) continue
104 console.log('Updating comment ' + comment.url)
106 comment.url = getVideoCommentActivityPubUrl(comment.Video, comment)
110 console.log('Updating video and torrent files.')
112 const videos = await VideoModel.list()
113 for (const video of videos) {
114 if (video.isOwned() === false) continue
116 console.log('Updated video ' + video.uuid)
118 video.url = getVideoActivityPubUrl(video)
121 for (const file of video.VideoFiles) {
122 console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid)
123 await video.createTorrentAndSetInfoHash(file)