]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/url.ts
feature/ability to disable video history by default (#5728)
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / url.ts
index 7816b0be081a834e4a9ae1deb9f2467cff4ec99e..5cdac71bf0248053c46ab78d4e4ca92716837bc8 100644 (file)
@@ -1,15 +1,18 @@
-import { WEBSERVER } from '../../initializers/constants'
+import { REMOTE_SCHEME, WEBSERVER } from '../../initializers/constants'
 import {
+  MAbuseFull,
   MAbuseId,
   MActor,
-  MActorFollowActors,
+  MActorFollow,
   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'
@@ -53,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) {
@@ -85,15 +92,12 @@ function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorI
   return follower.url + '/follows/' + following.id
 }
 
-function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollowActors) {
-  const follower = actorFollow.ActorFollower
-  const me = actorFollow.ActorFollowing
-
-  return WEBSERVER.URL + '/accepts/follows/' + follower.id + '/' + me.id
+function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollow) {
+  return WEBSERVER.URL + '/accepts/follows/' + actorFollow.id
 }
 
-function getLocalActorFollowRejectActivityPubUrl (follower: MActorId, following: MActorId) {
-  return WEBSERVER.URL + '/rejects/follows/' + follower.id + '/' + following.id
+function getLocalActorFollowRejectActivityPubUrl () {
+  return WEBSERVER.URL + '/rejects/follows/' + new Date().toISOString()
 }
 
 function getLocalVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) {
@@ -112,6 +116,35 @@ 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,
@@ -135,5 +168,10 @@ export {
   getLocalVideoSharesActivityPubUrl,
   getLocalVideoCommentsActivityPubUrl,
   getLocalVideoLikesActivityPubUrl,
-  getLocalVideoDislikesActivityPubUrl
+  getLocalVideoDislikesActivityPubUrl,
+  getLocalVideoViewerActivityPubUrl,
+
+  getAbuseTargetUrl,
+  checkUrlsSameHost,
+  buildRemoteVideoBaseUrl
 }