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