]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/url.ts
Prevent duplicated HLS playlist on transcoding
[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,
b2111066 10 MLocalVideoViewer,
453e83ea 11 MVideoId,
de94ac86 12 MVideoPlaylistElement,
453e83ea 13 MVideoUrl,
7e98a7df
C
14 MVideoUUID,
15 MVideoWithHost
26d6bf65 16} from '../../types/models'
26d6bf65 17import { MVideoFileVideoUUID } from '../../types/models/video/video-file'
de94ac86 18import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist'
26d6bf65 19import { MStreamingPlaylist } from '../../types/models/video/video-streaming-playlist'
453e83ea 20
de94ac86 21function getLocalVideoActivityPubUrl (video: MVideoUUID) {
6dd9de95 22 return WEBSERVER.URL + '/videos/watch/' + video.uuid
892211e8
C
23}
24
de94ac86 25function getLocalVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) {
6dd9de95 26 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid
418d092a
C
27}
28
de94ac86 29function getLocalVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) {
37190663 30 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id
418d092a
C
31}
32
de94ac86 33function 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 39function getLocalVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) {
6dd9de95 40 return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}`
09209296
C
41}
42
de94ac86 43function getLocalVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) {
6dd9de95 44 return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
50d6de9c
C
45}
46
de94ac86 47function getLocalVideoChannelActivityPubUrl (videoChannelName: string) {
6dd9de95 48 return WEBSERVER.URL + '/video-channels/' + videoChannelName
892211e8
C
49}
50
de94ac86 51function getLocalAccountActivityPubUrl (accountName: string) {
6dd9de95 52 return WEBSERVER.URL + '/accounts/' + accountName
892211e8
C
53}
54
de94ac86 55function getLocalAbuseActivityPubUrl (abuse: MAbuseId) {
d95d1559 56 return WEBSERVER.URL + '/admin/abuses/' + abuse.id
892211e8
C
57}
58
ac907dc7
C
59function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId, viewerIdentifier: string) {
60 return byActor.url + '/views/videos/' + video.id + '/' + viewerIdentifier
40ff5707
C
61}
62
b2111066
C
63function getLocalVideoViewerActivityPubUrl (stats: MLocalVideoViewer) {
64 return WEBSERVER.URL + '/videos/local-viewer/' + stats.uuid
65}
66
de94ac86 67function getVideoLikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
50d6de9c 68 return byActor.url + '/likes/' + video.id
0032ebe9
C
69}
70
de94ac86 71function getVideoDislikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
50d6de9c 72 return byActor.url + '/dislikes/' + video.id
0032ebe9
C
73}
74
de94ac86 75function getLocalVideoSharesActivityPubUrl (video: MVideoUrl) {
46531a0a
C
76 return video.url + '/announces'
77}
78
de94ac86 79function getLocalVideoCommentsActivityPubUrl (video: MVideoUrl) {
46531a0a
C
80 return video.url + '/comments'
81}
82
de94ac86 83function getLocalVideoLikesActivityPubUrl (video: MVideoUrl) {
46531a0a
C
84 return video.url + '/likes'
85}
86
de94ac86 87function getLocalVideoDislikesActivityPubUrl (video: MVideoUrl) {
46531a0a
C
88 return video.url + '/dislikes'
89}
90
de94ac86 91function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorId) {
5b9c965d 92 return follower.url + '/follows/' + following.id
892211e8
C
93}
94
de94ac86 95function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollowActors) {
50d6de9c
C
96 const follower = actorFollow.ActorFollower
97 const me = actorFollow.ActorFollowing
892211e8 98
de94ac86 99 return WEBSERVER.URL + '/accepts/follows/' + follower.id + '/' + me.id
892211e8
C
100}
101
de94ac86
C
102function getLocalActorFollowRejectActivityPubUrl (follower: MActorId, following: MActorId) {
103 return WEBSERVER.URL + '/rejects/follows/' + follower.id + '/' + following.id
5b9c965d
C
104}
105
de94ac86 106function getLocalVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) {
5c6d985f 107 return video.url + '/announces/' + byActor.id
892211e8
C
108}
109
c3badc81
C
110function getDeleteActivityPubUrl (originalUrl: string) {
111 return originalUrl + '/delete'
112}
113
892211e8 114function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
4e50b6a1 115 return originalUrl + '/updates/' + updatedAt
892211e8
C
116}
117
118function getUndoActivityPubUrl (originalUrl: string) {
119 return originalUrl + '/undo'
120}
121
d26836cd
C
122// ---------------------------------------------------------------------------
123
124function getAbuseTargetUrl (abuse: MAbuseFull) {
125 return abuse.VideoAbuse?.Video?.url ||
126 abuse.VideoCommentAbuse?.VideoComment?.url ||
127 abuse.FlaggedAccount.Actor.url
128}
129
7e98a7df
C
130// ---------------------------------------------------------------------------
131
132function 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
142function 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
892211e8 151export {
de94ac86
C
152 getLocalVideoActivityPubUrl,
153 getLocalVideoPlaylistActivityPubUrl,
154 getLocalVideoPlaylistElementActivityPubUrl,
155 getLocalVideoCacheFileActivityPubUrl,
156 getLocalVideoCacheStreamingPlaylistActivityPubUrl,
157 getLocalVideoCommentActivityPubUrl,
158 getLocalVideoChannelActivityPubUrl,
159 getLocalAccountActivityPubUrl,
160 getLocalAbuseActivityPubUrl,
161 getLocalActorFollowActivityPubUrl,
162 getLocalActorFollowAcceptActivityPubUrl,
163 getLocalVideoAnnounceActivityPubUrl,
892211e8 164 getUpdateActivityPubUrl,
40ff5707 165 getUndoActivityPubUrl,
de94ac86
C
166 getVideoLikeActivityPubUrlByLocalActor,
167 getLocalVideoViewActivityPubUrl,
168 getVideoDislikeActivityPubUrlByLocalActor,
169 getLocalActorFollowRejectActivityPubUrl,
46531a0a 170 getDeleteActivityPubUrl,
de94ac86
C
171 getLocalVideoSharesActivityPubUrl,
172 getLocalVideoCommentsActivityPubUrl,
173 getLocalVideoLikesActivityPubUrl,
d26836cd 174 getLocalVideoDislikesActivityPubUrl,
b2111066 175 getLocalVideoViewerActivityPubUrl,
7e98a7df
C
176
177 getAbuseTargetUrl,
178 checkUrlsSameHost,
179 buildRemoteVideoBaseUrl
892211e8 180}