]>
Commit | Line | Data |
---|---|---|
7e98a7df | 1 | import { REMOTE_SCHEME, WEBSERVER } from '../../initializers/constants' |
453e83ea | 2 | import { |
d26836cd | 3 | MAbuseFull, |
de94ac86 | 4 | MAbuseId, |
453e83ea | 5 | MActor, |
0f58b11f | 6 | MActorFollow, |
453e83ea C |
7 | MActorId, |
8 | MActorUrl, | |
9 | MCommentId, | |
b2111066 | 10 | MLocalVideoViewer, |
453e83ea | 11 | MVideoId, |
de94ac86 | 12 | MVideoPlaylistElement, |
453e83ea | 13 | MVideoUrl, |
7e98a7df C |
14 | MVideoUUID, |
15 | MVideoWithHost | |
26d6bf65 | 16 | } from '../../types/models' |
26d6bf65 | 17 | import { MVideoFileVideoUUID } from '../../types/models/video/video-file' |
de94ac86 | 18 | import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist' |
26d6bf65 | 19 | import { MStreamingPlaylist } from '../../types/models/video/video-streaming-playlist' |
453e83ea | 20 | |
de94ac86 | 21 | function getLocalVideoActivityPubUrl (video: MVideoUUID) { |
6dd9de95 | 22 | return WEBSERVER.URL + '/videos/watch/' + video.uuid |
892211e8 C |
23 | } |
24 | ||
de94ac86 | 25 | function getLocalVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) { |
6dd9de95 | 26 | return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid |
418d092a C |
27 | } |
28 | ||
de94ac86 | 29 | function getLocalVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) { |
37190663 | 30 | return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id |
418d092a C |
31 | } |
32 | ||
de94ac86 | 33 | function getLocalVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) { |
d05be4d9 | 34 | const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : '' |
c48e82b5 | 35 | |
6dd9de95 | 36 | return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}` |
c48e82b5 C |
37 | } |
38 | ||
de94ac86 | 39 | function getLocalVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) { |
6dd9de95 | 40 | return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}` |
09209296 C |
41 | } |
42 | ||
de94ac86 | 43 | function getLocalVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) { |
6dd9de95 | 44 | return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id |
50d6de9c C |
45 | } |
46 | ||
de94ac86 | 47 | function getLocalVideoChannelActivityPubUrl (videoChannelName: string) { |
6dd9de95 | 48 | return WEBSERVER.URL + '/video-channels/' + videoChannelName |
892211e8 C |
49 | } |
50 | ||
de94ac86 | 51 | function getLocalAccountActivityPubUrl (accountName: string) { |
6dd9de95 | 52 | return WEBSERVER.URL + '/accounts/' + accountName |
892211e8 C |
53 | } |
54 | ||
de94ac86 | 55 | function getLocalAbuseActivityPubUrl (abuse: MAbuseId) { |
d95d1559 | 56 | return WEBSERVER.URL + '/admin/abuses/' + abuse.id |
892211e8 C |
57 | } |
58 | ||
ac907dc7 C |
59 | function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId, viewerIdentifier: string) { |
60 | return byActor.url + '/views/videos/' + video.id + '/' + viewerIdentifier | |
40ff5707 C |
61 | } |
62 | ||
b2111066 C |
63 | function getLocalVideoViewerActivityPubUrl (stats: MLocalVideoViewer) { |
64 | return WEBSERVER.URL + '/videos/local-viewer/' + stats.uuid | |
65 | } | |
66 | ||
de94ac86 | 67 | function getVideoLikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) { |
50d6de9c | 68 | return byActor.url + '/likes/' + video.id |
0032ebe9 C |
69 | } |
70 | ||
de94ac86 | 71 | function getVideoDislikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) { |
50d6de9c | 72 | return byActor.url + '/dislikes/' + video.id |
0032ebe9 C |
73 | } |
74 | ||
de94ac86 | 75 | function getLocalVideoSharesActivityPubUrl (video: MVideoUrl) { |
46531a0a C |
76 | return video.url + '/announces' |
77 | } | |
78 | ||
de94ac86 | 79 | function getLocalVideoCommentsActivityPubUrl (video: MVideoUrl) { |
46531a0a C |
80 | return video.url + '/comments' |
81 | } | |
82 | ||
de94ac86 | 83 | function getLocalVideoLikesActivityPubUrl (video: MVideoUrl) { |
46531a0a C |
84 | return video.url + '/likes' |
85 | } | |
86 | ||
de94ac86 | 87 | function getLocalVideoDislikesActivityPubUrl (video: MVideoUrl) { |
46531a0a C |
88 | return video.url + '/dislikes' |
89 | } | |
90 | ||
de94ac86 | 91 | function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorId) { |
5b9c965d | 92 | return follower.url + '/follows/' + following.id |
892211e8 C |
93 | } |
94 | ||
0f58b11f | 95 | function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollow) { |
9e2a4af3 | 96 | return WEBSERVER.URL + '/accepts/follows/' + actorFollow.id |
892211e8 C |
97 | } |
98 | ||
9e2a4af3 C |
99 | function getLocalActorFollowRejectActivityPubUrl () { |
100 | return WEBSERVER.URL + '/rejects/follows/' + new Date().toISOString() | |
5b9c965d C |
101 | } |
102 | ||
de94ac86 | 103 | function getLocalVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) { |
5c6d985f | 104 | return video.url + '/announces/' + byActor.id |
892211e8 C |
105 | } |
106 | ||
c3badc81 C |
107 | function getDeleteActivityPubUrl (originalUrl: string) { |
108 | return originalUrl + '/delete' | |
109 | } | |
110 | ||
892211e8 | 111 | function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) { |
4e50b6a1 | 112 | return originalUrl + '/updates/' + updatedAt |
892211e8 C |
113 | } |
114 | ||
115 | function getUndoActivityPubUrl (originalUrl: string) { | |
116 | return originalUrl + '/undo' | |
117 | } | |
118 | ||
d26836cd C |
119 | // --------------------------------------------------------------------------- |
120 | ||
121 | function getAbuseTargetUrl (abuse: MAbuseFull) { | |
122 | return abuse.VideoAbuse?.Video?.url || | |
123 | abuse.VideoCommentAbuse?.VideoComment?.url || | |
124 | abuse.FlaggedAccount.Actor.url | |
125 | } | |
126 | ||
7e98a7df C |
127 | // --------------------------------------------------------------------------- |
128 | ||
129 | function buildRemoteVideoBaseUrl (video: MVideoWithHost, path: string, scheme?: string) { | |
130 | if (!scheme) scheme = REMOTE_SCHEME.HTTP | |
131 | ||
132 | const host = video.VideoChannel.Actor.Server.host | |
133 | ||
134 | return scheme + '://' + host + path | |
135 | } | |
136 | ||
137 | // --------------------------------------------------------------------------- | |
138 | ||
139 | function checkUrlsSameHost (url1: string, url2: string) { | |
140 | const idHost = new URL(url1).host | |
141 | const actorHost = new URL(url2).host | |
142 | ||
143 | return idHost && actorHost && idHost.toLowerCase() === actorHost.toLowerCase() | |
144 | } | |
145 | ||
146 | // --------------------------------------------------------------------------- | |
147 | ||
892211e8 | 148 | export { |
de94ac86 C |
149 | getLocalVideoActivityPubUrl, |
150 | getLocalVideoPlaylistActivityPubUrl, | |
151 | getLocalVideoPlaylistElementActivityPubUrl, | |
152 | getLocalVideoCacheFileActivityPubUrl, | |
153 | getLocalVideoCacheStreamingPlaylistActivityPubUrl, | |
154 | getLocalVideoCommentActivityPubUrl, | |
155 | getLocalVideoChannelActivityPubUrl, | |
156 | getLocalAccountActivityPubUrl, | |
157 | getLocalAbuseActivityPubUrl, | |
158 | getLocalActorFollowActivityPubUrl, | |
159 | getLocalActorFollowAcceptActivityPubUrl, | |
160 | getLocalVideoAnnounceActivityPubUrl, | |
892211e8 | 161 | getUpdateActivityPubUrl, |
40ff5707 | 162 | getUndoActivityPubUrl, |
de94ac86 C |
163 | getVideoLikeActivityPubUrlByLocalActor, |
164 | getLocalVideoViewActivityPubUrl, | |
165 | getVideoDislikeActivityPubUrlByLocalActor, | |
166 | getLocalActorFollowRejectActivityPubUrl, | |
46531a0a | 167 | getDeleteActivityPubUrl, |
de94ac86 C |
168 | getLocalVideoSharesActivityPubUrl, |
169 | getLocalVideoCommentsActivityPubUrl, | |
170 | getLocalVideoLikesActivityPubUrl, | |
d26836cd | 171 | getLocalVideoDislikesActivityPubUrl, |
b2111066 | 172 | getLocalVideoViewerActivityPubUrl, |
7e98a7df C |
173 | |
174 | getAbuseTargetUrl, | |
175 | checkUrlsSameHost, | |
176 | buildRemoteVideoBaseUrl | |
892211e8 | 177 | } |