X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Furl.ts;h=7816b0be081a834e4a9ae1deb9f2467cff4ec99e;hb=d4a8e7a65f97bb3257facc13e1ae8ffdbad61ddb;hp=00bbbba2ddf3ffca48d13bd48ff29c572bf5d2ba;hpb=418d092afa81e2c8fe8ac6838fc4b5eb0af6a782;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts index 00bbbba2d..7816b0be0 100644 --- a/server/lib/activitypub/url.ts +++ b/server/lib/activitypub/url.ts @@ -1,96 +1,102 @@ -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 { VideoFileModel } from '../../models/video/video-file' -import { VideoStreamingPlaylist } from '../../../shared/models/videos/video-streaming-playlist.model' -import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist' -import { VideoPlaylistModel } from '../../models/video/video-playlist' -import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element' +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: VideoModel) { - return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid +function getLocalVideoActivityPubUrl (video: MVideoUUID) { + return WEBSERVER.URL + '/videos/watch/' + video.uuid } -function getVideoPlaylistActivityPubUrl (videoPlaylist: VideoPlaylistModel) { - return CONFIG.WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid +function getLocalVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) { + return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid } -function getVideoPlaylistElementActivityPubUrl (videoPlaylist: VideoPlaylistModel, video: VideoModel) { - return CONFIG.WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/' + video.uuid +function getLocalVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) { + return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id } -function getVideoCacheFileActivityPubUrl (videoFile: VideoFileModel) { +function getLocalVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) { const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : '' - return `${CONFIG.WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}` + return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}` } -function getVideoCacheStreamingPlaylistActivityPubUrl (video: VideoModel, playlist: VideoStreamingPlaylistModel) { - return `${CONFIG.WEBSERVER.URL}/redundancy/video-playlists/${playlist.getStringType()}/${video.uuid}` +function getLocalVideoCacheStreamingPlaylistActivityPubUrl (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 + '/comments/' + videoComment.id +function getLocalVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) { + return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id } -function getVideoChannelActivityPubUrl (videoChannelName: string) { - return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannelName +function getLocalVideoChannelActivityPubUrl (videoChannelName: string) { + return WEBSERVER.URL + '/video-channels/' + videoChannelName } -function getAccountActivityPubUrl (accountName: string) { - return CONFIG.WEBSERVER.URL + '/accounts/' + accountName +function getLocalAccountActivityPubUrl (accountName: string) { + return WEBSERVER.URL + '/accounts/' + accountName } -function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseModel) { - return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id +function getLocalAbuseActivityPubUrl (abuse: MAbuseId) { + return WEBSERVER.URL + '/admin/abuses/' + abuse.id } -function getVideoViewActivityPubUrl (byActor: ActorModel, video: VideoModel) { +function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) { return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString() } -function getVideoLikeActivityPubUrl (byActor: ActorModel, video: VideoModel | { id: number }) { +function getVideoLikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) { return byActor.url + '/likes/' + video.id } -function getVideoDislikeActivityPubUrl (byActor: ActorModel, video: VideoModel | { id: number }) { +function getVideoDislikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) { return byActor.url + '/dislikes/' + video.id } -function getVideoSharesActivityPubUrl (video: VideoModel) { +function getLocalVideoSharesActivityPubUrl (video: MVideoUrl) { return video.url + '/announces' } -function getVideoCommentsActivityPubUrl (video: VideoModel) { +function getLocalVideoCommentsActivityPubUrl (video: MVideoUrl) { return video.url + '/comments' } -function getVideoLikesActivityPubUrl (video: VideoModel) { +function getLocalVideoLikesActivityPubUrl (video: MVideoUrl) { return video.url + '/likes' } -function getVideoDislikesActivityPubUrl (video: VideoModel) { +function getLocalVideoDislikesActivityPubUrl (video: MVideoUrl) { return video.url + '/dislikes' } -function getActorFollowActivityPubUrl (actorFollow: ActorFollowModel) { - const me = actorFollow.ActorFollower - const following = actorFollow.ActorFollowing - - return me.url + '/follows/' + following.id +function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorId) { + return follower.url + '/follows/' + following.id } -function getActorFollowAcceptActivityPubUrl (actorFollow: ActorFollowModel) { +function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollowActors) { const follower = actorFollow.ActorFollower const me = actorFollow.ActorFollowing - return follower.url + '/accepts/follows/' + me.id + return WEBSERVER.URL + '/accepts/follows/' + follower.id + '/' + me.id +} + +function getLocalActorFollowRejectActivityPubUrl (follower: MActorId, following: MActorId) { + return WEBSERVER.URL + '/rejects/follows/' + follower.id + '/' + following.id } -function getVideoAnnounceActivityPubUrl (byActor: ActorModel, video: VideoModel) { +function getLocalVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) { return video.url + '/announces/' + byActor.id } @@ -107,26 +113,27 @@ function getUndoActivityPubUrl (originalUrl: string) { } export { - getVideoActivityPubUrl, - getVideoPlaylistElementActivityPubUrl, - getVideoPlaylistActivityPubUrl, - getVideoCacheStreamingPlaylistActivityPubUrl, - getVideoChannelActivityPubUrl, - getAccountActivityPubUrl, - getVideoAbuseActivityPubUrl, - getActorFollowActivityPubUrl, - getActorFollowAcceptActivityPubUrl, - getVideoAnnounceActivityPubUrl, + getLocalVideoActivityPubUrl, + getLocalVideoPlaylistActivityPubUrl, + getLocalVideoPlaylistElementActivityPubUrl, + getLocalVideoCacheFileActivityPubUrl, + getLocalVideoCacheStreamingPlaylistActivityPubUrl, + getLocalVideoCommentActivityPubUrl, + getLocalVideoChannelActivityPubUrl, + getLocalAccountActivityPubUrl, + getLocalAbuseActivityPubUrl, + getLocalActorFollowActivityPubUrl, + getLocalActorFollowAcceptActivityPubUrl, + getLocalVideoAnnounceActivityPubUrl, getUpdateActivityPubUrl, getUndoActivityPubUrl, - getVideoViewActivityPubUrl, - getVideoLikeActivityPubUrl, - getVideoDislikeActivityPubUrl, - getVideoCommentActivityPubUrl, + getVideoLikeActivityPubUrlByLocalActor, + getLocalVideoViewActivityPubUrl, + getVideoDislikeActivityPubUrlByLocalActor, + getLocalActorFollowRejectActivityPubUrl, getDeleteActivityPubUrl, - getVideoSharesActivityPubUrl, - getVideoCommentsActivityPubUrl, - getVideoLikesActivityPubUrl, - getVideoDislikesActivityPubUrl, - getVideoCacheFileActivityPubUrl + getLocalVideoSharesActivityPubUrl, + getLocalVideoCommentsActivityPubUrl, + getLocalVideoLikesActivityPubUrl, + getLocalVideoDislikesActivityPubUrl }