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