]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/update-host.ts
More specific message when signup is not allowed
[github/Chocobozzz/PeerTube.git] / scripts / update-host.ts
CommitLineData
f8360396
C
1import { updateTorrentMetadata } from '@server/helpers/webtorrent'
2import { getServerActor } from '@server/models/application/application'
74dc3bca 3import { WEBSERVER } from '../server/initializers/constants'
f8360396 4import { initDatabaseModels } from '../server/initializers/database'
23687332 5import {
de94ac86
C
6 getLocalAccountActivityPubUrl,
7 getLocalVideoActivityPubUrl,
8 getLocalVideoAnnounceActivityPubUrl,
9 getLocalVideoChannelActivityPubUrl,
10 getLocalVideoCommentActivityPubUrl
e1c55031 11} from '../server/lib/activitypub/url'
23687332 12import { AccountModel } from '../server/models/account/account'
f8360396
C
13import { ActorModel } from '../server/models/actor/actor'
14import { ActorFollowModel } from '../server/models/actor/actor-follow'
15import { VideoModel } from '../server/models/video/video'
23687332 16import { VideoChannelModel } from '../server/models/video/video-channel'
f8360396
C
17import { VideoCommentModel } from '../server/models/video/video-comment'
18import { VideoShareModel } from '../server/models/video/video-share'
d7a25329 19
23687332
C
20run()
21 .then(() => process.exit(0))
22 .catch(err => {
23 console.error(err)
24 process.exit(-1)
eb8b27c9 25 })
23687332
C
26
27async function run () {
28 await initDatabaseModels(true)
29
30 const serverAccount = await getServerActor()
31
32 {
33 const res = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
34 const hasFollowing = res.total > 0
35
eb8b27c9 36 if (hasFollowing === true) {
23687332 37 throw new Error('Cannot update host because you follow other servers!')
75d612ce 38 }
23687332 39 }
75d612ce 40
23687332
C
41 console.log('Updating actors.')
42
43 const actors: ActorModel[] = await ActorModel.unscoped().findAll({
44 include: [
45 {
46 model: VideoChannelModel.unscoped(),
47 required: false
48 },
49 {
50 model: AccountModel.unscoped(),
51 required: false
c91de743 52 }
23687332
C
53 ]
54 })
55 for (const actor of actors) {
56 if (actor.isOwned() === false) continue
57
58 console.log('Updating actor ' + actor.url)
59
60 const newUrl = actor.Account
de94ac86
C
61 ? getLocalAccountActivityPubUrl(actor.preferredUsername)
62 : getLocalVideoChannelActivityPubUrl(actor.preferredUsername)
23687332
C
63
64 actor.url = newUrl
65 actor.inboxUrl = newUrl + '/inbox'
66 actor.outboxUrl = newUrl + '/outbox'
74dc3bca 67 actor.sharedInboxUrl = WEBSERVER.URL + '/inbox'
23687332
C
68 actor.followersUrl = newUrl + '/followers'
69 actor.followingUrl = newUrl + '/following'
70
71 await actor.save()
72 }
73
74 console.log('Updating video shares.')
75
76 const videoShares: VideoShareModel[] = await VideoShareModel.findAll({
77 include: [ VideoModel.unscoped(), ActorModel.unscoped() ]
fdbda9e3 78 })
23687332
C
79 for (const videoShare of videoShares) {
80 if (videoShare.Video.isOwned() === false) continue
81
82 console.log('Updating video share ' + videoShare.url)
83
de94ac86 84 videoShare.url = getLocalVideoAnnounceActivityPubUrl(videoShare.Actor, videoShare.Video)
23687332
C
85 await videoShare.save()
86 }
87
88 console.log('Updating video comments.')
89 const videoComments: VideoCommentModel[] = await VideoCommentModel.findAll({
90 include: [
91 {
92 model: VideoModel.unscoped()
93 },
94 {
95 model: AccountModel.unscoped(),
96 include: [
97 {
98 model: ActorModel.unscoped()
99 }
100 ]
101 }
102 ]
75d612ce 103 })
23687332
C
104 for (const comment of videoComments) {
105 if (comment.isOwned() === false) continue
106
107 console.log('Updating comment ' + comment.url)
108
de94ac86 109 comment.url = getLocalVideoCommentActivityPubUrl(comment.Video, comment)
23687332
C
110 await comment.save()
111 }
112
113 console.log('Updating video and torrent files.')
114
e1ab52d7 115 const ids = await VideoModel.listLocalIds()
116 for (const id of ids) {
4fae2b1f 117 const video = await VideoModel.loadFull(id)
90a8bd30 118
09209296 119 console.log('Updating video ' + video.uuid)
23687332 120
de94ac86 121 video.url = getLocalVideoActivityPubUrl(video)
23687332
C
122 await video.save()
123
124 for (const file of video.VideoFiles) {
125 console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid)
9b293cd6 126 await updateTorrentMetadata(video, file)
764b1a14
C
127
128 await file.save()
23687332 129 }
09209296 130
764b1a14
C
131 const playlist = video.getHLSPlaylist()
132 for (const file of (playlist?.VideoFiles || [])) {
133 console.log('Updating fragmented torrent file %s of video %s.', file.resolution, video.uuid)
134
6ba93fa6 135 await updateTorrentMetadata(playlist, file)
09209296 136
764b1a14 137 await file.save()
09209296 138 }
23687332
C
139 }
140}