]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/url.ts
Add live autostart/messages in embed
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / url.ts
index 338398f2b0bf37cb88e4aad5c63d4d828c69d7c6..2f68f7a17017d8925d7454c47c176835bddb8d4f 100644 (file)
@@ -1,4 +1,4 @@
-import { WEBSERVER } from '../../initializers/constants'
+import { REMOTE_SCHEME, WEBSERVER } from '../../initializers/constants'
 import {
   MAbuseFull,
   MAbuseId,
@@ -7,10 +7,12 @@ import {
   MActorId,
   MActorUrl,
   MCommentId,
+  MLocalVideoViewer,
   MVideoId,
   MVideoPlaylistElement,
   MVideoUrl,
-  MVideoUUID
+  MVideoUUID,
+  MVideoWithHost
 } from '../../types/models'
 import { MVideoFileVideoUUID } from '../../types/models/video/video-file'
 import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist'
@@ -54,8 +56,12 @@ function getLocalAbuseActivityPubUrl (abuse: MAbuseId) {
   return WEBSERVER.URL + '/admin/abuses/' + abuse.id
 }
 
-function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) {
-  return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString()
+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) {
@@ -121,6 +127,27 @@ function getAbuseTargetUrl (abuse: MAbuseFull) {
     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,
@@ -145,5 +172,9 @@ export {
   getLocalVideoCommentsActivityPubUrl,
   getLocalVideoLikesActivityPubUrl,
   getLocalVideoDislikesActivityPubUrl,
-  getAbuseTargetUrl
+  getLocalVideoViewerActivityPubUrl,
+
+  getAbuseTargetUrl,
+  checkUrlsSameHost,
+  buildRemoteVideoBaseUrl
 }