1
0
Fork 0
peertube/server/lib/activitypub/url.ts

150 lines
4.9 KiB
TypeScript
Raw Normal View History

import { WEBSERVER } from '../../initializers/constants'
2019-08-15 09:53:26 +00:00
import {
2021-07-30 14:51:27 +00:00
MAbuseFull,
2020-11-20 10:21:08 +00:00
MAbuseId,
2019-08-15 09:53:26 +00:00
MActor,
MActorFollowActors,
MActorId,
MActorUrl,
MCommentId,
MVideoId,
2020-11-20 10:21:08 +00:00
MVideoPlaylistElement,
2019-08-15 09:53:26 +00:00
MVideoUrl,
2020-11-20 10:21:08 +00:00
MVideoUUID
2020-06-18 08:45:25 +00:00
} from '../../types/models'
import { MVideoFileVideoUUID } from '../../types/models/video/video-file'
2020-11-20 10:21:08 +00:00
import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist'
2020-06-18 08:45:25 +00:00
import { MStreamingPlaylist } from '../../types/models/video/video-streaming-playlist'
2019-08-15 09:53:26 +00:00
2020-11-20 10:21:08 +00:00
function getLocalVideoActivityPubUrl (video: MVideoUUID) {
2019-04-11 09:33:44 +00:00
return WEBSERVER.URL + '/videos/watch/' + video.uuid
}
2020-11-20 10:21:08 +00:00
function getLocalVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) {
2019-04-11 09:33:44 +00:00
return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid
2019-02-26 09:55:40 +00:00
}
2020-11-20 10:21:08 +00:00
function getLocalVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) {
return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id
2019-02-26 09:55:40 +00:00
}
2020-11-20 10:21:08 +00:00
function getLocalVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) {
const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : ''
2018-09-11 14:27:07 +00:00
2019-04-11 09:33:44 +00:00
return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}`
2018-09-11 14:27:07 +00:00
}
2020-11-20 10:21:08 +00:00
function getLocalVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) {
2019-04-11 09:33:44 +00:00
return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}`
2019-01-29 07:37:25 +00:00
}
2020-11-20 10:21:08 +00:00
function getLocalVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) {
2019-04-11 09:33:44 +00:00
return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
2017-12-14 16:38:41 +00:00
}
2020-11-20 10:21:08 +00:00
function getLocalVideoChannelActivityPubUrl (videoChannelName: string) {
2019-04-11 09:33:44 +00:00
return WEBSERVER.URL + '/video-channels/' + videoChannelName
}
2020-11-20 10:21:08 +00:00
function getLocalAccountActivityPubUrl (accountName: string) {
2019-04-11 09:33:44 +00:00
return WEBSERVER.URL + '/accounts/' + accountName
}
2020-11-20 10:21:08 +00:00
function getLocalAbuseActivityPubUrl (abuse: MAbuseId) {
2020-07-01 14:05:30 +00:00
return WEBSERVER.URL + '/admin/abuses/' + abuse.id
}
2020-11-20 10:21:08 +00:00
function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) {
2018-11-14 14:01:28 +00:00
return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString()
2017-11-22 15:25:03 +00:00
}
2020-11-20 10:21:08 +00:00
function getVideoLikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
2017-12-14 16:38:41 +00:00
return byActor.url + '/likes/' + video.id
2017-11-23 13:19:55 +00:00
}
2020-11-20 10:21:08 +00:00
function getVideoDislikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
2017-12-14 16:38:41 +00:00
return byActor.url + '/dislikes/' + video.id
2017-11-23 13:19:55 +00:00
}
2020-11-20 10:21:08 +00:00
function getLocalVideoSharesActivityPubUrl (video: MVideoUrl) {
return video.url + '/announces'
}
2020-11-20 10:21:08 +00:00
function getLocalVideoCommentsActivityPubUrl (video: MVideoUrl) {
return video.url + '/comments'
}
2020-11-20 10:21:08 +00:00
function getLocalVideoLikesActivityPubUrl (video: MVideoUrl) {
return video.url + '/likes'
}
2020-11-20 10:21:08 +00:00
function getLocalVideoDislikesActivityPubUrl (video: MVideoUrl) {
return video.url + '/dislikes'
}
2020-11-20 10:21:08 +00:00
function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorId) {
2019-04-08 12:04:57 +00:00
return follower.url + '/follows/' + following.id
}
2020-11-20 10:21:08 +00:00
function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollowActors) {
2017-12-14 16:38:41 +00:00
const follower = actorFollow.ActorFollower
const me = actorFollow.ActorFollowing
2020-11-20 10:21:08 +00:00
return WEBSERVER.URL + '/accepts/follows/' + follower.id + '/' + me.id
}
2020-11-20 10:21:08 +00:00
function getLocalActorFollowRejectActivityPubUrl (follower: MActorId, following: MActorId) {
return WEBSERVER.URL + '/rejects/follows/' + follower.id + '/' + following.id
2019-04-08 12:04:57 +00:00
}
2020-11-20 10:21:08 +00:00
function getLocalVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) {
2018-11-14 14:01:28 +00:00
return video.url + '/announces/' + byActor.id
}
2018-01-04 15:56:36 +00:00
function getDeleteActivityPubUrl (originalUrl: string) {
return originalUrl + '/delete'
}
function getUpdateActivityPubUrl (originalUrl: string, updatedAt: string) {
return originalUrl + '/updates/' + updatedAt
}
function getUndoActivityPubUrl (originalUrl: string) {
return originalUrl + '/undo'
}
2021-07-30 14:51:27 +00:00
// ---------------------------------------------------------------------------
function getAbuseTargetUrl (abuse: MAbuseFull) {
return abuse.VideoAbuse?.Video?.url ||
abuse.VideoCommentAbuse?.VideoComment?.url ||
abuse.FlaggedAccount.Actor.url
}
export {
2020-11-20 10:21:08 +00:00
getLocalVideoActivityPubUrl,
getLocalVideoPlaylistActivityPubUrl,
getLocalVideoPlaylistElementActivityPubUrl,
getLocalVideoCacheFileActivityPubUrl,
getLocalVideoCacheStreamingPlaylistActivityPubUrl,
getLocalVideoCommentActivityPubUrl,
getLocalVideoChannelActivityPubUrl,
getLocalAccountActivityPubUrl,
getLocalAbuseActivityPubUrl,
getLocalActorFollowActivityPubUrl,
getLocalActorFollowAcceptActivityPubUrl,
getLocalVideoAnnounceActivityPubUrl,
getUpdateActivityPubUrl,
2017-11-22 15:25:03 +00:00
getUndoActivityPubUrl,
2020-11-20 10:21:08 +00:00
getVideoLikeActivityPubUrlByLocalActor,
getLocalVideoViewActivityPubUrl,
getVideoDislikeActivityPubUrlByLocalActor,
getLocalActorFollowRejectActivityPubUrl,
getDeleteActivityPubUrl,
2020-11-20 10:21:08 +00:00
getLocalVideoSharesActivityPubUrl,
getLocalVideoCommentsActivityPubUrl,
getLocalVideoLikesActivityPubUrl,
2021-07-30 14:51:27 +00:00
getLocalVideoDislikesActivityPubUrl,
getAbuseTargetUrl
}