diff options
author | Chocobozzz <me@florianbigard.com> | 2018-12-17 15:52:38 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-12-18 11:35:50 +0100 |
commit | 8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4 (patch) | |
tree | 5e3392af5592d1401ada86d21f93bb7ad9da8ab1 /server/middlewares/validators | |
parent | 583cd0d2129dc855e599f981d70e537feade1632 (diff) | |
download | PeerTube-8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4.tar.gz PeerTube-8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4.tar.zst PeerTube-8b9a525a180cc9f3a98c334cc052dcfc8f36dcd4.zip |
Add history on server side
Add ability to disable, clear and list user videos history
Diffstat (limited to 'server/middlewares/validators')
-rw-r--r-- | server/middlewares/validators/index.ts | 1 | ||||
-rw-r--r-- | server/middlewares/validators/user-history.ts | 30 | ||||
-rw-r--r-- | server/middlewares/validators/videos/video-watch.ts | 7 |
3 files changed, 38 insertions, 0 deletions
diff --git a/server/middlewares/validators/index.ts b/server/middlewares/validators/index.ts index 46c7f0f3a..65dd00335 100644 --- a/server/middlewares/validators/index.ts +++ b/server/middlewares/validators/index.ts | |||
@@ -12,3 +12,4 @@ export * from './videos' | |||
12 | export * from './webfinger' | 12 | export * from './webfinger' |
13 | export * from './search' | 13 | export * from './search' |
14 | export * from './server' | 14 | export * from './server' |
15 | export * from './user-history' | ||
diff --git a/server/middlewares/validators/user-history.ts b/server/middlewares/validators/user-history.ts new file mode 100644 index 000000000..3c8971ea1 --- /dev/null +++ b/server/middlewares/validators/user-history.ts | |||
@@ -0,0 +1,30 @@ | |||
1 | import * as express from 'express' | ||
2 | import 'express-validator' | ||
3 | import { body, param, query } from 'express-validator/check' | ||
4 | import { logger } from '../../helpers/logger' | ||
5 | import { areValidationErrors } from './utils' | ||
6 | import { ActorFollowModel } from '../../models/activitypub/actor-follow' | ||
7 | import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' | ||
8 | import { UserModel } from '../../models/account/user' | ||
9 | import { CONFIG } from '../../initializers' | ||
10 | import { isDateValid, toArray } from '../../helpers/custom-validators/misc' | ||
11 | |||
12 | const userHistoryRemoveValidator = [ | ||
13 | body('beforeDate') | ||
14 | .optional() | ||
15 | .custom(isDateValid).withMessage('Should have a valid before date'), | ||
16 | |||
17 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
18 | logger.debug('Checking userHistoryRemoveValidator parameters', { parameters: req.body }) | ||
19 | |||
20 | if (areValidationErrors(req, res)) return | ||
21 | |||
22 | return next() | ||
23 | } | ||
24 | ] | ||
25 | |||
26 | // --------------------------------------------------------------------------- | ||
27 | |||
28 | export { | ||
29 | userHistoryRemoveValidator | ||
30 | } | ||
diff --git a/server/middlewares/validators/videos/video-watch.ts b/server/middlewares/validators/videos/video-watch.ts index bca64662f..c38ad8a10 100644 --- a/server/middlewares/validators/videos/video-watch.ts +++ b/server/middlewares/validators/videos/video-watch.ts | |||
@@ -4,6 +4,7 @@ import { isIdOrUUIDValid } from '../../../helpers/custom-validators/misc' | |||
4 | import { isVideoExist } from '../../../helpers/custom-validators/videos' | 4 | import { isVideoExist } from '../../../helpers/custom-validators/videos' |
5 | import { areValidationErrors } from '../utils' | 5 | import { areValidationErrors } from '../utils' |
6 | import { logger } from '../../../helpers/logger' | 6 | import { logger } from '../../../helpers/logger' |
7 | import { UserModel } from '../../../models/account/user' | ||
7 | 8 | ||
8 | const videoWatchingValidator = [ | 9 | const videoWatchingValidator = [ |
9 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), | 10 | param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid id'), |
@@ -17,6 +18,12 @@ const videoWatchingValidator = [ | |||
17 | if (areValidationErrors(req, res)) return | 18 | if (areValidationErrors(req, res)) return |
18 | if (!await isVideoExist(req.params.videoId, res, 'id')) return | 19 | if (!await isVideoExist(req.params.videoId, res, 'id')) return |
19 | 20 | ||
21 | const user = res.locals.oauth.token.User as UserModel | ||
22 | if (user.videosHistoryEnabled === false) { | ||
23 | logger.warn('Cannot set videos to watch by user %d: videos history is disabled.', user.id) | ||
24 | return res.status(409).end() | ||
25 | } | ||
26 | |||
20 | return next() | 27 | return next() |
21 | } | 28 | } |
22 | ] | 29 | ] |