X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Furl.ts;h=6290af34ba91c5ecb399c07b6b521b05cefc6a98;hb=134cf2bce96a8c5aefd55154e884964975d8cf23;hp=729bb8dda446a8376a2a2be10e548eebdc83261e;hpb=bf1f650817dadfd5eeee9e5e0b6b6938c136e25d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts index 729bb8dda..6290af34b 100644 --- a/server/lib/activitypub/url.ts +++ b/server/lib/activitypub/url.ts @@ -1,58 +1,106 @@ -import { CONFIG } from '../../initializers' -import { ActorModel } from '../../models/activitypub/actor' -import { ActorFollowModel } from '../../models/activitypub/actor-follow' -import { VideoModel } from '../../models/video/video' -import { VideoAbuseModel } from '../../models/video/video-abuse' -import { VideoCommentModel } from '../../models/video/video-comment' +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: MVideoUUID) { + return WEBSERVER.URL + '/videos/watch/' + video.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 getVideoActivityPubUrl (video: VideoModel) { - return CONFIG.WEBSERVER.URL + '/videos/watch/' + 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: VideoModel, videoComment: VideoCommentModel) { - return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid + '#comment-' + videoComment.id +function getVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) { + return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id } -function getVideoChannelActivityPubUrl (videoChannelUUID: string) { - return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannelUUID +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: VideoAbuseModel) { - return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id +function getVideoAbuseActivityPubUrl (videoAbuse: MVideoAbuseId) { + return WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id } -function getVideoViewActivityPubUrl (byActor: ActorModel, video: VideoModel) { - return video.url + '/views/' + byActor.uuid + '/' + new Date().toISOString() +function getVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) { + return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString() } -function getVideoLikeActivityPubUrl (byActor: ActorModel, video: VideoModel) { +function getVideoLikeActivityPubUrl (byActor: MActorUrl, video: MVideoId) { return byActor.url + '/likes/' + video.id } -function getVideoDislikeActivityPubUrl (byActor: ActorModel, video: VideoModel) { +function getVideoDislikeActivityPubUrl (byActor: MActorUrl, video: MVideoId) { return byActor.url + '/dislikes/' + video.id } -function getActorFollowActivityPubUrl (actorFollow: ActorFollowModel) { - const me = actorFollow.ActorFollower - const following = actorFollow.ActorFollowing +function getVideoSharesActivityPubUrl (video: MVideoUrl) { + return video.url + '/announces' +} - return me.url + '/follows/' + following.id +function getVideoCommentsActivityPubUrl (video: MVideoUrl) { + return video.url + '/comments' } -function getActorFollowAcceptActivityPubUrl (actorFollow: ActorFollowModel) { +function getVideoLikesActivityPubUrl (video: MVideoUrl) { + return video.url + '/likes' +} + +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 getAnnounceActivityPubUrl (originalUrl: string, byActor: ActorModel) { - return originalUrl + '/announces/' + byActor.id +function getActorFollowRejectActivityPubUrl (follower: MActorUrl, following: MActorId) { + return follower.url + '/rejects/follows/' + following.id +} + +function getVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) { + return video.url + '/announces/' + byActor.id +} + +function getDeleteActivityPubUrl (originalUrl: string) { + return originalUrl + '/delete' } function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) { @@ -65,16 +113,26 @@ function getUndoActivityPubUrl (originalUrl: string) { export { getVideoActivityPubUrl, + getVideoPlaylistElementActivityPubUrl, + getVideoPlaylistActivityPubUrl, + getVideoCacheStreamingPlaylistActivityPubUrl, getVideoChannelActivityPubUrl, getAccountActivityPubUrl, getVideoAbuseActivityPubUrl, getActorFollowActivityPubUrl, getActorFollowAcceptActivityPubUrl, - getAnnounceActivityPubUrl, + getVideoAnnounceActivityPubUrl, getUpdateActivityPubUrl, getUndoActivityPubUrl, getVideoViewActivityPubUrl, getVideoLikeActivityPubUrl, getVideoDislikeActivityPubUrl, - getVideoCommentActivityPubUrl + getActorFollowRejectActivityPubUrl, + getVideoCommentActivityPubUrl, + getDeleteActivityPubUrl, + getVideoSharesActivityPubUrl, + getVideoCommentsActivityPubUrl, + getVideoLikesActivityPubUrl, + getVideoDislikesActivityPubUrl, + getVideoCacheFileActivityPubUrl }