1 import { REMOTE_SCHEME, WEBSERVER } from '../../initializers/constants'
11 MVideoPlaylistElement,
15 } from '../../types/models'
16 import { MVideoFileVideoUUID } from '../../types/models/video/video-file'
17 import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist'
18 import { MStreamingPlaylist } from '../../types/models/video/video-streaming-playlist'
20 function getLocalVideoActivityPubUrl (video: MVideoUUID) {
21 return WEBSERVER.URL + '/videos/watch/' + video.uuid
24 function getLocalVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) {
25 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid
28 function getLocalVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) {
29 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id
32 function getLocalVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) {
33 const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : ''
35 return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}`
38 function getLocalVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) {
39 return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}`
42 function getLocalVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) {
43 return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
46 function getLocalVideoChannelActivityPubUrl (videoChannelName: string) {
47 return WEBSERVER.URL + '/video-channels/' + videoChannelName
50 function getLocalAccountActivityPubUrl (accountName: string) {
51 return WEBSERVER.URL + '/accounts/' + accountName
54 function getLocalAbuseActivityPubUrl (abuse: MAbuseId) {
55 return WEBSERVER.URL + '/admin/abuses/' + abuse.id
58 function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) {
59 return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString()
62 function getVideoLikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
63 return byActor.url + '/likes/' + video.id
66 function getVideoDislikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
67 return byActor.url + '/dislikes/' + video.id
70 function getLocalVideoSharesActivityPubUrl (video: MVideoUrl) {
71 return video.url + '/announces'
74 function getLocalVideoCommentsActivityPubUrl (video: MVideoUrl) {
75 return video.url + '/comments'
78 function getLocalVideoLikesActivityPubUrl (video: MVideoUrl) {
79 return video.url + '/likes'
82 function getLocalVideoDislikesActivityPubUrl (video: MVideoUrl) {
83 return video.url + '/dislikes'
86 function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorId) {
87 return follower.url + '/follows/' + following.id
90 function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollowActors) {
91 const follower = actorFollow.ActorFollower
92 const me = actorFollow.ActorFollowing
94 return WEBSERVER.URL + '/accepts/follows/' + follower.id + '/' + me.id
97 function getLocalActorFollowRejectActivityPubUrl (follower: MActorId, following: MActorId) {
98 return WEBSERVER.URL + '/rejects/follows/' + follower.id + '/' + following.id
101 function getLocalVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) {
102 return video.url + '/announces/' + byActor.id
105 function getDeleteActivityPubUrl (originalUrl: string) {
106 return originalUrl + '/delete'
109 function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
110 return originalUrl + '/updates/' + updatedAt
113 function getUndoActivityPubUrl (originalUrl: string) {
114 return originalUrl + '/undo'
117 // ---------------------------------------------------------------------------
119 function getAbuseTargetUrl (abuse: MAbuseFull) {
120 return abuse.VideoAbuse?.Video?.url ||
121 abuse.VideoCommentAbuse?.VideoComment?.url ||
122 abuse.FlaggedAccount.Actor.url
125 // ---------------------------------------------------------------------------
127 function buildRemoteVideoBaseUrl (video: MVideoWithHost, path: string, scheme?: string) {
128 if (!scheme) scheme = REMOTE_SCHEME.HTTP
130 const host = video.VideoChannel.Actor.Server.host
132 return scheme + '://' + host + path
135 // ---------------------------------------------------------------------------
137 function checkUrlsSameHost (url1: string, url2: string) {
138 const idHost = new URL(url1).host
139 const actorHost = new URL(url2).host
141 return idHost && actorHost && idHost.toLowerCase() === actorHost.toLowerCase()
144 // ---------------------------------------------------------------------------
147 getLocalVideoActivityPubUrl,
148 getLocalVideoPlaylistActivityPubUrl,
149 getLocalVideoPlaylistElementActivityPubUrl,
150 getLocalVideoCacheFileActivityPubUrl,
151 getLocalVideoCacheStreamingPlaylistActivityPubUrl,
152 getLocalVideoCommentActivityPubUrl,
153 getLocalVideoChannelActivityPubUrl,
154 getLocalAccountActivityPubUrl,
155 getLocalAbuseActivityPubUrl,
156 getLocalActorFollowActivityPubUrl,
157 getLocalActorFollowAcceptActivityPubUrl,
158 getLocalVideoAnnounceActivityPubUrl,
159 getUpdateActivityPubUrl,
160 getUndoActivityPubUrl,
161 getVideoLikeActivityPubUrlByLocalActor,
162 getLocalVideoViewActivityPubUrl,
163 getVideoDislikeActivityPubUrlByLocalActor,
164 getLocalActorFollowRejectActivityPubUrl,
165 getDeleteActivityPubUrl,
166 getLocalVideoSharesActivityPubUrl,
167 getLocalVideoCommentsActivityPubUrl,
168 getLocalVideoLikesActivityPubUrl,
169 getLocalVideoDislikesActivityPubUrl,
173 buildRemoteVideoBaseUrl