diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-14 17:38:41 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-19 10:53:16 +0100 |
commit | 50d6de9c286abcb34ff4234d56d9cbb803db7665 (patch) | |
tree | f1732b27edcd05c7877a8358b8312f1e38c287ed /server/controllers/activitypub | |
parent | fadf619ad61a016c1c7fc53de5a8f398a4f77519 (diff) | |
download | PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.gz PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.tar.zst PeerTube-50d6de9c286abcb34ff4234d56d9cbb803db7665.zip |
Begin moving video channel to actor
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r-- | server/controllers/activitypub/client.ts | 31 | ||||
-rw-r--r-- | server/controllers/activitypub/inbox.ts | 10 | ||||
-rw-r--r-- | server/controllers/activitypub/outbox.ts | 20 |
3 files changed, 25 insertions, 36 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 72b216254..8c6294ff7 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -2,20 +2,13 @@ | |||
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { activityPubCollectionPagination, pageToStartAndCount } from '../../helpers' | 3 | import { activityPubCollectionPagination, pageToStartAndCount } from '../../helpers' |
4 | import { ACTIVITY_PUB, CONFIG } from '../../initializers' | 4 | import { ACTIVITY_PUB, CONFIG } from '../../initializers' |
5 | import { buildVideoChannelAnnounceToFollowers } from '../../lib/activitypub/send' | 5 | import { buildVideoAnnounceToFollowers } from '../../lib/activitypub/send' |
6 | import { buildVideoAnnounceToFollowers } from '../../lib/index' | ||
7 | import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares' | 6 | import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares' |
8 | import { | 7 | import { videoChannelsGetValidator, videosGetValidator, videosShareValidator } from '../../middlewares/validators' |
9 | videoChannelsGetValidator, | ||
10 | videoChannelsShareValidator, | ||
11 | videosGetValidator, | ||
12 | videosShareValidator | ||
13 | } from '../../middlewares/validators' | ||
14 | import { AccountModel } from '../../models/account/account' | 8 | import { AccountModel } from '../../models/account/account' |
15 | import { AccountFollowModel } from '../../models/account/account-follow' | 9 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' |
16 | import { VideoModel } from '../../models/video/video' | 10 | import { VideoModel } from '../../models/video/video' |
17 | import { VideoChannelModel } from '../../models/video/video-channel' | 11 | import { VideoChannelModel } from '../../models/video/video-channel' |
18 | import { VideoChannelShareModel } from '../../models/video/video-channel-share' | ||
19 | import { VideoShareModel } from '../../models/video/video-share' | 12 | import { VideoShareModel } from '../../models/video/video-share' |
20 | 13 | ||
21 | const activityPubClientRouter = express.Router() | 14 | const activityPubClientRouter = express.Router() |
@@ -50,11 +43,6 @@ activityPubClientRouter.get('/video-channels/:id', | |||
50 | executeIfActivityPub(asyncMiddleware(videoChannelController)) | 43 | executeIfActivityPub(asyncMiddleware(videoChannelController)) |
51 | ) | 44 | ) |
52 | 45 | ||
53 | activityPubClientRouter.get('/video-channels/:id/announces/:accountId', | ||
54 | executeIfActivityPub(asyncMiddleware(videoChannelsShareValidator)), | ||
55 | executeIfActivityPub(asyncMiddleware(videoChannelAnnounceController)) | ||
56 | ) | ||
57 | |||
58 | // --------------------------------------------------------------------------- | 46 | // --------------------------------------------------------------------------- |
59 | 47 | ||
60 | export { | 48 | export { |
@@ -75,7 +63,7 @@ async function accountFollowersController (req: express.Request, res: express.Re | |||
75 | const page = req.query.page || 1 | 63 | const page = req.query.page || 1 |
76 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 64 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
77 | 65 | ||
78 | const result = await AccountFollowModel.listAcceptedFollowerUrlsForApi([ account.id ], undefined, start, count) | 66 | const result = await ActorFollowModel.listAcceptedFollowerUrlsForApi([ account.Actor.id ], undefined, start, count) |
79 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) | 67 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) |
80 | 68 | ||
81 | return res.json(activityPubResult) | 69 | return res.json(activityPubResult) |
@@ -87,7 +75,7 @@ async function accountFollowingController (req: express.Request, res: express.Re | |||
87 | const page = req.query.page || 1 | 75 | const page = req.query.page || 1 |
88 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 76 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
89 | 77 | ||
90 | const result = await AccountFollowModel.listAcceptedFollowingUrlsForApi([ account.id ], undefined, start, count) | 78 | const result = await ActorFollowModel.listAcceptedFollowingUrlsForApi([ account.Actor.id ], undefined, start, count) |
91 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) | 79 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) |
92 | 80 | ||
93 | return res.json(activityPubResult) | 81 | return res.json(activityPubResult) |
@@ -101,14 +89,7 @@ function videoController (req: express.Request, res: express.Response, next: exp | |||
101 | 89 | ||
102 | async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { | 90 | async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { |
103 | const share = res.locals.videoShare as VideoShareModel | 91 | const share = res.locals.videoShare as VideoShareModel |
104 | const object = await buildVideoAnnounceToFollowers(share.Account, res.locals.video, undefined) | 92 | const object = await buildVideoAnnounceToFollowers(share.Actor, res.locals.video, undefined) |
105 | |||
106 | return res.json(object) | ||
107 | } | ||
108 | |||
109 | async function videoChannelAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
110 | const share = res.locals.videoChannelShare as VideoChannelShareModel | ||
111 | const object = await buildVideoChannelAnnounceToFollowers(share.Account, share.VideoChannel, undefined) | ||
112 | 93 | ||
113 | return res.json(object) | 94 | return res.json(object) |
114 | } | 95 | } |
diff --git a/server/controllers/activitypub/inbox.ts b/server/controllers/activitypub/inbox.ts index 88a0834f6..8332eabb1 100644 --- a/server/controllers/activitypub/inbox.ts +++ b/server/controllers/activitypub/inbox.ts | |||
@@ -5,6 +5,7 @@ import { isActivityValid } from '../../helpers/custom-validators/activitypub/act | |||
5 | import { processActivities } from '../../lib/activitypub/process/process' | 5 | import { processActivities } from '../../lib/activitypub/process/process' |
6 | import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' | 6 | import { asyncMiddleware, checkSignature, localAccountValidator, signatureValidator } from '../../middlewares' |
7 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' | 7 | import { activityPubValidator } from '../../middlewares/validators/activitypub/activity' |
8 | import { ActorModel } from '../../models/activitypub/actor' | ||
8 | 9 | ||
9 | const inboxRouter = express.Router() | 10 | const inboxRouter = express.Router() |
10 | 11 | ||
@@ -48,7 +49,14 @@ async function inboxController (req: express.Request, res: express.Response, nex | |||
48 | activities = activities.filter(a => isActivityValid(a)) | 49 | activities = activities.filter(a => isActivityValid(a)) |
49 | logger.debug('We keep %d activities.', activities.length, { activities }) | 50 | logger.debug('We keep %d activities.', activities.length, { activities }) |
50 | 51 | ||
51 | await processActivities(activities, res.locals.signature.account, res.locals.account) | 52 | let specificActor: ActorModel = undefined |
53 | if (res.locals.account) { | ||
54 | specificActor = res.locals.account | ||
55 | } else if (res.locals.videoChannel) { | ||
56 | specificActor = res.locals.videoChannel | ||
57 | } | ||
58 | |||
59 | await processActivities(activities, res.locals.signature.actor, specificActor) | ||
52 | 60 | ||
53 | res.status(204).end() | 61 | res.status(204).end() |
54 | } | 62 | } |
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts index 6ed8a3454..01ba253c6 100644 --- a/server/controllers/activitypub/outbox.ts +++ b/server/controllers/activitypub/outbox.ts | |||
@@ -3,9 +3,8 @@ import { Activity } from '../../../shared/models/activitypub/activity' | |||
3 | import { activityPubCollectionPagination } from '../../helpers/activitypub' | 3 | import { activityPubCollectionPagination } from '../../helpers/activitypub' |
4 | import { pageToStartAndCount } from '../../helpers/core-utils' | 4 | import { pageToStartAndCount } from '../../helpers/core-utils' |
5 | import { ACTIVITY_PUB } from '../../initializers/constants' | 5 | import { ACTIVITY_PUB } from '../../initializers/constants' |
6 | import { addActivityData } from '../../lib/activitypub/send/send-add' | 6 | import { announceActivityData, createActivityData } from '../../lib/activitypub/send' |
7 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' | 7 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' |
8 | import { announceActivityData } from '../../lib/index' | ||
9 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' | 8 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' |
10 | import { AccountModel } from '../../models/account/account' | 9 | import { AccountModel } from '../../models/account/account' |
11 | import { VideoModel } from '../../models/video/video' | 10 | import { VideoModel } from '../../models/video/video' |
@@ -27,29 +26,30 @@ export { | |||
27 | 26 | ||
28 | async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { | 27 | async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { |
29 | const account: AccountModel = res.locals.account | 28 | const account: AccountModel = res.locals.account |
29 | const actor = account.Actor | ||
30 | 30 | ||
31 | const page = req.query.page || 1 | 31 | const page = req.query.page || 1 |
32 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 32 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
33 | 33 | ||
34 | const data = await VideoModel.listAllAndSharedByAccountForOutbox(account.id, start, count) | 34 | const data = await VideoModel.listAllAndSharedByActorForOutbox(actor.id, start, count) |
35 | const activities: Activity[] = [] | 35 | const activities: Activity[] = [] |
36 | 36 | ||
37 | for (const video of data.data) { | 37 | for (const video of data.data) { |
38 | const videoObject = video.toActivityPubObject() | 38 | const videoObject = video.toActivityPubObject() |
39 | 39 | ||
40 | // This is a shared video | ||
41 | const videoChannel = video.VideoChannel | 40 | const videoChannel = video.VideoChannel |
41 | // This is a shared video | ||
42 | if (video.VideoShares !== undefined && video.VideoShares.length !== 0) { | 42 | if (video.VideoShares !== undefined && video.VideoShares.length !== 0) { |
43 | const addActivity = await addActivityData(video.url, videoChannel.Account, video, videoChannel.Actor.url, videoObject, undefined) | 43 | const createActivity = await createActivityData(video.url, videoChannel.Account.Actor, videoObject, undefined) |
44 | 44 | ||
45 | const url = getAnnounceActivityPubUrl(video.url, account) | 45 | const url = getAnnounceActivityPubUrl(video.url, actor) |
46 | const announceActivity = await announceActivityData(url, account, addActivity, undefined) | 46 | const announceActivity = await announceActivityData(url, actor, createActivity, undefined) |
47 | 47 | ||
48 | activities.push(announceActivity) | 48 | activities.push(announceActivity) |
49 | } else { | 49 | } else { |
50 | const addActivity = await addActivityData(video.url, account, video, videoChannel.Actor.url, videoObject, undefined) | 50 | const createActivity = await createActivityData(video.url, videoChannel.Account.Actor, videoObject, undefined) |
51 | 51 | ||
52 | activities.push(addActivity) | 52 | activities.push(createActivity) |
53 | } | 53 | } |
54 | } | 54 | } |
55 | 55 | ||
@@ -57,7 +57,7 @@ async function outboxController (req: express.Request, res: express.Response, ne | |||
57 | data: activities, | 57 | data: activities, |
58 | total: data.total | 58 | total: data.total |
59 | } | 59 | } |
60 | const json = activityPubCollectionPagination(account.url + '/outbox', page, newResult) | 60 | const json = activityPubCollectionPagination(account.Actor.url + '/outbox', page, newResult) |
61 | 61 | ||
62 | return res.json(json).end() | 62 | return res.json(json).end() |
63 | } | 63 | } |