]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/url.ts
Handle reports from mastodon
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / url.ts
index 41ac0f9a8c0e9ecc41dc6278614b9cdb86639079..6290af34ba91c5ecb399c07b6b521b05cefc6a98 100644 (file)
-import { CONFIG } from '../../initializers/constants'
-import { VideoInstance } from '../../models/video/video-interface'
-import { VideoChannelInstance } from '../../models/video/video-channel-interface'
-import { VideoAbuseInstance } from '../../models/video/video-abuse-interface'
-import { AccountFollowInstance } from '../../models/account/account-follow-interface'
-import { AccountInstance } from '../../models/account/account-interface'
+import { WEBSERVER } from '../../initializers/constants'
+import {
+  MActor,
+  MActorFollowActors,
+  MActorId,
+  MActorUrl,
+  MCommentId,
+  MVideoAbuseId,
+  MVideoId,
+  MVideoUrl,
+  MVideoUUID
+} from '../../typings/models'
+import { MVideoPlaylist, MVideoPlaylistUUID } from '../../typings/models/video/video-playlist'
+import { MVideoFileVideoUUID } from '../../typings/models/video/video-file'
+import { MStreamingPlaylist } from '../../typings/models/video/video-streaming-playlist'
 
-function getVideoActivityPubUrl (video: VideoInstance) {
-  return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid
+function getVideoActivityPubUrl (video: MVideoUUID) {
+  return WEBSERVER.URL + '/videos/watch/' + video.uuid
 }
 
-function getVideoChannelActivityPubUrl (videoChannel: VideoChannelInstance) {
-  return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannel.uuid
+function getVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) {
+  return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid
+}
+
+function getVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, video: MVideoUUID) {
+  return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/' + video.uuid
+}
+
+function getVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) {
+  const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : ''
+
+  return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}`
+}
+
+function getVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) {
+  return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}`
+}
+
+function getVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) {
+  return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
+}
+
+function getVideoChannelActivityPubUrl (videoChannelName: string) {
+  return WEBSERVER.URL + '/video-channels/' + videoChannelName
 }
 
 function getAccountActivityPubUrl (accountName: string) {
-  return CONFIG.WEBSERVER.URL + '/account/' + accountName
+  return WEBSERVER.URL + '/accounts/' + accountName
+}
+
+function getVideoAbuseActivityPubUrl (videoAbuse: MVideoAbuseId) {
+  return WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id
+}
+
+function getVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) {
+  return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString()
+}
+
+function getVideoLikeActivityPubUrl (byActor: MActorUrl, video: MVideoId) {
+  return byActor.url + '/likes/' + video.id
+}
+
+function getVideoDislikeActivityPubUrl (byActor: MActorUrl, video: MVideoId) {
+  return byActor.url + '/dislikes/' + video.id
+}
+
+function getVideoSharesActivityPubUrl (video: MVideoUrl) {
+  return video.url + '/announces'
 }
 
-function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseInstance) {
-  return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id
+function getVideoCommentsActivityPubUrl (video: MVideoUrl) {
+  return video.url + '/comments'
 }
 
-function getAccountFollowActivityPubUrl (accountFollow: AccountFollowInstance) {
-  const me = accountFollow.AccountFollower
-  const following = accountFollow.AccountFollowing
+function getVideoLikesActivityPubUrl (video: MVideoUrl) {
+  return video.url + '/likes'
+}
+
+function getVideoDislikesActivityPubUrl (video: MVideoUrl) {
+  return video.url + '/dislikes'
+}
 
-  return me.url + '#follows/' + following.id
+function getActorFollowActivityPubUrl (follower: MActor, following: MActorId) {
+  return follower.url + '/follows/' + following.id
 }
 
-function getAccountFollowAcceptActivityPubUrl (accountFollow: AccountFollowInstance) {
-  const follower = accountFollow.AccountFollower
-  const me = accountFollow.AccountFollowing
+function getActorFollowAcceptActivityPubUrl (actorFollow: MActorFollowActors) {
+  const follower = actorFollow.ActorFollower
+  const me = actorFollow.ActorFollowing
+
+  return follower.url + '/accepts/follows/' + me.id
+}
+
+function getActorFollowRejectActivityPubUrl (follower: MActorUrl, following: MActorId) {
+  return follower.url + '/rejects/follows/' + following.id
+}
 
-  return follower.url + '#accepts/follows/' + me.id
+function getVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) {
+  return video.url + '/announces/' + byActor.id
 }
 
-function getAnnounceActivityPubUrl (originalUrl: string, byAccount: AccountInstance) {
-  return originalUrl + '#announces/' + byAccount.id
+function getDeleteActivityPubUrl (originalUrl: string) {
+  return originalUrl + '/delete'
 }
 
 function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
-  return originalUrl + '#updates/' + updatedAt
+  return originalUrl + '/updates/' + updatedAt
 }
 
 function getUndoActivityPubUrl (originalUrl: string) {
@@ -49,12 +113,26 @@ function getUndoActivityPubUrl (originalUrl: string) {
 
 export {
   getVideoActivityPubUrl,
+  getVideoPlaylistElementActivityPubUrl,
+  getVideoPlaylistActivityPubUrl,
+  getVideoCacheStreamingPlaylistActivityPubUrl,
   getVideoChannelActivityPubUrl,
   getAccountActivityPubUrl,
   getVideoAbuseActivityPubUrl,
-  getAccountFollowActivityPubUrl,
-  getAccountFollowAcceptActivityPubUrl,
-  getAnnounceActivityPubUrl,
+  getActorFollowActivityPubUrl,
+  getActorFollowAcceptActivityPubUrl,
+  getVideoAnnounceActivityPubUrl,
   getUpdateActivityPubUrl,
-  getUndoActivityPubUrl
+  getUndoActivityPubUrl,
+  getVideoViewActivityPubUrl,
+  getVideoLikeActivityPubUrl,
+  getVideoDislikeActivityPubUrl,
+  getActorFollowRejectActivityPubUrl,
+  getVideoCommentActivityPubUrl,
+  getDeleteActivityPubUrl,
+  getVideoSharesActivityPubUrl,
+  getVideoCommentsActivityPubUrl,
+  getVideoLikesActivityPubUrl,
+  getVideoDislikesActivityPubUrl,
+  getVideoCacheFileActivityPubUrl
 }