aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-13 17:39:41 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commit7a7724e66e4533523083e7336cd0d0c747c4a33b (patch)
tree805299eb9c6829158cd17e5a823a84a3a54d8209 /server/middlewares
parent571389d43b8fc8aaf27e77c06f19b320b08dbbc9 (diff)
downloadPeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.tar.gz
PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.tar.zst
PeerTube-7a7724e66e4533523083e7336cd0d0c747c4a33b.zip
Handle follow/accept
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/sort.ts16
-rw-r--r--server/middlewares/validators/account.ts25
-rw-r--r--server/middlewares/validators/sort.ts11
3 files changed, 35 insertions, 17 deletions
diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts
index 91aa3e5b6..20ae341f0 100644
--- a/server/middlewares/sort.ts
+++ b/server/middlewares/sort.ts
@@ -34,6 +34,18 @@ function setVideosSort (req: express.Request, res: express.Response, next: expre
34 return next() 34 return next()
35} 35}
36 36
37function setFollowersSort (req: express.Request, res: express.Response, next: express.NextFunction) {
38 if (!req.query.sort) req.query.sort = '-createdAt'
39
40 return next()
41}
42
43function setFollowingSort (req: express.Request, res: express.Response, next: express.NextFunction) {
44 if (!req.query.sort) req.query.sort = '-createdAt'
45
46 return next()
47}
48
37function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) { 49function setBlacklistSort (req: express.Request, res: express.Response, next: express.NextFunction) {
38 let newSort: SortType = { sortModel: undefined, sortValue: undefined } 50 let newSort: SortType = { sortModel: undefined, sortValue: undefined }
39 51
@@ -63,5 +75,7 @@ export {
63 setVideoAbusesSort, 75 setVideoAbusesSort,
64 setVideoChannelsSort, 76 setVideoChannelsSort,
65 setVideosSort, 77 setVideosSort,
66 setBlacklistSort 78 setBlacklistSort,
79 setFollowersSort,
80 setFollowingSort
67} 81}
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts
index 5abe942d6..3ccf2ea21 100644
--- a/server/middlewares/validators/account.ts
+++ b/server/middlewares/validators/account.ts
@@ -1,21 +1,20 @@
1import { param } from 'express-validator/check'
2import * as express from 'express' 1import * as express from 'express'
3 2import { param } from 'express-validator/check'
4import { database as db } from '../../initializers/database'
5import { checkErrors } from './utils'
6import { 3import {
7 logger,
8 isUserUsernameValid,
9 isUserPasswordValid,
10 isUserVideoQuotaValid,
11 isUserDisplayNSFWValid, 4 isUserDisplayNSFWValid,
5 isUserPasswordValid,
12 isUserRoleValid, 6 isUserRoleValid,
13 isAccountNameValid 7 isUserUsernameValid,
8 isUserVideoQuotaValid,
9 logger
14} from '../../helpers' 10} from '../../helpers'
11import { isAccountNameWithHostValid } from '../../helpers/custom-validators/video-accounts'
12import { database as db } from '../../initializers/database'
15import { AccountInstance } from '../../models' 13import { AccountInstance } from '../../models'
14import { checkErrors } from './utils'
16 15
17const localAccountValidator = [ 16const localAccountValidator = [
18 param('name').custom(isAccountNameValid).withMessage('Should have a valid account name'), 17 param('nameWithHost').custom(isAccountNameWithHostValid).withMessage('Should have a valid account with domain name (myuser@domain.tld)'),
19 18
20 (req: express.Request, res: express.Response, next: express.NextFunction) => { 19 (req: express.Request, res: express.Response, next: express.NextFunction) => {
21 logger.debug('Checking localAccountValidator parameters', { parameters: req.params }) 20 logger.debug('Checking localAccountValidator parameters', { parameters: req.params })
@@ -34,8 +33,10 @@ export {
34 33
35// --------------------------------------------------------------------------- 34// ---------------------------------------------------------------------------
36 35
37function checkLocalAccountExists (name: string, res: express.Response, callback: (err: Error, account: AccountInstance) => void) { 36function checkLocalAccountExists (nameWithHost: string, res: express.Response, callback: (err: Error, account: AccountInstance) => void) {
38 db.Account.loadLocalAccountByName(name) 37 const [ name, host ] = nameWithHost.split('@')
38
39 db.Account.loadLocalAccountByNameAndPod(name, host)
39 .then(account => { 40 .then(account => {
40 if (!account) { 41 if (!account) {
41 return res.status(404) 42 return res.status(404)
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts
index d23a95537..6fea41bb8 100644
--- a/server/middlewares/validators/sort.ts
+++ b/server/middlewares/validators/sort.ts
@@ -6,29 +6,32 @@ import { logger } from '../../helpers'
6import { SORTABLE_COLUMNS } from '../../initializers' 6import { SORTABLE_COLUMNS } from '../../initializers'
7 7
8// Initialize constants here for better performances 8// Initialize constants here for better performances
9const SORTABLE_PODS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.PODS)
10const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS) 9const SORTABLE_USERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.USERS)
11const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES) 10const SORTABLE_VIDEO_ABUSES_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_ABUSES)
12const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS) 11const SORTABLE_VIDEOS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEOS)
13const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS) 12const SORTABLE_BLACKLISTS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.BLACKLISTS)
14const SORTABLE_VIDEO_CHANNELS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS) 13const SORTABLE_VIDEO_CHANNELS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.VIDEO_CHANNELS)
14const SORTABLE_FOLLOWERS_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.FOLLOWERS)
15const SORTABLE_FOLLOWING_COLUMNS = createSortableColumns(SORTABLE_COLUMNS.FOLLOWING)
15 16
16const podsSortValidator = checkSort(SORTABLE_PODS_COLUMNS)
17const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS) 17const usersSortValidator = checkSort(SORTABLE_USERS_COLUMNS)
18const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS) 18const videoAbusesSortValidator = checkSort(SORTABLE_VIDEO_ABUSES_COLUMNS)
19const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS) 19const videosSortValidator = checkSort(SORTABLE_VIDEOS_COLUMNS)
20const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS) 20const blacklistSortValidator = checkSort(SORTABLE_BLACKLISTS_COLUMNS)
21const videoChannelsSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_COLUMNS) 21const videoChannelsSortValidator = checkSort(SORTABLE_VIDEO_CHANNELS_COLUMNS)
22const followersSortValidator = checkSort(SORTABLE_FOLLOWERS_COLUMNS)
23const followingSortValidator = checkSort(SORTABLE_FOLLOWING_COLUMNS)
22 24
23// --------------------------------------------------------------------------- 25// ---------------------------------------------------------------------------
24 26
25export { 27export {
26 podsSortValidator,
27 usersSortValidator, 28 usersSortValidator,
28 videoAbusesSortValidator, 29 videoAbusesSortValidator,
29 videoChannelsSortValidator, 30 videoChannelsSortValidator,
30 videosSortValidator, 31 videosSortValidator,
31 blacklistSortValidator 32 blacklistSortValidator,
33 followersSortValidator,
34 followingSortValidator
32} 35}
33 36
34// --------------------------------------------------------------------------- 37// ---------------------------------------------------------------------------