diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/activitypub/client.ts | 27 | ||||
-rw-r--r-- | server/controllers/api/index.ts | 4 | ||||
-rw-r--r-- | server/controllers/api/users/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 4 |
4 files changed, 17 insertions, 20 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 2812bfe1e..84828e7e0 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | // Intercept ActivityPub client requests | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
3 | import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' | 2 | import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' |
4 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' | 3 | import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' |
@@ -37,10 +36,12 @@ import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike' | |||
37 | import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' | 36 | import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' |
38 | import { VideoPlaylistModel } from '../../models/video/video-playlist' | 37 | import { VideoPlaylistModel } from '../../models/video/video-playlist' |
39 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' | 38 | import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' |
40 | import { MAccountId, MActorId, MVideo, MVideoAPWithoutCaption } from '@server/typings/models' | 39 | import { MAccountId, MActorId, MVideoAPWithoutCaption, MVideoId } from '@server/typings/models' |
41 | 40 | ||
42 | const activityPubClientRouter = express.Router() | 41 | const activityPubClientRouter = express.Router() |
43 | 42 | ||
43 | // Intercept ActivityPub client requests | ||
44 | |||
44 | activityPubClientRouter.get('/accounts?/:name', | 45 | activityPubClientRouter.get('/accounts?/:name', |
45 | executeIfActivityPub, | 46 | executeIfActivityPub, |
46 | asyncMiddleware(localAccountValidator), | 47 | asyncMiddleware(localAccountValidator), |
@@ -85,7 +86,7 @@ activityPubClientRouter.get('/videos/watch/:id/activity', | |||
85 | ) | 86 | ) |
86 | activityPubClientRouter.get('/videos/watch/:id/announces', | 87 | activityPubClientRouter.get('/videos/watch/:id/announces', |
87 | executeIfActivityPub, | 88 | executeIfActivityPub, |
88 | asyncMiddleware(videosCustomGetValidator('only-video')), | 89 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
89 | asyncMiddleware(videoAnnouncesController) | 90 | asyncMiddleware(videoAnnouncesController) |
90 | ) | 91 | ) |
91 | activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', | 92 | activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', |
@@ -95,17 +96,17 @@ activityPubClientRouter.get('/videos/watch/:id/announces/:actorId', | |||
95 | ) | 96 | ) |
96 | activityPubClientRouter.get('/videos/watch/:id/likes', | 97 | activityPubClientRouter.get('/videos/watch/:id/likes', |
97 | executeIfActivityPub, | 98 | executeIfActivityPub, |
98 | asyncMiddleware(videosCustomGetValidator('only-video')), | 99 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
99 | asyncMiddleware(videoLikesController) | 100 | asyncMiddleware(videoLikesController) |
100 | ) | 101 | ) |
101 | activityPubClientRouter.get('/videos/watch/:id/dislikes', | 102 | activityPubClientRouter.get('/videos/watch/:id/dislikes', |
102 | executeIfActivityPub, | 103 | executeIfActivityPub, |
103 | asyncMiddleware(videosCustomGetValidator('only-video')), | 104 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
104 | asyncMiddleware(videoDislikesController) | 105 | asyncMiddleware(videoDislikesController) |
105 | ) | 106 | ) |
106 | activityPubClientRouter.get('/videos/watch/:id/comments', | 107 | activityPubClientRouter.get('/videos/watch/:id/comments', |
107 | executeIfActivityPub, | 108 | executeIfActivityPub, |
108 | asyncMiddleware(videosCustomGetValidator('only-video')), | 109 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
109 | asyncMiddleware(videoCommentsController) | 110 | asyncMiddleware(videoCommentsController) |
110 | ) | 111 | ) |
111 | activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId', | 112 | activityPubClientRouter.get('/videos/watch/:videoId/comments/:commentId', |
@@ -238,7 +239,7 @@ async function videoAnnounceController (req: express.Request, res: express.Respo | |||
238 | } | 239 | } |
239 | 240 | ||
240 | async function videoAnnouncesController (req: express.Request, res: express.Response) { | 241 | async function videoAnnouncesController (req: express.Request, res: express.Response) { |
241 | const video = res.locals.onlyVideo | 242 | const video = res.locals.onlyImmutableVideo |
242 | 243 | ||
243 | const handler = async (start: number, count: number) => { | 244 | const handler = async (start: number, count: number) => { |
244 | const result = await VideoShareModel.listAndCountByVideoId(video.id, start, count) | 245 | const result = await VideoShareModel.listAndCountByVideoId(video.id, start, count) |
@@ -253,21 +254,21 @@ async function videoAnnouncesController (req: express.Request, res: express.Resp | |||
253 | } | 254 | } |
254 | 255 | ||
255 | async function videoLikesController (req: express.Request, res: express.Response) { | 256 | async function videoLikesController (req: express.Request, res: express.Response) { |
256 | const video = res.locals.onlyVideo | 257 | const video = res.locals.onlyImmutableVideo |
257 | const json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video)) | 258 | const json = await videoRates(req, 'like', video, getVideoLikesActivityPubUrl(video)) |
258 | 259 | ||
259 | return activityPubResponse(activityPubContextify(json), res) | 260 | return activityPubResponse(activityPubContextify(json), res) |
260 | } | 261 | } |
261 | 262 | ||
262 | async function videoDislikesController (req: express.Request, res: express.Response) { | 263 | async function videoDislikesController (req: express.Request, res: express.Response) { |
263 | const video = res.locals.onlyVideo | 264 | const video = res.locals.onlyImmutableVideo |
264 | const json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video)) | 265 | const json = await videoRates(req, 'dislike', video, getVideoDislikesActivityPubUrl(video)) |
265 | 266 | ||
266 | return activityPubResponse(activityPubContextify(json), res) | 267 | return activityPubResponse(activityPubContextify(json), res) |
267 | } | 268 | } |
268 | 269 | ||
269 | async function videoCommentsController (req: express.Request, res: express.Response) { | 270 | async function videoCommentsController (req: express.Request, res: express.Response) { |
270 | const video = res.locals.onlyVideo | 271 | const video = res.locals.onlyImmutableVideo |
271 | 272 | ||
272 | const handler = async (start: number, count: number) => { | 273 | const handler = async (start: number, count: number) => { |
273 | const result = await VideoCommentModel.listAndCountByVideoId(video.id, start, count) | 274 | const result = await VideoCommentModel.listAndCountByVideoId(video.id, start, count) |
@@ -334,10 +335,10 @@ async function videoRedundancyController (req: express.Request, res: express.Res | |||
334 | 335 | ||
335 | if (req.path.endsWith('/activity')) { | 336 | if (req.path.endsWith('/activity')) { |
336 | const data = buildCreateActivity(videoRedundancy.url, serverActor, object, audience) | 337 | const data = buildCreateActivity(videoRedundancy.url, serverActor, object, audience) |
337 | return activityPubResponse(activityPubContextify(data), res) | 338 | return activityPubResponse(activityPubContextify(data, 'CacheFile'), res) |
338 | } | 339 | } |
339 | 340 | ||
340 | return activityPubResponse(activityPubContextify(object), res) | 341 | return activityPubResponse(activityPubContextify(object, 'CacheFile'), res) |
341 | } | 342 | } |
342 | 343 | ||
343 | async function videoPlaylistController (req: express.Request, res: express.Response) { | 344 | async function videoPlaylistController (req: express.Request, res: express.Response) { |
@@ -386,7 +387,7 @@ async function actorPlaylists (req: express.Request, account: MAccountId) { | |||
386 | return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page) | 387 | return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page) |
387 | } | 388 | } |
388 | 389 | ||
389 | function videoRates (req: express.Request, rateType: VideoRateType, video: MVideo, url: string) { | 390 | function videoRates (req: express.Request, rateType: VideoRateType, video: MVideoId, url: string) { |
390 | const handler = async (start: number, count: number) => { | 391 | const handler = async (start: number, count: number) => { |
391 | const result = await AccountVideoRateModel.listAndCountAccountUrlsByVideoId(rateType, video.id, start, count) | 392 | const result = await AccountVideoRateModel.listAndCountAccountUrlsByVideoId(rateType, video.id, start, count) |
392 | return { | 393 | return { |
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index 6138a32de..7bec6c527 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts | |||
@@ -1,5 +1,4 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as RateLimit from 'express-rate-limit' | ||
3 | import { configRouter } from './config' | 2 | import { configRouter } from './config' |
4 | import { jobsRouter } from './jobs' | 3 | import { jobsRouter } from './jobs' |
5 | import { oauthClientsRouter } from './oauth-clients' | 4 | import { oauthClientsRouter } from './oauth-clients' |
@@ -15,6 +14,7 @@ import { overviewsRouter } from './overviews' | |||
15 | import { videoPlaylistRouter } from './video-playlist' | 14 | import { videoPlaylistRouter } from './video-playlist' |
16 | import { CONFIG } from '../../initializers/config' | 15 | import { CONFIG } from '../../initializers/config' |
17 | import { pluginRouter } from './plugins' | 16 | import { pluginRouter } from './plugins' |
17 | import * as RateLimit from 'express-rate-limit' | ||
18 | 18 | ||
19 | const apiRouter = express.Router() | 19 | const apiRouter = express.Router() |
20 | 20 | ||
@@ -24,8 +24,6 @@ apiRouter.use(cors({ | |||
24 | credentials: true | 24 | credentials: true |
25 | })) | 25 | })) |
26 | 26 | ||
27 | // FIXME: https://github.com/nfriedly/express-rate-limit/issues/138 | ||
28 | // @ts-ignore | ||
29 | const apiRateLimiter = RateLimit({ | 27 | const apiRateLimiter = RateLimit({ |
30 | windowMs: CONFIG.RATES_LIMIT.API.WINDOW_MS, | 28 | windowMs: CONFIG.RATES_LIMIT.API.WINDOW_MS, |
31 | max: CONFIG.RATES_LIMIT.API.MAX | 29 | max: CONFIG.RATES_LIMIT.API.MAX |
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts index b960e80c1..0b7012537 100644 --- a/server/controllers/api/users/index.ts +++ b/server/controllers/api/users/index.ts | |||
@@ -53,8 +53,6 @@ import { Hooks } from '@server/lib/plugins/hooks' | |||
53 | 53 | ||
54 | const auditLogger = auditLoggerFactory('users') | 54 | const auditLogger = auditLoggerFactory('users') |
55 | 55 | ||
56 | // FIXME: https://github.com/nfriedly/express-rate-limit/issues/138 | ||
57 | // @ts-ignore | ||
58 | const loginRateLimiter = RateLimit({ | 56 | const loginRateLimiter = RateLimit({ |
59 | windowMs: CONFIG.RATES_LIMIT.LOGIN.WINDOW_MS, | 57 | windowMs: CONFIG.RATES_LIMIT.LOGIN.WINDOW_MS, |
60 | max: CONFIG.RATES_LIMIT.LOGIN.MAX | 58 | max: CONFIG.RATES_LIMIT.LOGIN.MAX |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 1d61f8427..eb46ea01f 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -135,7 +135,7 @@ videosRouter.get('/:id', | |||
135 | asyncMiddleware(getVideo) | 135 | asyncMiddleware(getVideo) |
136 | ) | 136 | ) |
137 | videosRouter.post('/:id/views', | 137 | videosRouter.post('/:id/views', |
138 | asyncMiddleware(videosGetValidator), | 138 | asyncMiddleware(videosCustomGetValidator('only-immutable-attributes')), |
139 | asyncMiddleware(viewVideo) | 139 | asyncMiddleware(viewVideo) |
140 | ) | 140 | ) |
141 | 141 | ||
@@ -458,7 +458,7 @@ async function getVideo (req: express.Request, res: express.Response) { | |||
458 | } | 458 | } |
459 | 459 | ||
460 | async function viewVideo (req: express.Request, res: express.Response) { | 460 | async function viewVideo (req: express.Request, res: express.Response) { |
461 | const videoInstance = res.locals.videoAll | 461 | const videoInstance = res.locals.onlyImmutableVideo |
462 | 462 | ||
463 | const ip = req.ip | 463 | const ip = req.ip |
464 | const exists = await Redis.Instance.doesVideoIPViewExist(ip, videoInstance.uuid) | 464 | const exists = await Redis.Instance.doesVideoIPViewExist(ip, videoInstance.uuid) |