1 import { REMOTE_SCHEME, WEBSERVER } from '../../initializers/constants'
12 MVideoPlaylistElement,
16 } from '../../types/models'
17 import { MVideoFileVideoUUID } from '../../types/models/video/video-file'
18 import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist'
19 import { MStreamingPlaylist } from '../../types/models/video/video-streaming-playlist'
21 function getLocalVideoActivityPubUrl (video: MVideoUUID) {
22 return WEBSERVER.URL + '/videos/watch/' + video.uuid
25 function getLocalVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) {
26 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid
29 function getLocalVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) {
30 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id
33 function getLocalVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) {
34 const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : ''
36 return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}`
39 function getLocalVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) {
40 return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}`
43 function getLocalVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) {
44 return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
47 function getLocalVideoChannelActivityPubUrl (videoChannelName: string) {
48 return WEBSERVER.URL + '/video-channels/' + videoChannelName
51 function getLocalAccountActivityPubUrl (accountName: string) {
52 return WEBSERVER.URL + '/accounts/' + accountName
55 function getLocalAbuseActivityPubUrl (abuse: MAbuseId) {
56 return WEBSERVER.URL + '/admin/abuses/' + abuse.id
59 function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId, viewerIdentifier: string) {
60 return byActor.url + '/views/videos/' + video.id + '/' + viewerIdentifier
63 function getLocalVideoViewerActivityPubUrl (stats: MLocalVideoViewer) {
64 return WEBSERVER.URL + '/videos/local-viewer/' + stats.uuid
67 function getVideoLikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
68 return byActor.url + '/likes/' + video.id
71 function getVideoDislikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
72 return byActor.url + '/dislikes/' + video.id
75 function getLocalVideoSharesActivityPubUrl (video: MVideoUrl) {
76 return video.url + '/announces'
79 function getLocalVideoCommentsActivityPubUrl (video: MVideoUrl) {
80 return video.url + '/comments'
83 function getLocalVideoLikesActivityPubUrl (video: MVideoUrl) {
84 return video.url + '/likes'
87 function getLocalVideoDislikesActivityPubUrl (video: MVideoUrl) {
88 return video.url + '/dislikes'
91 function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorId) {
92 return follower.url + '/follows/' + following.id
95 function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollow) {
96 return WEBSERVER.URL + '/accepts/follows/' + actorFollow.id
99 function getLocalActorFollowRejectActivityPubUrl () {
100 return WEBSERVER.URL + '/rejects/follows/' + new Date().toISOString()
103 function getLocalVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) {
104 return video.url + '/announces/' + byActor.id
107 function getDeleteActivityPubUrl (originalUrl: string) {
108 return originalUrl + '/delete'
111 function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
112 return originalUrl + '/updates/' + updatedAt
115 function getUndoActivityPubUrl (originalUrl: string) {
116 return originalUrl + '/undo'
119 // ---------------------------------------------------------------------------
121 function getAbuseTargetUrl (abuse: MAbuseFull) {
122 return abuse.VideoAbuse?.Video?.url ||
123 abuse.VideoCommentAbuse?.VideoComment?.url ||
124 abuse.FlaggedAccount.Actor.url
127 // ---------------------------------------------------------------------------
129 function buildRemoteVideoBaseUrl (video: MVideoWithHost, path: string, scheme?: string) {
130 if (!scheme) scheme = REMOTE_SCHEME.HTTP
132 const host = video.VideoChannel.Actor.Server.host
134 return scheme + '://' + host + path
137 // ---------------------------------------------------------------------------
139 function checkUrlsSameHost (url1: string, url2: string) {
140 const idHost = new URL(url1).host
141 const actorHost = new URL(url2).host
143 return idHost && actorHost && idHost.toLowerCase() === actorHost.toLowerCase()
146 // ---------------------------------------------------------------------------
149 getLocalVideoActivityPubUrl,
150 getLocalVideoPlaylistActivityPubUrl,
151 getLocalVideoPlaylistElementActivityPubUrl,
152 getLocalVideoCacheFileActivityPubUrl,
153 getLocalVideoCacheStreamingPlaylistActivityPubUrl,
154 getLocalVideoCommentActivityPubUrl,
155 getLocalVideoChannelActivityPubUrl,
156 getLocalAccountActivityPubUrl,
157 getLocalAbuseActivityPubUrl,
158 getLocalActorFollowActivityPubUrl,
159 getLocalActorFollowAcceptActivityPubUrl,
160 getLocalVideoAnnounceActivityPubUrl,
161 getUpdateActivityPubUrl,
162 getUndoActivityPubUrl,
163 getVideoLikeActivityPubUrlByLocalActor,
164 getLocalVideoViewActivityPubUrl,
165 getVideoDislikeActivityPubUrlByLocalActor,
166 getLocalActorFollowRejectActivityPubUrl,
167 getDeleteActivityPubUrl,
168 getLocalVideoSharesActivityPubUrl,
169 getLocalVideoCommentsActivityPubUrl,
170 getLocalVideoLikesActivityPubUrl,
171 getLocalVideoDislikesActivityPubUrl,
172 getLocalVideoViewerActivityPubUrl,
176 buildRemoteVideoBaseUrl