]>
Commit | Line | Data |
---|---|---|
2aaa1a3f | 1 | import { registerTSPaths } from '../server/helpers/register-ts-paths' |
20146df2 C |
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' |
d7a25329 C |
22 | import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' |
23 | ||
23687332 C |
24 | run() |
25 | .then(() => process.exit(0)) | |
26 | .catch(err => { | |
27 | console.error(err) | |
28 | process.exit(-1) | |
eb8b27c9 | 29 | }) |
23687332 C |
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 | ||
eb8b27c9 | 40 | if (hasFollowing === true) { |
23687332 | 41 | throw new Error('Cannot update host because you follow other servers!') |
75d612ce | 42 | } |
23687332 | 43 | } |
75d612ce | 44 | |
23687332 C |
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 | |
c91de743 | 56 | } |
23687332 C |
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 | ? getAccountActivityPubUrl(actor.preferredUsername) | |
66 | : getVideoChannelActivityPubUrl(actor.preferredUsername) | |
67 | ||
68 | actor.url = newUrl | |
69 | actor.inboxUrl = newUrl + '/inbox' | |
70 | actor.outboxUrl = newUrl + '/outbox' | |
74dc3bca | 71 | actor.sharedInboxUrl = WEBSERVER.URL + '/inbox' |
23687332 C |
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() ] | |
fdbda9e3 | 82 | }) |
23687332 C |
83 | for (const videoShare of videoShares) { |
84 | if (videoShare.Video.isOwned() === false) continue | |
85 | ||
86 | console.log('Updating video share ' + videoShare.url) | |
87 | ||
5c6d985f | 88 | videoShare.url = getVideoAnnounceActivityPubUrl(videoShare.Actor, videoShare.Video) |
23687332 C |
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 | ] | |
75d612ce | 107 | }) |
23687332 C |
108 | for (const comment of videoComments) { |
109 | if (comment.isOwned() === false) continue | |
110 | ||
111 | console.log('Updating comment ' + comment.url) | |
112 | ||
113 | comment.url = getVideoCommentActivityPubUrl(comment.Video, comment) | |
114 | await comment.save() | |
115 | } | |
116 | ||
117 | console.log('Updating video and torrent files.') | |
118 | ||
09209296 | 119 | const videos = await VideoModel.listLocal() |
23687332 | 120 | for (const video of videos) { |
09209296 | 121 | console.log('Updating video ' + video.uuid) |
23687332 C |
122 | |
123 | video.url = getVideoActivityPubUrl(video) | |
124 | await video.save() | |
125 | ||
126 | for (const file of video.VideoFiles) { | |
127 | console.log('Updating torrent file %s of video %s.', file.resolution, video.uuid) | |
d7a25329 | 128 | await createTorrentAndSetInfoHash(video, file) |
23687332 | 129 | } |
09209296 C |
130 | |
131 | for (const playlist of video.VideoStreamingPlaylists) { | |
74dc3bca C |
132 | playlist.playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid) |
133 | playlist.segmentsSha256Url = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid) | |
09209296 C |
134 | |
135 | await playlist.save() | |
136 | } | |
23687332 C |
137 | } |
138 | } |