X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Furl.ts;h=7816b0be081a834e4a9ae1deb9f2467cff4ec99e;hb=d4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb;hp=6475c4218c3aa412e473656600e61023129e0546;hpb=4e50b6a1c9a3eb261e04ede73241648e6edf21d6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts index 6475c4218..7816b0be0 100644 --- a/server/lib/activitypub/url.ts +++ b/server/lib/activitypub/url.ts @@ -1,54 +1,107 @@ -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 { + MAbuseId, + MActor, + MActorFollowActors, + MActorId, + MActorUrl, + MCommentId, + MVideoId, + MVideoPlaylistElement, + MVideoUrl, + MVideoUUID +} 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 getVideoActivityPubUrl (video: VideoInstance) { - return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid +function getLocalVideoActivityPubUrl (video: MVideoUUID) { + return WEBSERVER.URL + '/videos/watch/' + video.uuid } -function getVideoChannelActivityPubUrl (videoChannel: VideoChannelInstance) { - return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannel.uuid +function getLocalVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) { + return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid } -function getAccountActivityPubUrl (accountName: string) { - return CONFIG.WEBSERVER.URL + '/account/' + accountName +function getLocalVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) { + return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id } -function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseInstance) { - return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.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 getVideoViewActivityPubUrl (byAccount: AccountInstance, video: VideoInstance) { - return video.url + '/views/' + byAccount.uuid + '/' + new Date().toISOString() +function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) { + return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString() } -function getVideoLikeActivityPubUrl (byAccount: AccountInstance, video: VideoInstance) { - return byAccount.url + '/likes/' + video.id +function getVideoLikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) { + return byActor.url + '/likes/' + video.id } -function getVideoDislikeActivityPubUrl (byAccount: AccountInstance, video: VideoInstance) { - return byAccount.url + '/dislikes/' + video.id +function getVideoDislikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) { + return byActor.url + '/dislikes/' + video.id } -function getAccountFollowActivityPubUrl (accountFollow: AccountFollowInstance) { - const me = accountFollow.AccountFollower - const following = accountFollow.AccountFollowing +function getLocalVideoSharesActivityPubUrl (video: MVideoUrl) { + return video.url + '/announces' +} + +function getLocalVideoCommentsActivityPubUrl (video: MVideoUrl) { + return video.url + '/comments' +} - return me.url + '/follows/' + following.id +function getLocalVideoLikesActivityPubUrl (video: MVideoUrl) { + return video.url + '/likes' } -function getAccountFollowAcceptActivityPubUrl (accountFollow: AccountFollowInstance) { - const follower = accountFollow.AccountFollower - const me = accountFollow.AccountFollowing +function getLocalVideoDislikesActivityPubUrl (video: MVideoUrl) { + return video.url + '/dislikes' +} + +function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorId) { + 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 getLocalActorFollowRejectActivityPubUrl (follower: MActorId, following: MActorId) { + return WEBSERVER.URL + '/rejects/follows/' + follower.id + '/' + following.id +} - return follower.url + '/accepts/follows/' + me.id +function getLocalVideoAnnounceActivityPubUrl (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) { @@ -60,16 +113,27 @@ function getUndoActivityPubUrl (originalUrl: string) { } export { - getVideoActivityPubUrl, - getVideoChannelActivityPubUrl, - getAccountActivityPubUrl, - getVideoAbuseActivityPubUrl, - getAccountFollowActivityPubUrl, - getAccountFollowAcceptActivityPubUrl, - getAnnounceActivityPubUrl, + getLocalVideoActivityPubUrl, + getLocalVideoPlaylistActivityPubUrl, + getLocalVideoPlaylistElementActivityPubUrl, + getLocalVideoCacheFileActivityPubUrl, + getLocalVideoCacheStreamingPlaylistActivityPubUrl, + getLocalVideoCommentActivityPubUrl, + getLocalVideoChannelActivityPubUrl, + getLocalAccountActivityPubUrl, + getLocalAbuseActivityPubUrl, + getLocalActorFollowActivityPubUrl, + getLocalActorFollowAcceptActivityPubUrl, + getLocalVideoAnnounceActivityPubUrl, getUpdateActivityPubUrl, getUndoActivityPubUrl, - getVideoViewActivityPubUrl, - getVideoLikeActivityPubUrl, - getVideoDislikeActivityPubUrl + getVideoLikeActivityPubUrlByLocalActor, + getLocalVideoViewActivityPubUrl, + getVideoDislikeActivityPubUrlByLocalActor, + getLocalActorFollowRejectActivityPubUrl, + getDeleteActivityPubUrl, + getLocalVideoSharesActivityPubUrl, + getLocalVideoCommentsActivityPubUrl, + getLocalVideoLikesActivityPubUrl, + getLocalVideoDislikesActivityPubUrl }