aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/validators/follows.ts2
-rw-r--r--server/middlewares/validators/search.ts19
-rw-r--r--server/middlewares/validators/sort.ts5
-rw-r--r--server/middlewares/validators/user-subscriptions.ts24
4 files changed, 40 insertions, 10 deletions
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts
index faefc1179..73fa28be9 100644
--- a/server/middlewares/validators/follows.ts
+++ b/server/middlewares/validators/follows.ts
@@ -38,7 +38,7 @@ const removeFollowingValidator = [
38 if (areValidationErrors(req, res)) return 38 if (areValidationErrors(req, res)) return
39 39
40 const serverActor = await getServerActor() 40 const serverActor = await getServerActor()
41 const follow = await ActorFollowModel.loadByActorAndTargetNameAndHost(serverActor.id, SERVER_ACTOR_NAME, req.params.host) 41 const follow = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(serverActor.id, SERVER_ACTOR_NAME, req.params.host)
42 42
43 if (!follow) { 43 if (!follow) {
44 return res 44 return res
diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts
index e516c4c41..8baf643a5 100644
--- a/server/middlewares/validators/search.ts
+++ b/server/middlewares/validators/search.ts
@@ -5,7 +5,7 @@ import { query } from 'express-validator/check'
5import { isNumberArray, isStringArray, isNSFWQueryValid } from '../../helpers/custom-validators/search' 5import { isNumberArray, isStringArray, isNSFWQueryValid } from '../../helpers/custom-validators/search'
6import { isBooleanValid, isDateValid, toArray } from '../../helpers/custom-validators/misc' 6import { isBooleanValid, isDateValid, toArray } from '../../helpers/custom-validators/misc'
7 7
8const searchValidator = [ 8const videosSearchValidator = [
9 query('search').optional().not().isEmpty().withMessage('Should have a valid search'), 9 query('search').optional().not().isEmpty().withMessage('Should have a valid search'),
10 10
11 query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'), 11 query('startDate').optional().custom(isDateValid).withMessage('Should have a valid start date'),
@@ -15,7 +15,19 @@ const searchValidator = [
15 query('durationMax').optional().isInt().withMessage('Should have a valid max duration'), 15 query('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
16 16
17 (req: express.Request, res: express.Response, next: express.NextFunction) => { 17 (req: express.Request, res: express.Response, next: express.NextFunction) => {
18 logger.debug('Checking search query', { parameters: req.query }) 18 logger.debug('Checking videos search query', { parameters: req.query })
19
20 if (areValidationErrors(req, res)) return
21
22 return next()
23 }
24]
25
26const videoChannelsSearchValidator = [
27 query('search').not().isEmpty().withMessage('Should have a valid search'),
28
29 (req: express.Request, res: express.Response, next: express.NextFunction) => {
30 logger.debug('Checking video channels search query', { parameters: req.query })
19 31
20 if (areValidationErrors(req, res)) return 32 if (areValidationErrors(req, res)) return
21 33
@@ -61,5 +73,6 @@ const commonVideosFiltersValidator = [
61 73
62export { 74export {
63 commonVideosFiltersValidator, 75 commonVideosFiltersValidator,
64 searchValidator 76 videoChannelsSearchValidator,
77 videosSearchValidator
65} 78}
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts
index b30e97e61..08dcc2680 100644
--- a/server/middlewares/validators/sort.ts
+++ b/server/middlewares/validators/sort.ts
@@ -8,6 +8,7 @@ const SORTABLE_JOBS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.JOBS)
8const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) 8const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES)
9const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) 9const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS)
10const SORTABLE_VIDEOS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS_SEARCH) 10const SORTABLE_VIDEOS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS_SEARCH)
11const SORTABLE_VIDEO_CHANNELS_SEARCH_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS_SEARCH)
11const SORTABLE_VIDEO_IMPORTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_IMPORTS) 12const SORTABLE_VIDEO_IMPORTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_IMPORTS)
12const SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS) 13const SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_COMMENT_THREADS)
13const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS) 14const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS)
@@ -23,6 +24,7 @@ const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS)
23const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) 24const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS)
24const videoImportsSortValidator = checkSort(SORTABLE_VIDEO_IMPORTS_COLUMNS) 25const videoImportsSortValidator = checkSort(SORTABLE_VIDEO_IMPORTS_COLUMNS)
25const videosSearchSortValidator = checkSort(SORTABLE_VIDEOS_SEARCH_COLUMNS) 26const videosSearchSortValidator = checkSort(SORTABLE_VIDEOS_SEARCH_COLUMNS)
27const videoChannelsSearchSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_SEARCH_COLUMNS)
26const videoCommentThreadsSortValidator = checkSort(SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS) 28const videoCommentThreadsSortValidator = checkSort(SORTABLE_VIDEO_COMMENT_THREADS_COLUMNS)
27const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS) 29const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS)
28const videoChannelsSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_COLUMNS) 30const videoChannelsSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_COLUMNS)
@@ -45,5 +47,6 @@ export {
45 followingSortValidator, 47 followingSortValidator,
46 jobsSortValidator, 48 jobsSortValidator,
47 videoCommentThreadsSortValidator, 49 videoCommentThreadsSortValidator,
48 userSubscriptionsSortValidator 50 userSubscriptionsSortValidator,
51 videoChannelsSearchSortValidator
49} 52}
diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.ts
index d8c26c742..c5f8d9d4c 100644
--- a/server/middlewares/validators/user-subscriptions.ts
+++ b/server/middlewares/validators/user-subscriptions.ts
@@ -1,12 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { body, param } from 'express-validator/check' 3import { body, param, query } from 'express-validator/check'
4import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
6import { ActorFollowModel } from '../../models/activitypub/actor-follow' 6import { ActorFollowModel } from '../../models/activitypub/actor-follow'
7import { isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' 7import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor'
8import { UserModel } from '../../models/account/user' 8import { UserModel } from '../../models/account/user'
9import { CONFIG } from '../../initializers' 9import { CONFIG } from '../../initializers'
10import { toArray } from '../../helpers/custom-validators/misc'
10 11
11const userSubscriptionAddValidator = [ 12const userSubscriptionAddValidator = [
12 body('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to follow (username@domain)'), 13 body('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to follow (username@domain)'),
@@ -20,6 +21,20 @@ const userSubscriptionAddValidator = [
20 } 21 }
21] 22]
22 23
24const areSubscriptionsExistValidator = [
25 query('uris')
26 .customSanitizer(toArray)
27 .custom(areValidActorHandles).withMessage('Should have a valid uri array'),
28
29 (req: express.Request, res: express.Response, next: express.NextFunction) => {
30 logger.debug('Checking areSubscriptionsExistValidator parameters', { parameters: req.query })
31
32 if (areValidationErrors(req, res)) return
33
34 return next()
35 }
36]
37
23const userSubscriptionGetValidator = [ 38const userSubscriptionGetValidator = [
24 param('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to unfollow'), 39 param('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to unfollow'),
25 40
@@ -32,7 +47,7 @@ const userSubscriptionGetValidator = [
32 if (host === CONFIG.WEBSERVER.HOST) host = null 47 if (host === CONFIG.WEBSERVER.HOST) host = null
33 48
34 const user: UserModel = res.locals.oauth.token.User 49 const user: UserModel = res.locals.oauth.token.User
35 const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHost(user.Account.Actor.id, name, host) 50 const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(user.Account.Actor.id, name, host)
36 51
37 if (!subscription || !subscription.ActorFollowing.VideoChannel) { 52 if (!subscription || !subscription.ActorFollowing.VideoChannel) {
38 return res 53 return res
@@ -51,8 +66,7 @@ const userSubscriptionGetValidator = [
51// --------------------------------------------------------------------------- 66// ---------------------------------------------------------------------------
52 67
53export { 68export {
69 areSubscriptionsExistValidator,
54 userSubscriptionAddValidator, 70 userSubscriptionAddValidator,
55 userSubscriptionGetValidator 71 userSubscriptionGetValidator
56} 72}
57
58// ---------------------------------------------------------------------------