aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/update-host.ts141
1 files changed, 116 insertions, 25 deletions
diff --git a/scripts/update-host.ts b/scripts/update-host.ts
index ed8b999a9..1dc19664d 100755
--- a/scripts/update-host.ts
+++ b/scripts/update-host.ts
@@ -1,35 +1,126 @@
1import { getServerActor } from '../server/helpers/utils' 1import { CONFIG, initDatabaseModels } from '../server/initializers'
2import { initDatabaseModels } from '../server/initializers'
3import { ActorFollowModel } from '../server/models/activitypub/actor-follow' 2import { ActorFollowModel } from '../server/models/activitypub/actor-follow'
4import { VideoModel } from '../server/models/video/video' 3import { VideoModel } from '../server/models/video/video'
4import { ActorModel } from '../server/models/activitypub/actor'
5import {
6 getAccountActivityPubUrl,
7 getAnnounceActivityPubUrl,
8 getVideoActivityPubUrl, getVideoChannelActivityPubUrl,
9 getVideoCommentActivityPubUrl
10} from '../server/lib/activitypub'
11import { VideoShareModel } from '../server/models/video/video-share'
12import { VideoCommentModel } from '../server/models/video/video-comment'
13import { getServerActor } from '../server/helpers/utils'
14import { AccountModel } from '../server/models/account/account'
15import { VideoChannelModel } from '../server/models/video/video-channel'
5 16
6initDatabaseModels(true) 17run()
7 .then(() => { 18 .then(() => process.exit(0))
8 return getServerActor() 19 .catch(err => {
9 }) 20 console.error(err)
10 .then(serverAccount => { 21 process.exit(-1)
11 return ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
12 })
13 .then(res => {
14 return res.total > 0
15 }) 22 })
16 .then(hasFollowing => { 23
24async function run () {
25 await initDatabaseModels(true)
26
27 const serverAccount = await getServerActor()
28
29 {
30 const res = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
31 const hasFollowing = res.total > 0
32
17 if (hasFollowing === true) { 33 if (hasFollowing === true) {
18 console.log('Cannot update host because you follow other servers!') 34 throw new Error('Cannot update host because you follow other servers!')
19 process.exit(-1)
20 } 35 }
36 }
21 37
22 console.log('Updating torrent files.') 38 console.log('Updating actors.')
23 return VideoModel.list() 39
24 }) 40 const actors: ActorModel[] = await ActorModel.unscoped().findAll({
25 .then(async videos => { 41 include: [
26 for (const video of videos) { 42 {
27 for (const file of video.VideoFiles) { 43 model: VideoChannelModel.unscoped(),
28 await video.createTorrentAndSetInfoHash(file) 44 required: false
29 console.log('Updated video ' + video.uuid) 45 },
46 {
47 model: AccountModel.unscoped(),
48 required: false
30 } 49 }
31 } 50 ]
51 })
52 for (const actor of actors) {
53 if (actor.isOwned() === false) continue
54
55 console.log('Updating actor ' + actor.url)
56
57 const newUrl = actor.Account
58 ? getAccountActivityPubUrl(actor.preferredUsername)
59 : getVideoChannelActivityPubUrl(actor.preferredUsername)
60
61 actor.url = newUrl
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'
67
68 await actor.save()
69 }
70
71 console.log('Updating video shares.')
72
73 const videoShares: VideoShareModel[] = await VideoShareModel.findAll({
74 include: [ VideoModel.unscoped(), ActorModel.unscoped() ]
32 }) 75 })
33 .then(() => { 76 for (const videoShare of videoShares) {
34 process.exit(0) 77 if (videoShare.Video.isOwned() === false) continue
78
79 console.log('Updating video share ' + videoShare.url)
80
81 videoShare.url = getAnnounceActivityPubUrl(videoShare.Video.url, videoShare.Actor)
82 await videoShare.save()
83 }
84
85 console.log('Updating video comments.')
86 const videoComments: VideoCommentModel[] = await VideoCommentModel.findAll({
87 include: [
88 {
89 model: VideoModel.unscoped()
90 },
91 {
92 model: AccountModel.unscoped(),
93 include: [
94 {
95 model: ActorModel.unscoped()
96 }
97 ]
98 }
99 ]
35 }) 100 })
101 for (const comment of videoComments) {
102 if (comment.isOwned() === false) continue
103
104 console.log('Updating comment ' + comment.url)
105
106 comment.url = getVideoCommentActivityPubUrl(comment.Video, comment)
107 await comment.save()
108 }
109
110 console.log('Updating video and torrent files.')
111
112 const videos = await VideoModel.list()
113 for (const video of videos) {
114 if (video.isOwned() === false) continue
115
116 console.log('Updated video ' + video.uuid)
117
118 video.url = getVideoActivityPubUrl(video)
119 await video.save()
120
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)
124 }
125 }
126}