From 5c6d985faeef1d6793d3f44ca6374f1a9b722806 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 14 Nov 2018 15:01:28 +0100 Subject: Check activities host --- server/controllers/activitypub/client.ts | 36 ++++++++++++++++++++++++++++---- server/controllers/activitypub/inbox.ts | 6 ++++-- 2 files changed, 36 insertions(+), 6 deletions(-) (limited to 'server/controllers/activitypub') diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 433186179..ffbf1ba19 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -3,17 +3,22 @@ import * as express from 'express' import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers' -import { buildAnnounceWithVideoAudience } from '../../lib/activitypub/send' +import { buildAnnounceWithVideoAudience, buildDislikeActivity, buildLikeActivity } from '../../lib/activitypub/send' import { audiencify, getAudience } from '../../lib/activitypub/audience' import { buildCreateActivity } from '../../lib/activitypub/send/send-create' import { asyncMiddleware, + videosShareValidator, executeIfActivityPub, localAccountValidator, localVideoChannelValidator, videosCustomGetValidator } from '../../middlewares' -import { videoCommentGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators' +import { + getAccountVideoRateValidator, + videoCommentGetValidator, + videosGetValidator +} from '../../middlewares/validators' import { AccountModel } from '../../models/account/account' import { ActorModel } from '../../models/activitypub/actor' import { ActorFollowModel } from '../../models/activitypub/actor-follow' @@ -25,6 +30,7 @@ import { cacheRoute } from '../../middlewares/cache' import { activityPubResponse } from './utils' import { AccountVideoRateModel } from '../../models/account/account-video-rate' import { + getRateUrl, getVideoCommentsActivityPubUrl, getVideoDislikesActivityPubUrl, getVideoLikesActivityPubUrl, @@ -48,6 +54,14 @@ activityPubClientRouter.get('/accounts?/:name/following', executeIfActivityPub(asyncMiddleware(localAccountValidator)), executeIfActivityPub(asyncMiddleware(accountFollowingController)) ) +activityPubClientRouter.get('/accounts?/:name/likes/:videoId', + executeIfActivityPub(asyncMiddleware(getAccountVideoRateValidator('like'))), + executeIfActivityPub(getAccountVideoRate('like')) +) +activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', + executeIfActivityPub(asyncMiddleware(getAccountVideoRateValidator('dislike'))), + executeIfActivityPub(getAccountVideoRate('dislike')) +) activityPubClientRouter.get('/videos/watch/:id', executeIfActivityPub(asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS))), @@ -62,7 +76,7 @@ activityPubClientRouter.get('/videos/watch/:id/announces', executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video'))), executeIfActivityPub(asyncMiddleware(videoAnnouncesController)) ) -activityPubClientRouter.get('/videos/watch/:id/announces/:accountId', +activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', executeIfActivityPub(asyncMiddleware(videosShareValidator)), executeIfActivityPub(asyncMiddleware(videoAnnounceController)) ) @@ -133,6 +147,20 @@ async function accountFollowingController (req: express.Request, res: express.Re return activityPubResponse(activityPubContextify(activityPubResult), res) } +function getAccountVideoRate (rateType: VideoRateType) { + return (req: express.Request, res: express.Response) => { + const accountVideoRate: AccountVideoRateModel = res.locals.accountVideoRate + + const byActor = accountVideoRate.Account.Actor + const url = getRateUrl(rateType, byActor, accountVideoRate.Video) + const APObject = rateType === 'like' + ? buildLikeActivity(url, byActor, accountVideoRate.Video) + : buildCreateActivity(url, byActor, buildDislikeActivity(url, byActor, accountVideoRate.Video)) + + return activityPubResponse(activityPubContextify(APObject), res) + } +} + async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { const video: VideoModel = res.locals.video @@ -276,7 +304,7 @@ function videoRates (req: express.Request, rateType: VideoRateType, video: Video const result = await AccountVideoRateModel.listAndCountAccountUrlsByVideoId(rateType, video.id, start, count) return { total: result.count, - data: result.rows.map(r => r.Account.Actor.url) + data: result.rows.map(r => r.url) } } return activityPubCollectionPagination(url, handler, req.query.page) diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts index 738d155eb..f0e65015b 100644 --- a/server/controllers/activitypub/inbox.ts +++ b/server/controllers/activitypub/inbox.ts @@ -43,11 +43,13 @@ export { // --------------------------------------------------------------------------- const inboxQueue = queue<{ activities: Activity[], signatureActor?: ActorModel, inboxActor?: ActorModel }, Error>((task, cb) => { - processActivities(task.activities, task.signatureActor, task.inboxActor) + const options = { signatureActor: task.signatureActor, inboxActor: task.inboxActor } + + processActivities(task.activities, options) .then(() => cb()) }) -function inboxController (req: express.Request, res: express.Response, next: express.NextFunction) { +function inboxController (req: express.Request, res: express.Response) { const rootActivity: RootActivity = req.body let activities: Activity[] = [] -- cgit v1.2.3 From 8d1fa36ad22a21a9b0fb6bf51a27d09954220013 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Nov 2018 11:18:13 +0100 Subject: Do not host remote AP objects --- server/controllers/activitypub/client.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'server/controllers/activitypub') diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index ffbf1ba19..a342a48d4 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -39,6 +39,7 @@ import { import { VideoCaptionModel } from '../../models/video/video-caption' import { videoRedundancyGetValidator } from '../../middlewares/validators/redundancy' import { getServerActor } from '../../helpers/utils' +import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' const activityPubClientRouter = express.Router() @@ -164,6 +165,8 @@ function getAccountVideoRate (rateType: VideoRateType) { async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { const video: VideoModel = res.locals.video + if (video.isOwned() === false) return res.redirect(video.url) + // We need captions to render AP object video.VideoCaptions = await VideoCaptionModel.listVideoCaptions(video.id) @@ -180,6 +183,9 @@ async function videoController (req: express.Request, res: express.Response, nex async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { const share = res.locals.videoShare as VideoShareModel + + if (share.Actor.isOwned() === false) return res.redirect(share.url) + const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.video, undefined) return activityPubResponse(activityPubContextify(activity), res) @@ -252,6 +258,8 @@ async function videoChannelFollowingController (req: express.Request, res: expre async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) { const videoComment: VideoCommentModel = res.locals.videoComment + if (videoComment.isOwned() === false) return res.redirect(videoComment.url) + const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined) const isPublic = true // Comments are always public const audience = getAudience(videoComment.Account.Actor, isPublic) @@ -267,7 +275,9 @@ async function videoCommentController (req: express.Request, res: express.Respon } async function videoRedundancyController (req: express.Request, res: express.Response) { - const videoRedundancy = res.locals.videoRedundancy + const videoRedundancy: VideoRedundancyModel = res.locals.videoRedundancy + if (videoRedundancy.isOwned() === false) return res.redirect(videoRedundancy.url) + const serverActor = await getServerActor() const audience = getAudience(serverActor) -- cgit v1.2.3 From babecc3c09cd4ed06fe643a97fff4bcc31c5a9be Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Nov 2018 15:38:09 +0100 Subject: Fix AP collections pagination --- server/controllers/activitypub/client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'server/controllers/activitypub') diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index a342a48d4..d9d385460 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -298,7 +298,7 @@ async function actorFollowing (req: express.Request, actor: ActorModel) { return ActorFollowModel.listAcceptedFollowingUrlsForApi([ actor.id ], undefined, start, count) } - return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, handler, req.query.page) + return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page) } async function actorFollowers (req: express.Request, actor: ActorModel) { @@ -306,7 +306,7 @@ async function actorFollowers (req: express.Request, actor: ActorModel) { return ActorFollowModel.listAcceptedFollowerUrlsForApi([ actor.id ], undefined, start, count) } - return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, handler, req.query.page) + return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page) } function videoRates (req: express.Request, rateType: VideoRateType, video: VideoModel, url: string) { -- cgit v1.2.3 From 1a8dd4da77468068d1ff7f7bd67f76399ae04e04 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 30 Nov 2018 15:06:06 +0100 Subject: Fix AP redirection --- server/controllers/activitypub/client.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'server/controllers/activitypub') diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index d9d385460..1a4e28dc8 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -162,10 +162,10 @@ function getAccountVideoRate (rateType: VideoRateType) { } } -async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { +async function videoController (req: express.Request, res: express.Response) { const video: VideoModel = res.locals.video - if (video.isOwned() === false) return res.redirect(video.url) + if (video.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(video.url) // We need captions to render AP object video.VideoCaptions = await VideoCaptionModel.listVideoCaptions(video.id) @@ -181,17 +181,17 @@ async function videoController (req: express.Request, res: express.Response, nex return activityPubResponse(activityPubContextify(videoObject), res) } -async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { +async function videoAnnounceController (req: express.Request, res: express.Response) { const share = res.locals.videoShare as VideoShareModel - if (share.Actor.isOwned() === false) return res.redirect(share.url) + if (share.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(share.url) const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.video, undefined) return activityPubResponse(activityPubContextify(activity), res) } -async function videoAnnouncesController (req: express.Request, res: express.Response, next: express.NextFunction) { +async function videoAnnouncesController (req: express.Request, res: express.Response) { const video: VideoModel = res.locals.video const handler = async (start: number, count: number) => { @@ -206,21 +206,21 @@ async function videoAnnouncesController (req: express.Request, res: express.Resp return activityPubResponse(activityPubContextify(json), res) } -async function videoLikesController (req: express.Request, res: express.Response, next: express.NextFunction) { +async function videoLikesController (req: express.Request, res: express.Response) { const video: VideoModel = res.locals.video const json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video)) return activityPubResponse(activityPubContextify(json), res) } -async function videoDislikesController (req: express.Request, res: express.Response, next: express.NextFunction) { +async function videoDislikesController (req: express.Request, res: express.Response) { const video: VideoModel = res.locals.video const json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video)) return activityPubResponse(activityPubContextify(json), res) } -async function videoCommentsController (req: express.Request, res: express.Response, next: express.NextFunction) { +async function videoCommentsController (req: express.Request, res: express.Response) { const video: VideoModel = res.locals.video const handler = async (start: number, count: number) => { @@ -235,30 +235,30 @@ async function videoCommentsController (req: express.Request, res: express.Respo return activityPubResponse(activityPubContextify(json), res) } -async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) { +async function videoChannelController (req: express.Request, res: express.Response) { const videoChannel: VideoChannelModel = res.locals.videoChannel return activityPubResponse(activityPubContextify(videoChannel.toActivityPubObject()), res) } -async function videoChannelFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { +async function videoChannelFollowersController (req: express.Request, res: express.Response) { const videoChannel: VideoChannelModel = res.locals.videoChannel const activityPubResult = await actorFollowers(req, videoChannel.Actor) return activityPubResponse(activityPubContextify(activityPubResult), res) } -async function videoChannelFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { +async function videoChannelFollowingController (req: express.Request, res: express.Response) { const videoChannel: VideoChannelModel = res.locals.videoChannel const activityPubResult = await actorFollowing(req, videoChannel.Actor) return activityPubResponse(activityPubContextify(activityPubResult), res) } -async function videoCommentController (req: express.Request, res: express.Response, next: express.NextFunction) { +async function videoCommentController (req: express.Request, res: express.Response) { const videoComment: VideoCommentModel = res.locals.videoComment - if (videoComment.isOwned() === false) return res.redirect(videoComment.url) + if (videoComment.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoComment.url) const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined) const isPublic = true // Comments are always public @@ -276,7 +276,7 @@ async function videoCommentController (req: express.Request, res: express.Respon async function videoRedundancyController (req: express.Request, res: express.Response) { const videoRedundancy: VideoRedundancyModel = res.locals.videoRedundancy - if (videoRedundancy.isOwned() === false) return res.redirect(videoRedundancy.url) + if (videoRedundancy.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoRedundancy.url) const serverActor = await getServerActor() -- cgit v1.2.3 From 1e7eb25f6cb6893db8f99ff40ef0509aa2a16614 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 15 Jan 2019 14:52:33 +0100 Subject: Correctly send Flag/Dislike/View activities --- server/controllers/activitypub/client.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'server/controllers/activitypub') diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 1a4e28dc8..7e87f6f3b 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -3,22 +3,18 @@ import * as express from 'express' import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers' -import { buildAnnounceWithVideoAudience, buildDislikeActivity, buildLikeActivity } from '../../lib/activitypub/send' +import { buildAnnounceWithVideoAudience, buildLikeActivity } from '../../lib/activitypub/send' import { audiencify, getAudience } from '../../lib/activitypub/audience' import { buildCreateActivity } from '../../lib/activitypub/send/send-create' import { asyncMiddleware, - videosShareValidator, executeIfActivityPub, localAccountValidator, localVideoChannelValidator, - videosCustomGetValidator + videosCustomGetValidator, + videosShareValidator } from '../../middlewares' -import { - getAccountVideoRateValidator, - videoCommentGetValidator, - videosGetValidator -} from '../../middlewares/validators' +import { getAccountVideoRateValidator, videoCommentGetValidator, videosGetValidator } from '../../middlewares/validators' import { AccountModel } from '../../models/account/account' import { ActorModel } from '../../models/activitypub/actor' import { ActorFollowModel } from '../../models/activitypub/actor-follow' @@ -40,6 +36,7 @@ import { VideoCaptionModel } from '../../models/video/video-caption' import { videoRedundancyGetValidator } from '../../middlewares/validators/redundancy' import { getServerActor } from '../../helpers/utils' import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' +import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike' const activityPubClientRouter = express.Router() @@ -156,7 +153,7 @@ function getAccountVideoRate (rateType: VideoRateType) { const url = getRateUrl(rateType, byActor, accountVideoRate.Video) const APObject = rateType === 'like' ? buildLikeActivity(url, byActor, accountVideoRate.Video) - : buildCreateActivity(url, byActor, buildDislikeActivity(url, byActor, accountVideoRate.Video)) + : buildDislikeActivity(url, byActor, accountVideoRate.Video) return activityPubResponse(activityPubContextify(APObject), res) } -- cgit v1.2.3 From 092092969633bbcf6d4891a083ea497a7d5c3154 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 29 Jan 2019 08:37:25 +0100 Subject: Add hls support on server --- server/controllers/activitypub/client.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'server/controllers/activitypub') diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 1a4e28dc8..32a83aa5f 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -37,7 +37,7 @@ import { getVideoSharesActivityPubUrl } from '../../lib/activitypub' import { VideoCaptionModel } from '../../models/video/video-caption' -import { videoRedundancyGetValidator } from '../../middlewares/validators/redundancy' +import { videoFileRedundancyGetValidator, videoPlaylistRedundancyGetValidator } from '../../middlewares/validators/redundancy' import { getServerActor } from '../../helpers/utils' import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' @@ -66,11 +66,11 @@ activityPubClientRouter.get('/accounts?/:name/dislikes/:videoId', activityPubClientRouter.get('/videos/watch/:id', executeIfActivityPub(asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.ACTIVITY_PUB.VIDEOS))), - executeIfActivityPub(asyncMiddleware(videosGetValidator)), + executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video-with-rights'))), executeIfActivityPub(asyncMiddleware(videoController)) ) activityPubClientRouter.get('/videos/watch/:id/activity', - executeIfActivityPub(asyncMiddleware(videosGetValidator)), + executeIfActivityPub(asyncMiddleware(videosCustomGetValidator('only-video-with-rights'))), executeIfActivityPub(asyncMiddleware(videoController)) ) activityPubClientRouter.get('/videos/watch/:id/announces', @@ -116,7 +116,11 @@ activityPubClientRouter.get('/video-channels/:name/following', ) activityPubClientRouter.get('/redundancy/videos/:videoId/:resolution([0-9]+)(-:fps([0-9]+))?', - executeIfActivityPub(asyncMiddleware(videoRedundancyGetValidator)), + executeIfActivityPub(asyncMiddleware(videoFileRedundancyGetValidator)), + executeIfActivityPub(asyncMiddleware(videoRedundancyController)) +) +activityPubClientRouter.get('/redundancy/video-playlists/:streamingPlaylistType/:videoId', + executeIfActivityPub(asyncMiddleware(videoPlaylistRedundancyGetValidator)), executeIfActivityPub(asyncMiddleware(videoRedundancyController)) ) @@ -163,7 +167,8 @@ function getAccountVideoRate (rateType: VideoRateType) { } async function videoController (req: express.Request, res: express.Response) { - const video: VideoModel = res.locals.video + // We need more attributes + const video: VideoModel = await VideoModel.loadForGetAPI(res.locals.video.id) if (video.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(video.url) -- cgit v1.2.3