]>
Commit | Line | Data |
---|---|---|
2aaa1a3f C |
1 | import { registerTSPaths } from '../server/helpers/register-ts-paths' |
2 | registerTSPaths() | |
3 | ||
74dc3bca | 4 | import { WEBSERVER } from '../server/initializers/constants' |
50d6de9c | 5 | import { ActorFollowModel } from '../server/models/activitypub/actor-follow' |
3fd3ab2d | 6 | import { VideoModel } from '../server/models/video/video' |
23687332 C |
7 | import { ActorModel } from '../server/models/activitypub/actor' |
8 | import { | |
9 | getAccountActivityPubUrl, | |
74dc3bca | 10 | getVideoActivityPubUrl, |
5c6d985f | 11 | getVideoAnnounceActivityPubUrl, |
74dc3bca | 12 | getVideoChannelActivityPubUrl, |
23687332 C |
13 | getVideoCommentActivityPubUrl |
14 | } from '../server/lib/activitypub' | |
15 | import { VideoShareModel } from '../server/models/video/video-share' | |
16 | import { VideoCommentModel } from '../server/models/video/video-comment' | |
17 | import { getServerActor } from '../server/helpers/utils' | |
18 | import { AccountModel } from '../server/models/account/account' | |
19 | import { VideoChannelModel } from '../server/models/video/video-channel' | |
09209296 | 20 | import { VideoStreamingPlaylistModel } from '../server/models/video/video-streaming-playlist' |
74dc3bca | 21 | import { initDatabaseModels } from '../server/initializers' |
75d612ce | 22 | |
23687332 C |
23 | run() |
24 | .then(() => process.exit(0)) | |
25 | .catch(err => { | |
26 | console.error(err) | |
27 | process.exit(-1) | |
eb8b27c9 | 28 | }) |
23687332 C |
29 | |
30 | async 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 | |
64 | ? getAccountActivityPubUrl(actor.preferredUsername) | |
65 | : getVideoChannelActivityPubUrl(actor.preferredUsername) | |
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 | ||
5c6d985f | 87 | videoShare.url = getVideoAnnounceActivityPubUrl(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 | ||
112 | comment.url = getVideoCommentActivityPubUrl(comment.Video, comment) | |
113 | await comment.save() | |
114 | } | |
115 | ||
116 | console.log('Updating video and torrent files.') | |
117 | ||
09209296 | 118 | const videos = await VideoModel.listLocal() |
23687332 | 119 | for (const video of videos) { |
09209296 | 120 | console.log('Updating video ' + video.uuid) |
23687332 C |
121 | |
122 | video.url = getVideoActivityPubUrl(video) | |
123 | await video.save() | |
124 | ||
125 | for (const file of video.VideoFiles) { | |
126 | console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid) | |
127 | await video.createTorrentAndSetInfoHash(file) | |
128 | } | |
09209296 C |
129 | |
130 | for (const playlist of video.VideoStreamingPlaylists) { | |
74dc3bca C |
131 | playlist.playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid) |
132 | playlist.segmentsSha256Url = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid) | |
09209296 C |
133 | |
134 | await playlist.save() | |
135 | } | |
23687332 C |
136 | } |
137 | } |