]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - scripts/update-host.ts
Add hls support on server
[github/Chocobozzz/PeerTube.git] / scripts / update-host.ts
CommitLineData
23687332 1import { CONFIG, initDatabaseModels } from '../server/initializers'
50d6de9c 2import { ActorFollowModel } from '../server/models/activitypub/actor-follow'
3fd3ab2d 3import { VideoModel } from '../server/models/video/video'
23687332
C
4import { ActorModel } from '../server/models/activitypub/actor'
5import {
6 getAccountActivityPubUrl,
5c6d985f 7 getVideoAnnounceActivityPubUrl,
23687332
C
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'
09209296 16import { VideoStreamingPlaylistModel } from '../server/models/video/video-streaming-playlist'
75d612ce 17
23687332
C
18run()
19 .then(() => process.exit(0))
20 .catch(err => {
21 console.error(err)
22 process.exit(-1)
eb8b27c9 23 })
23687332
C
24
25async function run () {
26 await initDatabaseModels(true)
27
28 const serverAccount = await getServerActor()
29
30 {
31 const res = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined)
32 const hasFollowing = res.total > 0
33
eb8b27c9 34 if (hasFollowing === true) {
23687332 35 throw new Error('Cannot update host because you follow other servers!')
75d612ce 36 }
23687332 37 }
75d612ce 38
23687332
C
39 console.log('Updating actors.')
40
41 const actors: ActorModel[] = await ActorModel.unscoped().findAll({
42 include: [
43 {
44 model: VideoChannelModel.unscoped(),
45 required: false
46 },
47 {
48 model: AccountModel.unscoped(),
49 required: false
c91de743 50 }
23687332
C
51 ]
52 })
53 for (const actor of actors) {
54 if (actor.isOwned() === false) continue
55
56 console.log('Updating actor ' + actor.url)
57
58 const newUrl = actor.Account
59 ? getAccountActivityPubUrl(actor.preferredUsername)
60 : getVideoChannelActivityPubUrl(actor.preferredUsername)
61
62 actor.url = newUrl
63 actor.inboxUrl = newUrl + '/inbox'
64 actor.outboxUrl = newUrl + '/outbox'
65 actor.sharedInboxUrl = CONFIG.WEBSERVER.URL + '/inbox'
66 actor.followersUrl = newUrl + '/followers'
67 actor.followingUrl = newUrl + '/following'
68
69 await actor.save()
70 }
71
72 console.log('Updating video shares.')
73
74 const videoShares: VideoShareModel[] = await VideoShareModel.findAll({
75 include: [ VideoModel.unscoped(), ActorModel.unscoped() ]
fdbda9e3 76 })
23687332
C
77 for (const videoShare of videoShares) {
78 if (videoShare.Video.isOwned() === false) continue
79
80 console.log('Updating video share ' + videoShare.url)
81
5c6d985f 82 videoShare.url = getVideoAnnounceActivityPubUrl(videoShare.Actor, videoShare.Video)
23687332
C
83 await videoShare.save()
84 }
85
86 console.log('Updating video comments.')
87 const videoComments: VideoCommentModel[] = await VideoCommentModel.findAll({
88 include: [
89 {
90 model: VideoModel.unscoped()
91 },
92 {
93 model: AccountModel.unscoped(),
94 include: [
95 {
96 model: ActorModel.unscoped()
97 }
98 ]
99 }
100 ]
75d612ce 101 })
23687332
C
102 for (const comment of videoComments) {
103 if (comment.isOwned() === false) continue
104
105 console.log('Updating comment ' + comment.url)
106
107 comment.url = getVideoCommentActivityPubUrl(comment.Video, comment)
108 await comment.save()
109 }
110
111 console.log('Updating video and torrent files.')
112
09209296 113 const videos = await VideoModel.listLocal()
23687332 114 for (const video of videos) {
09209296 115 console.log('Updating video ' + video.uuid)
23687332
C
116
117 video.url = getVideoActivityPubUrl(video)
118 await video.save()
119
120 for (const file of video.VideoFiles) {
121 console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid)
122 await video.createTorrentAndSetInfoHash(file)
123 }
09209296
C
124
125 for (const playlist of video.VideoStreamingPlaylists) {
126 playlist.playlistUrl = CONFIG.WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid)
127 playlist.segmentsSha256Url = CONFIG.WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid)
128
129 await playlist.save()
130 }
23687332
C
131 }
132}