import * as cors from 'cors'
import * as express from 'express'
-import { getRateUrl } from '@server/lib/activitypub/video-rates'
import { getServerActor } from '@server/models/application/application'
import { MAccountId, MActorId, MChannelId, MVideoId } from '@server/types/models'
import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos'
import { buildCreateActivity } from '../../lib/activitypub/send/send-create'
import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike'
import {
- getVideoCommentsActivityPubUrl,
- getVideoDislikesActivityPubUrl,
- getVideoLikesActivityPubUrl,
- getVideoSharesActivityPubUrl
+ getLocalVideoCommentsActivityPubUrl,
+ getLocalVideoDislikesActivityPubUrl,
+ getLocalVideoLikesActivityPubUrl,
+ getLocalVideoSharesActivityPubUrl
} from '../../lib/activitypub/url'
import {
asyncMiddleware,
const accountVideoRate = res.locals.accountVideoRate
const byActor = accountVideoRate.Account.Actor
- const url = getRateUrl(rateType, byActor, accountVideoRate.Video)
const APObject = rateType === 'like'
- ? buildLikeActivity(url, byActor, accountVideoRate.Video)
- : buildDislikeActivity(url, byActor, accountVideoRate.Video)
+ ? buildLikeActivity(accountVideoRate.url, byActor, accountVideoRate.Video)
+ : buildDislikeActivity(accountVideoRate.url, byActor, accountVideoRate.Video)
return activityPubResponse(activityPubContextify(APObject), res)
}
// We need more attributes
const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(res.locals.onlyVideoWithRights.id)
- if (video.url.startsWith(WEBSERVER.URL) === false) return res.redirect(video.url)
+ if (redirectIfNotOwned(video.url, res)) return
// We need captions to render AP object
const captions = await VideoCaptionModel.listVideoCaptions(video.id)
async function videoAnnounceController (req: express.Request, res: express.Response) {
const share = res.locals.videoShare
- if (share.url.startsWith(WEBSERVER.URL) === false) return res.redirect(share.url)
+ if (redirectIfNotOwned(share.url, res)) return
const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.videoAll, undefined)
async function videoAnnouncesController (req: express.Request, res: express.Response) {
const video = res.locals.onlyImmutableVideo
+ if (redirectIfNotOwned(video.url, res)) return
+
const handler = async (start: number, count: number) => {
const result = await VideoShareModel.listAndCountByVideoId(video.id, start, count)
return {
data: result.rows.map(r => r.url)
}
}
- const json = await activityPubCollectionPagination(getVideoSharesActivityPubUrl(video), handler, req.query.page)
+ const json = await activityPubCollectionPagination(getLocalVideoSharesActivityPubUrl(video), handler, req.query.page)
return activityPubResponse(activityPubContextify(json), res)
}
async function videoLikesController (req: express.Request, res: express.Response) {
const video = res.locals.onlyImmutableVideo
- const json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video))
+
+ if (redirectIfNotOwned(video.url, res)) return
+
+ const json = await videoRates(req, 'like', video, getLocalVideoLikesActivityPubUrl(video))
return activityPubResponse(activityPubContextify(json), res)
}
async function videoDislikesController (req: express.Request, res: express.Response) {
const video = res.locals.onlyImmutableVideo
- const json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video))
+
+ if (redirectIfNotOwned(video.url, res)) return
+
+ const json = await videoRates(req, 'dislike', video, getLocalVideoDislikesActivityPubUrl(video))
return activityPubResponse(activityPubContextify(json), res)
}
async function videoCommentsController (req: express.Request, res: express.Response) {
const video = res.locals.onlyImmutableVideo
+ if (redirectIfNotOwned(video.url, res)) return
+
const handler = async (start: number, count: number) => {
const result = await VideoCommentModel.listAndCountByVideoForAP(video, start, count)
return {
data: result.rows.map(r => r.url)
}
}
- const json = await activityPubCollectionPagination(getVideoCommentsActivityPubUrl(video), handler, req.query.page)
+ const json = await activityPubCollectionPagination(getLocalVideoCommentsActivityPubUrl(video), handler, req.query.page)
return activityPubResponse(activityPubContextify(json), res)
}
async function videoCommentController (req: express.Request, res: express.Response) {
const videoComment = res.locals.videoCommentFull
- if (videoComment.url.startsWith(WEBSERVER.URL) === false) return res.redirect(videoComment.url)
+ if (redirectIfNotOwned(videoComment.url, res)) return
const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined)
const isPublic = true // Comments are always public
async function videoRedundancyController (req: express.Request, res: express.Response) {
const videoRedundancy = res.locals.videoRedundancy
- if (videoRedundancy.url.startsWith(WEBSERVER.URL) === false) return res.redirect(videoRedundancy.url)
+
+ if (redirectIfNotOwned(videoRedundancy.url, res)) return
const serverActor = await getServerActor()
async function videoPlaylistController (req: express.Request, res: express.Response) {
const playlist = res.locals.videoPlaylistFull
+ if (redirectIfNotOwned(playlist.url, res)) return
+
// We need more attributes
playlist.OwnerAccount = await AccountModel.load(playlist.ownerAccountId)
function videoPlaylistElementController (req: express.Request, res: express.Response) {
const videoPlaylistElement = res.locals.videoPlaylistElementAP
+ if (redirectIfNotOwned(videoPlaylistElement.url, res)) return
+
const json = videoPlaylistElement.toActivityPubObject()
return activityPubResponse(activityPubContextify(json), res)
}
}
return activityPubCollectionPagination(url, handler, req.query.page)
}
+
+function redirectIfNotOwned (url: string, res: express.Response) {
+ if (url.startsWith(WEBSERVER.URL) === false) {
+ res.redirect(url)
+ return true
+ }
+
+ return false
+}