X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Factivitypub%2Fclient.ts;h=0d1dff96f2e41592f01e0a22557d2ec5901e78b2;hb=9c6ca37fc1512a99d420ea90707cebcd06cdc970;hp=7e87f6f3baad1f95707e746292c474dd3bd0dc72;hpb=1e7eb25f6cb6893db8f99ff40ef0509aa2a16614;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 7e87f6f3b..0d1dff96f 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -14,7 +14,7 @@ import { videosCustomGetValidator, videosShareValidator } from '../../middlewares' -import { getAccountVideoRateValidator, videoCommentGetValidator, videosGetValidator } from '../../middlewares/validators' +import { getAccountVideoRateValidator, videoCommentGetValidator } from '../../middlewares/validators' import { AccountModel } from '../../models/account/account' import { ActorModel } from '../../models/activitypub/actor' import { ActorFollowModel } from '../../models/activitypub/actor-follow' @@ -33,10 +33,14 @@ 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' import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike' +import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' +import { VideoPlaylistModel } from '../../models/video/video-playlist' +import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element' +import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' const activityPubClientRouter = express.Router() @@ -52,6 +56,10 @@ activityPubClientRouter.get('/accounts?/:name/following', executeIfActivityPub(asyncMiddleware(localAccountValidator)), executeIfActivityPub(asyncMiddleware(accountFollowingController)) ) +activityPubClientRouter.get('/accounts?/:name/playlists', + executeIfActivityPub(asyncMiddleware(localAccountValidator)), + executeIfActivityPub(asyncMiddleware(accountPlaylistsController)) +) activityPubClientRouter.get('/accounts?/:name/likes/:videoId', executeIfActivityPub(asyncMiddleware(getAccountVideoRateValidator('like'))), executeIfActivityPub(getAccountVideoRate('like')) @@ -63,11 +71,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', @@ -113,10 +121,23 @@ 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/streaming-playlists/:streamingPlaylistType/:videoId', + executeIfActivityPub(asyncMiddleware(videoPlaylistRedundancyGetValidator)), executeIfActivityPub(asyncMiddleware(videoRedundancyController)) ) +activityPubClientRouter.get('/video-playlists/:playlistId', + executeIfActivityPub(asyncMiddleware(videoPlaylistsGetValidator)), + executeIfActivityPub(asyncMiddleware(videoPlaylistController)) +) +activityPubClientRouter.get('/video-playlists/:playlistId/:videoId', + executeIfActivityPub(asyncMiddleware(videoPlaylistElementAPGetValidator)), + executeIfActivityPub(asyncMiddleware(videoPlaylistElementController)) +) + // --------------------------------------------------------------------------- export { @@ -125,26 +146,33 @@ export { // --------------------------------------------------------------------------- -function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { +function accountController (req: express.Request, res: express.Response) { const account: AccountModel = res.locals.account return activityPubResponse(activityPubContextify(account.toActivityPubObject()), res) } -async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { +async function accountFollowersController (req: express.Request, res: express.Response) { const account: AccountModel = res.locals.account const activityPubResult = await actorFollowers(req, account.Actor) return activityPubResponse(activityPubContextify(activityPubResult), res) } -async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { +async function accountFollowingController (req: express.Request, res: express.Response) { const account: AccountModel = res.locals.account const activityPubResult = await actorFollowing(req, account.Actor) return activityPubResponse(activityPubContextify(activityPubResult), res) } +async function accountPlaylistsController (req: express.Request, res: express.Response) { + const account: AccountModel = res.locals.account + const activityPubResult = await actorPlaylists(req, account) + + return activityPubResponse(activityPubContextify(activityPubResult), res) +} + function getAccountVideoRate (rateType: VideoRateType) { return (req: express.Request, res: express.Response) => { const accountVideoRate: AccountVideoRateModel = res.locals.accountVideoRate @@ -160,7 +188,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) @@ -288,6 +317,26 @@ async function videoRedundancyController (req: express.Request, res: express.Res return activityPubResponse(activityPubContextify(object), res) } +async function videoPlaylistController (req: express.Request, res: express.Response) { + const playlist: VideoPlaylistModel = res.locals.videoPlaylist + + // We need more attributes + playlist.OwnerAccount = await AccountModel.load(playlist.ownerAccountId) + + const json = await playlist.toActivityPubObject(req.query.page, null) + const audience = getAudience(playlist.OwnerAccount.Actor, playlist.privacy === VideoPlaylistPrivacy.PUBLIC) + const object = audiencify(json, audience) + + return activityPubResponse(activityPubContextify(object), res) +} + +async function videoPlaylistElementController (req: express.Request, res: express.Response) { + const videoPlaylistElement: VideoPlaylistElementModel = res.locals.videoPlaylistElement + + const json = videoPlaylistElement.toActivityPubObject() + return activityPubResponse(activityPubContextify(json), res) +} + // --------------------------------------------------------------------------- async function actorFollowing (req: express.Request, actor: ActorModel) { @@ -300,7 +349,15 @@ async function actorFollowing (req: express.Request, actor: ActorModel) { async function actorFollowers (req: express.Request, actor: ActorModel) { const handler = (start: number, count: number) => { - return ActorFollowModel.listAcceptedFollowerUrlsForApi([ actor.id ], undefined, start, count) + return ActorFollowModel.listAcceptedFollowerUrlsForAP([ actor.id ], undefined, start, count) + } + + return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page) +} + +async function actorPlaylists (req: express.Request, account: AccountModel) { + const handler = (start: number, count: number) => { + return VideoPlaylistModel.listUrlsOfForAP(account.id, start, count) } return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page)