X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fcontrollers%2Factivitypub%2Fclient.ts;h=24c8665a5286ca182eb8027933d5e25ee86cfc7c;hb=e71bcc0f4b31ecfd84a786411febfc6d18a85258;hp=5cfbc2f1d41ad907a6fa924b8f40c8a5a0cecb5f;hpb=7a7724e66e4533523083e7336cd0d0c747c4a33b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 5cfbc2f1d..24c8665a5 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -4,10 +4,13 @@ import * as express from 'express' import { database as db } from '../../initializers' import { executeIfActivityPub, localAccountValidator } from '../../middlewares' import { pageToStartAndCount } from '../../helpers' -import { AccountInstance } from '../../models' +import { AccountInstance, VideoChannelInstance } from '../../models' import { activityPubCollectionPagination } from '../../helpers/activitypub' -import { ACTIVITY_PUB } from '../../initializers/constants' +import { ACTIVITY_PUB, CONFIG } from '../../initializers/constants' import { asyncMiddleware } from '../../middlewares/async' +import { videosGetValidator } from '../../middlewares/validators/videos' +import { VideoInstance } from '../../models/video/video-interface' +import { videoChannelsGetValidator } from '../../middlewares/validators/video-channels' const activityPubClientRouter = express.Router() @@ -16,16 +19,26 @@ activityPubClientRouter.get('/account/:name', executeIfActivityPub(asyncMiddleware(accountController)) ) -activityPubClientRouter.get('/account/:nameWithHost/followers', +activityPubClientRouter.get('/account/:name/followers', executeIfActivityPub(localAccountValidator), executeIfActivityPub(asyncMiddleware(accountFollowersController)) ) -activityPubClientRouter.get('/account/:nameWithHost/following', +activityPubClientRouter.get('/account/:name/following', executeIfActivityPub(localAccountValidator), executeIfActivityPub(asyncMiddleware(accountFollowingController)) ) +activityPubClientRouter.get('/videos/watch/:id', + executeIfActivityPub(videosGetValidator), + executeIfActivityPub(asyncMiddleware(videoController)) +) + +activityPubClientRouter.get('/video-channels/:id', + executeIfActivityPub(videoChannelsGetValidator), + executeIfActivityPub(asyncMiddleware(videoChannelController)) +) + // --------------------------------------------------------------------------- export { @@ -46,8 +59,8 @@ async function accountFollowersController (req: express.Request, res: express.Re const page = req.params.page || 1 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) - const result = await db.Account.listFollowerUrlsForApi(account.id, start, count) - const activityPubResult = activityPubCollectionPagination(req.url, page, result) + const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi([ account.id ], start, count) + const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) return res.json(activityPubResult) } @@ -58,8 +71,20 @@ async function accountFollowingController (req: express.Request, res: express.Re const page = req.params.page || 1 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) - const result = await db.Account.listFollowingUrlsForApi(account.id, start, count) - const activityPubResult = activityPubCollectionPagination(req.url, page, result) + const result = await db.AccountFollow.listAcceptedFollowingUrlsForApi([ account.id ], start, count) + const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) return res.json(activityPubResult) } + +async function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { + const video: VideoInstance = res.locals.video + + return res.json(video.toActivityPubObject()) +} + +async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) { + const videoChannel: VideoChannelInstance = res.locals.videoChannel + + return res.json(videoChannel.toActivityPubObject()) +}