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