diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-12 17:53:50 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-13 16:50:33 +0100 |
commit | 3fd3ab2d34d512b160a5e6084d7609be7b4f4452 (patch) | |
tree | e5ca358287fca6ecacce83defcf23af1e8e9f419 /server/controllers/activitypub | |
parent | c893d4514e6ecbf282c7985fe5f82b8acd8a1137 (diff) | |
download | PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.gz PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.tar.zst PeerTube-3fd3ab2d34d512b160a5e6084d7609be7b4f4452.zip |
Move models to typescript-sequelize
Diffstat (limited to 'server/controllers/activitypub')
-rw-r--r-- | server/controllers/activitypub/client.ts | 48 | ||||
-rw-r--r-- | server/controllers/activitypub/outbox.ts | 8 |
2 files changed, 29 insertions, 27 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index a478acd14..72b216254 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -1,20 +1,22 @@ | |||
1 | // Intercept ActivityPub client requests | 1 | // Intercept ActivityPub client requests |
2 | import * as express from 'express' | 2 | import * as express from 'express' |
3 | import { pageToStartAndCount } from '../../helpers' | 3 | import { activityPubCollectionPagination, pageToStartAndCount } from '../../helpers' |
4 | import { activityPubCollectionPagination } from '../../helpers/activitypub' | 4 | import { ACTIVITY_PUB, CONFIG } from '../../initializers' |
5 | 5 | import { buildVideoChannelAnnounceToFollowers } from '../../lib/activitypub/send' | |
6 | import { database as db } from '../../initializers' | ||
7 | import { ACTIVITY_PUB, CONFIG } from '../../initializers/constants' | ||
8 | import { buildVideoChannelAnnounceToFollowers } from '../../lib/activitypub/send/send-announce' | ||
9 | import { buildVideoAnnounceToFollowers } from '../../lib/index' | 6 | import { buildVideoAnnounceToFollowers } from '../../lib/index' |
10 | import { executeIfActivityPub, localAccountValidator } from '../../middlewares' | 7 | import { asyncMiddleware, executeIfActivityPub, localAccountValidator } from '../../middlewares' |
11 | import { asyncMiddleware } from '../../middlewares/async' | 8 | import { |
12 | import { videoChannelsGetValidator, videoChannelsShareValidator } from '../../middlewares/validators/video-channels' | 9 | videoChannelsGetValidator, |
13 | import { videosGetValidator, videosShareValidator } from '../../middlewares/validators/videos' | 10 | videoChannelsShareValidator, |
14 | import { AccountInstance, VideoChannelInstance } from '../../models' | 11 | videosGetValidator, |
15 | import { VideoChannelShareInstance } from '../../models/video/video-channel-share-interface' | 12 | videosShareValidator |
16 | import { VideoInstance } from '../../models/video/video-interface' | 13 | } from '../../middlewares/validators' |
17 | import { VideoShareInstance } from '../../models/video/video-share-interface' | 14 | import { AccountModel } from '../../models/account/account' |
15 | import { AccountFollowModel } from '../../models/account/account-follow' | ||
16 | import { VideoModel } from '../../models/video/video' | ||
17 | import { VideoChannelModel } from '../../models/video/video-channel' | ||
18 | import { VideoChannelShareModel } from '../../models/video/video-channel-share' | ||
19 | import { VideoShareModel } from '../../models/video/video-share' | ||
18 | 20 | ||
19 | const activityPubClientRouter = express.Router() | 21 | const activityPubClientRouter = express.Router() |
20 | 22 | ||
@@ -62,57 +64,57 @@ export { | |||
62 | // --------------------------------------------------------------------------- | 64 | // --------------------------------------------------------------------------- |
63 | 65 | ||
64 | function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { | 66 | function accountController (req: express.Request, res: express.Response, next: express.NextFunction) { |
65 | const account: AccountInstance = res.locals.account | 67 | const account: AccountModel = res.locals.account |
66 | 68 | ||
67 | return res.json(account.toActivityPubObject()).end() | 69 | return res.json(account.toActivityPubObject()).end() |
68 | } | 70 | } |
69 | 71 | ||
70 | async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { | 72 | async function accountFollowersController (req: express.Request, res: express.Response, next: express.NextFunction) { |
71 | const account: AccountInstance = res.locals.account | 73 | const account: AccountModel = res.locals.account |
72 | 74 | ||
73 | const page = req.query.page || 1 | 75 | const page = req.query.page || 1 |
74 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 76 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
75 | 77 | ||
76 | const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi([ account.id ], undefined, start, count) | 78 | const result = await AccountFollowModel.listAcceptedFollowerUrlsForApi([ account.id ], undefined, start, count) |
77 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) | 79 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) |
78 | 80 | ||
79 | return res.json(activityPubResult) | 81 | return res.json(activityPubResult) |
80 | } | 82 | } |
81 | 83 | ||
82 | async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { | 84 | async function accountFollowingController (req: express.Request, res: express.Response, next: express.NextFunction) { |
83 | const account: AccountInstance = res.locals.account | 85 | const account: AccountModel = res.locals.account |
84 | 86 | ||
85 | const page = req.query.page || 1 | 87 | const page = req.query.page || 1 |
86 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) | 88 | const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) |
87 | 89 | ||
88 | const result = await db.AccountFollow.listAcceptedFollowingUrlsForApi([ account.id ], undefined, start, count) | 90 | const result = await AccountFollowModel.listAcceptedFollowingUrlsForApi([ account.id ], undefined, start, count) |
89 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) | 91 | const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) |
90 | 92 | ||
91 | return res.json(activityPubResult) | 93 | return res.json(activityPubResult) |
92 | } | 94 | } |
93 | 95 | ||
94 | function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { | 96 | function videoController (req: express.Request, res: express.Response, next: express.NextFunction) { |
95 | const video: VideoInstance = res.locals.video | 97 | const video: VideoModel = res.locals.video |
96 | 98 | ||
97 | return res.json(video.toActivityPubObject()) | 99 | return res.json(video.toActivityPubObject()) |
98 | } | 100 | } |
99 | 101 | ||
100 | async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { | 102 | async function videoAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { |
101 | const share = res.locals.videoShare as VideoShareInstance | 103 | const share = res.locals.videoShare as VideoShareModel |
102 | const object = await buildVideoAnnounceToFollowers(share.Account, res.locals.video, undefined) | 104 | const object = await buildVideoAnnounceToFollowers(share.Account, res.locals.video, undefined) |
103 | 105 | ||
104 | return res.json(object) | 106 | return res.json(object) |
105 | } | 107 | } |
106 | 108 | ||
107 | async function videoChannelAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { | 109 | async function videoChannelAnnounceController (req: express.Request, res: express.Response, next: express.NextFunction) { |
108 | const share = res.locals.videoChannelShare as VideoChannelShareInstance | 110 | const share = res.locals.videoChannelShare as VideoChannelShareModel |
109 | const object = await buildVideoChannelAnnounceToFollowers(share.Account, share.VideoChannel, undefined) | 111 | const object = await buildVideoChannelAnnounceToFollowers(share.Account, share.VideoChannel, undefined) |
110 | 112 | ||
111 | return res.json(object) | 113 | return res.json(object) |
112 | } | 114 | } |
113 | 115 | ||
114 | async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) { | 116 | async function videoChannelController (req: express.Request, res: express.Response, next: express.NextFunction) { |
115 | const videoChannel: VideoChannelInstance = res.locals.videoChannel | 117 | const videoChannel: VideoChannelModel = res.locals.videoChannel |
116 | 118 | ||
117 | return res.json(videoChannel.toActivityPubObject()) | 119 | return res.json(videoChannel.toActivityPubObject()) |
118 | } | 120 | } |
diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts index 5a2d43f3d..dc6b72a6e 100644 --- a/server/controllers/activitypub/outbox.ts +++ b/server/controllers/activitypub/outbox.ts | |||
@@ -2,13 +2,13 @@ import * as express from 'express' | |||
2 | import { Activity } from '../../../shared/models/activitypub/activity' | 2 | 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 { database as db } from '../../initializers' | ||
6 | import { ACTIVITY_PUB } from '../../initializers/constants' | 5 | import { ACTIVITY_PUB } from '../../initializers/constants' |
7 | import { addActivityData } from '../../lib/activitypub/send/send-add' | 6 | import { addActivityData } from '../../lib/activitypub/send/send-add' |
8 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' | 7 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url' |
9 | import { announceActivityData } from '../../lib/index' | 8 | import { announceActivityData } from '../../lib/index' |
10 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' | 9 | import { asyncMiddleware, localAccountValidator } from '../../middlewares' |
11 | import { AccountInstance } from '../../models/account/account-interface' | 10 | import { AccountModel } from '../../models/account/account' |
11 | import { VideoModel } from '../../models/video/video' | ||
12 | 12 | ||
13 | const outboxRouter = express.Router() | 13 | const outboxRouter = express.Router() |
14 | 14 | ||
@@ -26,12 +26,12 @@ export { | |||
26 | // --------------------------------------------------------------------------- | 26 | // --------------------------------------------------------------------------- |
27 | 27 | ||
28 | async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { | 28 | async function outboxController (req: express.Request, res: express.Response, next: express.NextFunction) { |
29 | const account: AccountInstance = res.locals.account | 29 | const account: AccountModel = res.locals.account |
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 db.Video.listAllAndSharedByAccountForOutbox(account.id, start, count) | 34 | const data = await VideoModel.listAllAndSharedByAccountForOutbox(account.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) { |