aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/url.ts
blob: 5cdac71bf0248053c46ab78d4e4ca92716837bc8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import { REMOTE_SCHEME, WEBSERVER } from '../../initializers/constants'
import {
  MAbuseFull,
  MAbuseId,
  MActor,
  MActorFollow,
  MActorId,
  MActorUrl,
  MCommentId,
  MLocalVideoViewer,
  MVideoId,
  MVideoPlaylistElement,
  MVideoUrl,
  MVideoUUID,
  MVideoWithHost
} from '../../types/models'
import { MVideoFileVideoUUID } from '../../types/models/video/video-file'
import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist'
import { MStreamingPlaylist } from '../../types/models/video/video-streaming-playlist'

function getLocalVideoActivityPubUrl (video: MVideoUUID) {
  return WEBSERVER.URL + '/videos/watch/' + video.uuid
}

function getLocalVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) {
  return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid
}

function getLocalVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) {
  return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id
}

function getLocalVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) {
  const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : ''

  return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}`
}

function getLocalVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) {
  return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}`
}

function getLocalVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) {
  return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
}

function getLocalVideoChannelActivityPubUrl (videoChannelName: string) {
  return WEBSERVER.URL + '/video-channels/' + videoChannelName
}

function getLocalAccountActivityPubUrl (accountName: string) {
  return WEBSERVER.URL + '/accounts/' + accountName
}

function getLocalAbuseActivityPubUrl (abuse: MAbuseId) {
  return WEBSERVER.URL + '/admin/abuses/' + abuse.id
}

function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId, viewerIdentifier: string) {
  return byActor.url + '/views/videos/' + video.id + '/' + viewerIdentifier
}

function getLocalVideoViewerActivityPubUrl (stats: MLocalVideoViewer) {
  return WEBSERVER.URL + '/videos/local-viewer/' + stats.uuid
}

function getVideoLikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
  return byActor.url + '/likes/' + video.id
}

function getVideoDislikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
  return byActor.url + '/dislikes/' + video.id
}

function getLocalVideoSharesActivityPubUrl (video: MVideoUrl) {
  return video.url + '/announces'
}

function getLocalVideoCommentsActivityPubUrl (video: MVideoUrl) {
  return video.url + '/comments'
}

function getLocalVideoLikesActivityPubUrl (video: MVideoUrl) {
  return video.url + '/likes'
}

function getLocalVideoDislikesActivityPubUrl (video: MVideoUrl) {
  return video.url + '/dislikes'
}

function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorId) {
  return follower.url + '/follows/' + following.id
}

function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollow) {
  return WEBSERVER.URL + '/accepts/follows/' + actorFollow.id
}

function getLocalActorFollowRejectActivityPubUrl () {
  return WEBSERVER.URL + '/rejects/follows/' + new Date().toISOString()
}

function getLocalVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) {
  return video.url + '/announces/' + byActor.id
}

function getDeleteActivityPubUrl (originalUrl: string) {
  return originalUrl + '/delete'
}

function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
  return originalUrl + '/updates/' + updatedAt
}

function getUndoActivityPubUrl (originalUrl: string) {
  return originalUrl + '/undo'
}

// ---------------------------------------------------------------------------

function getAbuseTargetUrl (abuse: MAbuseFull) {
  return abuse.VideoAbuse?.Video?.url ||
    abuse.VideoCommentAbuse?.VideoComment?.url ||
    abuse.FlaggedAccount.Actor.url
}

// ---------------------------------------------------------------------------

function buildRemoteVideoBaseUrl (video: MVideoWithHost, path: string, scheme?: string) {
  if (!scheme) scheme = REMOTE_SCHEME.HTTP

  const host = video.VideoChannel.Actor.Server.host

  return scheme + '://' + host + path
}

// ---------------------------------------------------------------------------

function checkUrlsSameHost (url1: string, url2: string) {
  const idHost = new URL(url1).host
  const actorHost = new URL(url2).host

  return idHost && actorHost && idHost.toLowerCase() === actorHost.toLowerCase()
}

// ---------------------------------------------------------------------------

export {
  getLocalVideoActivityPubUrl,
  getLocalVideoPlaylistActivityPubUrl,
  getLocalVideoPlaylistElementActivityPubUrl,
  getLocalVideoCacheFileActivityPubUrl,
  getLocalVideoCacheStreamingPlaylistActivityPubUrl,
  getLocalVideoCommentActivityPubUrl,
  getLocalVideoChannelActivityPubUrl,
  getLocalAccountActivityPubUrl,
  getLocalAbuseActivityPubUrl,
  getLocalActorFollowActivityPubUrl,
  getLocalActorFollowAcceptActivityPubUrl,
  getLocalVideoAnnounceActivityPubUrl,
  getUpdateActivityPubUrl,
  getUndoActivityPubUrl,
  getVideoLikeActivityPubUrlByLocalActor,
  getLocalVideoViewActivityPubUrl,
  getVideoDislikeActivityPubUrlByLocalActor,
  getLocalActorFollowRejectActivityPubUrl,
  getDeleteActivityPubUrl,
  getLocalVideoSharesActivityPubUrl,
  getLocalVideoCommentsActivityPubUrl,
  getLocalVideoLikesActivityPubUrl,
  getLocalVideoDislikesActivityPubUrl,
  getLocalVideoViewerActivityPubUrl,

  getAbuseTargetUrl,
  checkUrlsSameHost,
  buildRemoteVideoBaseUrl
}