X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Furl.ts;h=6290af34ba91c5ecb399c07b6b521b05cefc6a98;hb=0b5c385b4529f3bef8f9523de3f9470ffa58f5f5;hp=17395a99b81291d091877fbc2ad48741a9bd5e57;hpb=0032ebe94aa83fab761c7de3ceb6210ac4532824;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts index 17395a99b..6290af34b 100644 --- a/server/lib/activitypub/url.ts +++ b/server/lib/activitypub/url.ts @@ -1,58 +1,110 @@ -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: VideoAbuseInstance) { - return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id +function getVideoAbuseActivityPubUrl (videoAbuse: MVideoAbuseId) { + return WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id } -function getVideoViewActivityPubUrl (byAccount: AccountInstance, video: VideoInstance) { - return video.url + '#views/' + byAccount.uuid + '/' + new Date().toISOString() +function getVideoViewActivityPubUrl (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 getVideoLikeActivityPubUrl (byActor: MActorUrl, video: MVideoId) { + return byActor.url + '/likes/' + video.id } -function getVideoDislikeActivityPubUrl (byAccount: AccountInstance, video: VideoInstance) { - return byAccount.url + '#dislikes/' + video.id +function getVideoDislikeActivityPubUrl (byActor: MActorUrl, video: MVideoId) { + return byActor.url + '/dislikes/' + video.id } -function getAccountFollowActivityPubUrl (accountFollow: AccountFollowInstance) { - const me = accountFollow.AccountFollower - const following = accountFollow.AccountFollowing +function getVideoSharesActivityPubUrl (video: MVideoUrl) { + return video.url + '/announces' +} + +function getVideoCommentsActivityPubUrl (video: MVideoUrl) { + return video.url + '/comments' +} - return me.url + '#follows/' + following.id +function getVideoLikesActivityPubUrl (video: MVideoUrl) { + return video.url + '/likes' } -function getAccountFollowAcceptActivityPubUrl (accountFollow: AccountFollowInstance) { - const follower = accountFollow.AccountFollower - const me = accountFollow.AccountFollowing +function getVideoDislikesActivityPubUrl (video: MVideoUrl) { + return video.url + '/dislikes' +} + +function getActorFollowActivityPubUrl (follower: MActor, following: MActorId) { + return follower.url + '/follows/' + following.id +} + +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) { @@ -61,15 +113,26 @@ function getUndoActivityPubUrl (originalUrl: string) { export { getVideoActivityPubUrl, + getVideoPlaylistElementActivityPubUrl, + getVideoPlaylistActivityPubUrl, + getVideoCacheStreamingPlaylistActivityPubUrl, getVideoChannelActivityPubUrl, getAccountActivityPubUrl, getVideoAbuseActivityPubUrl, - getAccountFollowActivityPubUrl, - getAccountFollowAcceptActivityPubUrl, - getAnnounceActivityPubUrl, + getActorFollowActivityPubUrl, + getActorFollowAcceptActivityPubUrl, + getVideoAnnounceActivityPubUrl, getUpdateActivityPubUrl, getUndoActivityPubUrl, getVideoViewActivityPubUrl, getVideoLikeActivityPubUrl, - getVideoDislikeActivityPubUrl + getVideoDislikeActivityPubUrl, + getActorFollowRejectActivityPubUrl, + getVideoCommentActivityPubUrl, + getDeleteActivityPubUrl, + getVideoSharesActivityPubUrl, + getVideoCommentsActivityPubUrl, + getVideoLikesActivityPubUrl, + getVideoDislikesActivityPubUrl, + getVideoCacheFileActivityPubUrl }