aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-28 11:16:08 +0100
committerChocobozzz <me@florianbigard.com>2017-12-28 11:16:08 +0100
commitda854ddd502cd70685ef779c673b9e63757b8aa0 (patch)
tree21501d170cceaa044a5f23449cbd2eb47fd6415d /server/middlewares
parentf40bbe3146553ef45515ee6b6d93ce6028f045ca (diff)
downloadPeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.tar.gz
PeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.tar.zst
PeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.zip
Propagate old comment on new follow
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/activitypub.ts3
-rw-r--r--server/middlewares/oauth.ts3
-rw-r--r--server/middlewares/servers.ts2
-rw-r--r--server/middlewares/sort.ts2
-rw-r--r--server/middlewares/user-right.ts2
-rw-r--r--server/middlewares/validators/account.ts2
-rw-r--r--server/middlewares/validators/activitypub/activity.ts4
-rw-r--r--server/middlewares/validators/activitypub/signature.ts7
-rw-r--r--server/middlewares/validators/follows.ts4
-rw-r--r--server/middlewares/validators/oembed.ts3
-rw-r--r--server/middlewares/validators/pagination.ts2
-rw-r--r--server/middlewares/validators/sort.ts4
-rw-r--r--server/middlewares/validators/users.ts9
-rw-r--r--server/middlewares/validators/utils.ts2
-rw-r--r--server/middlewares/validators/video-blacklist.ts2
-rw-r--r--server/middlewares/validators/video-channels.ts5
-rw-r--r--server/middlewares/validators/video-comments.ts22
-rw-r--r--server/middlewares/validators/videos.ts17
-rw-r--r--server/middlewares/validators/webfinger.ts3
19 files changed, 54 insertions, 44 deletions
diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts
index c00a6affa..1488b42ab 100644
--- a/server/middlewares/activitypub.ts
+++ b/server/middlewares/activitypub.ts
@@ -1,7 +1,8 @@
1import { eachSeries } from 'async' 1import { eachSeries } from 'async'
2import { NextFunction, Request, RequestHandler, Response } from 'express' 2import { NextFunction, Request, RequestHandler, Response } from 'express'
3import { ActivityPubSignature } from '../../shared' 3import { ActivityPubSignature } from '../../shared'
4import { isSignatureVerified, logger } from '../helpers' 4import { logger } from '../helpers/logger'
5import { isSignatureVerified } from '../helpers/peertube-crypto'
5import { ACCEPT_HEADERS, ACTIVITY_PUB } from '../initializers' 6import { ACCEPT_HEADERS, ACTIVITY_PUB } from '../initializers'
6import { getOrCreateActorAndServerAndModel } from '../lib/activitypub' 7import { getOrCreateActorAndServerAndModel } from '../lib/activitypub'
7import { ActorModel } from '../models/activitypub/actor' 8import { ActorModel } from '../models/activitypub/actor'
diff --git a/server/middlewares/oauth.ts b/server/middlewares/oauth.ts
index 3faecdbcc..e59168ea8 100644
--- a/server/middlewares/oauth.ts
+++ b/server/middlewares/oauth.ts
@@ -1,9 +1,8 @@
1import 'express-validator' 1import 'express-validator'
2import * as express from 'express' 2import * as express from 'express'
3import * as OAuthServer from 'express-oauth-server' 3import * as OAuthServer from 'express-oauth-server'
4 4import { logger } from '../helpers/logger'
5import { OAUTH_LIFETIME } from '../initializers' 5import { OAUTH_LIFETIME } from '../initializers'
6import { logger } from '../helpers'
7 6
8const oAuthServer = new OAuthServer({ 7const oAuthServer = new OAuthServer({
9 accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN, 8 accessTokenLifetime: OAUTH_LIFETIME.ACCESS_TOKEN,
diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts
index e16bc4a86..a9dcad2d4 100644
--- a/server/middlewares/servers.ts
+++ b/server/middlewares/servers.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { getHostWithPort } from '../helpers' 3import { getHostWithPort } from '../helpers/utils'
4 4
5function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) { 5function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
6 if (!req.body.hosts) return next() 6 if (!req.body.hosts) return next()
diff --git a/server/middlewares/sort.ts b/server/middlewares/sort.ts
index 0eb50db89..fdd6d419f 100644
--- a/server/middlewares/sort.ts
+++ b/server/middlewares/sort.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { SortType } from '../helpers' 3import { SortType } from '../helpers/utils'
4 4
5function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) { 5function setUsersSort (req: express.Request, res: express.Response, next: express.NextFunction) {
6 if (!req.query.sort) req.query.sort = '-createdAt' 6 if (!req.query.sort) req.query.sort = '-createdAt'
diff --git a/server/middlewares/user-right.ts b/server/middlewares/user-right.ts
index 5d63ebaf4..5bb5bdfbd 100644
--- a/server/middlewares/user-right.ts
+++ b/server/middlewares/user-right.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { UserRight } from '../../shared' 3import { UserRight } from '../../shared'
4import { logger } from '../helpers' 4import { logger } from '../helpers/logger'
5import { UserModel } from '../models/account/user' 5import { UserModel } from '../models/account/user'
6 6
7function ensureUserHasRight (userRight: UserRight) { 7function ensureUserHasRight (userRight: UserRight) {
diff --git a/server/middlewares/validators/account.ts b/server/middlewares/validators/account.ts
index 6951dfc80..3573a9a50 100644
--- a/server/middlewares/validators/account.ts
+++ b/server/middlewares/validators/account.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator/check' 2import { param } from 'express-validator/check'
3import { logger } from '../../helpers'
4import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts' 3import { isAccountNameValid, isLocalAccountNameExist } from '../../helpers/custom-validators/accounts'
4import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
6 6
7const localAccountValidator = [ 7const localAccountValidator = [
diff --git a/server/middlewares/validators/activitypub/activity.ts b/server/middlewares/validators/activitypub/activity.ts
index e0225f30c..208e23f86 100644
--- a/server/middlewares/validators/activitypub/activity.ts
+++ b/server/middlewares/validators/activitypub/activity.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator/check' 2import { body } from 'express-validator/check'
3import { logger } from '../../../helpers' 3import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub/activity'
4import { isRootActivityValid } from '../../../helpers/custom-validators/activitypub' 4import { logger } from '../../../helpers/logger'
5import { areValidationErrors } from '../utils' 5import { areValidationErrors } from '../utils'
6 6
7const activityPubValidator = [ 7const activityPubValidator = [
diff --git a/server/middlewares/validators/activitypub/signature.ts b/server/middlewares/validators/activitypub/signature.ts
index d41bb6a8d..4efe9aafa 100644
--- a/server/middlewares/validators/activitypub/signature.ts
+++ b/server/middlewares/validators/activitypub/signature.ts
@@ -1,8 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator/check' 2import { body } from 'express-validator/check'
3import { logger } from '../../../helpers' 3import {
4import { isSignatureCreatorValid, isSignatureTypeValid, isSignatureValueValid } from '../../../helpers/custom-validators/activitypub' 4 isSignatureCreatorValid, isSignatureTypeValid,
5 isSignatureValueValid
6} from '../../../helpers/custom-validators/activitypub/signature'
5import { isDateValid } from '../../../helpers/custom-validators/misc' 7import { isDateValid } from '../../../helpers/custom-validators/misc'
8import { logger } from '../../../helpers/logger'
6import { areValidationErrors } from '../utils' 9import { areValidationErrors } from '../utils'
7 10
8const signatureValidator = [ 11const signatureValidator = [
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts
index 2240d30db..7dadf6a19 100644
--- a/server/middlewares/validators/follows.ts
+++ b/server/middlewares/validators/follows.ts
@@ -1,7 +1,9 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { getServerActor, isTestInstance, logger } from '../../helpers' 3import { isTestInstance } from '../../helpers/core-utils'
4import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' 4import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers'
5import { logger } from '../../helpers/logger'
6import { getServerActor } from '../../helpers/utils'
5import { CONFIG } from '../../initializers' 7import { CONFIG } from '../../initializers'
6import { ActorFollowModel } from '../../models/activitypub/actor-follow' 8import { ActorFollowModel } from '../../models/activitypub/actor-follow'
7import { areValidationErrors } from './utils' 9import { areValidationErrors } from './utils'
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts
index fb7b726e5..cd9b27b16 100644
--- a/server/middlewares/validators/oembed.ts
+++ b/server/middlewares/validators/oembed.ts
@@ -1,9 +1,10 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator/check' 2import { query } from 'express-validator/check'
3import { join } from 'path' 3import { join } from 'path'
4import { isTestInstance, logger } from '../../helpers' 4import { isTestInstance } from '../../helpers/core-utils'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
6import { isVideoExist } from '../../helpers/custom-validators/videos' 6import { isVideoExist } from '../../helpers/custom-validators/videos'
7import { logger } from '../../helpers/logger'
7import { CONFIG } from '../../initializers' 8import { CONFIG } from '../../initializers'
8import { areValidationErrors } from './utils' 9import { areValidationErrors } from './utils'
9 10
diff --git a/server/middlewares/validators/pagination.ts b/server/middlewares/validators/pagination.ts
index 25debfa6e..e1ed8cd65 100644
--- a/server/middlewares/validators/pagination.ts
+++ b/server/middlewares/validators/pagination.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator/check' 2import { query } from 'express-validator/check'
3import { logger } from '../../helpers' 3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
5 5
6const paginationValidator = [ 6const paginationValidator = [
diff --git a/server/middlewares/validators/sort.ts b/server/middlewares/validators/sort.ts
index 56855bda0..e1d8d7d1b 100644
--- a/server/middlewares/validators/sort.ts
+++ b/server/middlewares/validators/sort.ts
@@ -1,6 +1,6 @@
1import { query } from 'express-validator/check'
2import * as express from 'express' 1import * as express from 'express'
3import { logger } from '../../helpers' 2import { query } from 'express-validator/check'
3import { logger } from '../../helpers/logger'
4import { SORTABLE_COLUMNS } from '../../initializers' 4import { SORTABLE_COLUMNS } from '../../initializers'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
6 6
diff --git a/server/middlewares/validators/users.ts b/server/middlewares/validators/users.ts
index a6fdbe268..db40a5c88 100644
--- a/server/middlewares/validators/users.ts
+++ b/server/middlewares/validators/users.ts
@@ -1,17 +1,14 @@
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 } from 'express-validator/check'
4import { isSignupAllowed, logger } from '../../helpers'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 4import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
6import { 5import {
7 isUserDisplayNSFWValid, 6 isUserAutoPlayVideoValid, isUserDisplayNSFWValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid,
8 isUserAutoPlayVideoValid,
9 isUserPasswordValid,
10 isUserRoleValid,
11 isUserUsernameValid,
12 isUserVideoQuotaValid 7 isUserVideoQuotaValid
13} from '../../helpers/custom-validators/users' 8} from '../../helpers/custom-validators/users'
14import { isVideoExist } from '../../helpers/custom-validators/videos' 9import { isVideoExist } from '../../helpers/custom-validators/videos'
10import { logger } from '../../helpers/logger'
11import { isSignupAllowed } from '../../helpers/utils'
15import { UserModel } from '../../models/account/user' 12import { UserModel } from '../../models/account/user'
16import { areValidationErrors } from './utils' 13import { areValidationErrors } from './utils'
17 14
diff --git a/server/middlewares/validators/utils.ts b/server/middlewares/validators/utils.ts
index 61f76b457..55b140103 100644
--- a/server/middlewares/validators/utils.ts
+++ b/server/middlewares/validators/utils.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { validationResult } from 'express-validator/check' 2import { validationResult } from 'express-validator/check'
3import { logger } from '../../helpers' 3import { logger } from '../../helpers/logger'
4 4
5function areValidationErrors (req: express.Request, res: express.Response) { 5function areValidationErrors (req: express.Request, res: express.Response) {
6 const errors = validationResult(req) 6 const errors = validationResult(req)
diff --git a/server/middlewares/validators/video-blacklist.ts b/server/middlewares/validators/video-blacklist.ts
index 98099fe3f..3c1ef1b4e 100644
--- a/server/middlewares/validators/video-blacklist.ts
+++ b/server/middlewares/validators/video-blacklist.ts
@@ -1,8 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import { param } from 'express-validator/check' 2import { param } from 'express-validator/check'
3import { logger } from '../../helpers'
4import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
5import { isVideoExist } from '../../helpers/custom-validators/videos' 4import { isVideoExist } from '../../helpers/custom-validators/videos'
5import { logger } from '../../helpers/logger'
6import { VideoModel } from '../../models/video/video' 6import { VideoModel } from '../../models/video/video'
7import { VideoBlacklistModel } from '../../models/video/video-blacklist' 7import { VideoBlacklistModel } from '../../models/video/video-blacklist'
8import { areValidationErrors } from './utils' 8import { areValidationErrors } from './utils'
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts
index 0e6eff493..86bddde82 100644
--- a/server/middlewares/validators/video-channels.ts
+++ b/server/middlewares/validators/video-channels.ts
@@ -1,14 +1,13 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { UserRight } from '../../../shared' 3import { UserRight } from '../../../shared'
4import { logger } from '../../helpers'
5import { isAccountIdExist } from '../../helpers/custom-validators/accounts' 4import { isAccountIdExist } from '../../helpers/custom-validators/accounts'
6import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
7import { 6import {
8 isVideoChannelDescriptionValid, 7 isVideoChannelDescriptionValid, isVideoChannelExist,
9 isVideoChannelExist,
10 isVideoChannelNameValid 8 isVideoChannelNameValid
11} from '../../helpers/custom-validators/video-channels' 9} from '../../helpers/custom-validators/video-channels'
10import { logger } from '../../helpers/logger'
12import { UserModel } from '../../models/account/user' 11import { UserModel } from '../../models/account/user'
13import { VideoChannelModel } from '../../models/video/video-channel' 12import { VideoChannelModel } from '../../models/video/video-channel'
14import { areValidationErrors } from './utils' 13import { areValidationErrors } from './utils'
diff --git a/server/middlewares/validators/video-comments.ts b/server/middlewares/validators/video-comments.ts
index 1d19fac58..fdd092571 100644
--- a/server/middlewares/validators/video-comments.ts
+++ b/server/middlewares/validators/video-comments.ts
@@ -1,9 +1,9 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body, param } from 'express-validator/check' 2import { body, param } from 'express-validator/check'
3import { logger } from '../../helpers'
4import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' 3import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
5import { isValidVideoCommentText } from '../../helpers/custom-validators/video-comments' 4import { isValidVideoCommentText } from '../../helpers/custom-validators/video-comments'
6import { isVideoExist } from '../../helpers/custom-validators/videos' 5import { isVideoExist } from '../../helpers/custom-validators/videos'
6import { logger } from '../../helpers/logger'
7import { VideoModel } from '../../models/video/video' 7import { VideoModel } from '../../models/video/video'
8import { VideoCommentModel } from '../../models/video/video-comment' 8import { VideoCommentModel } from '../../models/video/video-comment'
9import { areValidationErrors } from './utils' 9import { areValidationErrors } from './utils'
@@ -66,13 +66,29 @@ const addVideoCommentReplyValidator = [
66 } 66 }
67] 67]
68 68
69const videoCommentGetValidator = [
70 param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid videoId'),
71 param('commentId').custom(isIdValid).not().isEmpty().withMessage('Should have a valid commentId'),
72
73 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
74 logger.debug('Checking videoCommentGetValidator parameters.', { parameters: req.params })
75
76 if (areValidationErrors(req, res)) return
77 if (!await isVideoExist(req.params.videoId, res)) return
78 if (!await isVideoCommentExist(req.params.commentId, res.locals.video, res)) return
79
80 return next()
81 }
82]
83
69// --------------------------------------------------------------------------- 84// ---------------------------------------------------------------------------
70 85
71export { 86export {
72 listVideoCommentThreadsValidator, 87 listVideoCommentThreadsValidator,
73 listVideoThreadCommentsValidator, 88 listVideoThreadCommentsValidator,
74 addVideoCommentThreadValidator, 89 addVideoCommentThreadValidator,
75 addVideoCommentReplyValidator 90 addVideoCommentReplyValidator,
91 videoCommentGetValidator
76} 92}
77 93
78// --------------------------------------------------------------------------- 94// ---------------------------------------------------------------------------
@@ -109,7 +125,7 @@ async function isVideoCommentThreadExist (id: number, video: VideoModel, res: ex
109} 125}
110 126
111async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) { 127async function isVideoCommentExist (id: number, video: VideoModel, res: express.Response) {
112 const videoComment = await VideoCommentModel.loadById(id) 128 const videoComment = await VideoCommentModel.loadByIdAndPopulateVideoAndAccountAndReply(id)
113 129
114 if (!videoComment) { 130 if (!videoComment) {
115 res.status(404) 131 res.status(404)
diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts
index b52d5f285..bffc50322 100644
--- a/server/middlewares/validators/videos.ts
+++ b/server/middlewares/validators/videos.ts
@@ -2,22 +2,13 @@ import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import { body, param, query } from 'express-validator/check' 3import { body, param, query } from 'express-validator/check'
4import { UserRight, VideoPrivacy } from '../../../shared' 4import { UserRight, VideoPrivacy } from '../../../shared'
5import { getDurationFromVideoFile, logger } from '../../helpers'
6import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc' 5import { isIdOrUUIDValid, isIdValid } from '../../helpers/custom-validators/misc'
7import { 6import {
8 isVideoAbuseReasonValid, 7 isVideoAbuseReasonValid, isVideoCategoryValid, isVideoDescriptionValid, isVideoExist, isVideoFile, isVideoLanguageValid,
9 isVideoCategoryValid, 8 isVideoLicenceValid, isVideoNameValid, isVideoNSFWValid, isVideoPrivacyValid, isVideoRatingTypeValid, isVideoTagsValid
10 isVideoDescriptionValid,
11 isVideoExist,
12 isVideoFile,
13 isVideoLanguageValid,
14 isVideoLicenceValid,
15 isVideoNameValid,
16 isVideoNSFWValid,
17 isVideoPrivacyValid,
18 isVideoRatingTypeValid,
19 isVideoTagsValid
20} from '../../helpers/custom-validators/videos' 9} from '../../helpers/custom-validators/videos'
10import { getDurationFromVideoFile } from '../../helpers/ffmpeg-utils'
11import { logger } from '../../helpers/logger'
21import { CONSTRAINTS_FIELDS } from '../../initializers' 12import { CONSTRAINTS_FIELDS } from '../../initializers'
22import { UserModel } from '../../models/account/user' 13import { UserModel } from '../../models/account/user'
23import { VideoModel } from '../../models/video/video' 14import { VideoModel } from '../../models/video/video'
diff --git a/server/middlewares/validators/webfinger.ts b/server/middlewares/validators/webfinger.ts
index 894c72498..3dbec6e44 100644
--- a/server/middlewares/validators/webfinger.ts
+++ b/server/middlewares/validators/webfinger.ts
@@ -1,7 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import { query } from 'express-validator/check' 2import { query } from 'express-validator/check'
3import { getHostWithPort, logger } from '../../helpers'
4import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger' 3import { isWebfingerResourceValid } from '../../helpers/custom-validators/webfinger'
4import { logger } from '../../helpers/logger'
5import { getHostWithPort } from '../../helpers/utils'
5import { ActorModel } from '../../models/activitypub/actor' 6import { ActorModel } from '../../models/activitypub/actor'
6import { areValidationErrors } from './utils' 7import { areValidationErrors } from './utils'
7 8