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