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