aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/users/my-history.ts4
-rw-r--r--server/middlewares/validators/user-history.ts19
-rw-r--r--server/models/account/user-video-history.ts3
-rw-r--r--server/models/video/video.ts4
-rw-r--r--server/tests/api/videos/videos-history.ts9
5 files changed, 34 insertions, 5 deletions
diff --git a/server/controllers/api/users/my-history.ts b/server/controllers/api/users/my-history.ts
index 80d4dc748..72c7da373 100644
--- a/server/controllers/api/users/my-history.ts
+++ b/server/controllers/api/users/my-history.ts
@@ -5,6 +5,7 @@ import {
5 authenticate, 5 authenticate,
6 paginationValidator, 6 paginationValidator,
7 setDefaultPagination, 7 setDefaultPagination,
8 userHistoryListValidator,
8 userHistoryRemoveValidator 9 userHistoryRemoveValidator
9} from '../../../middlewares' 10} from '../../../middlewares'
10import { getFormattedObjects } from '../../../helpers/utils' 11import { getFormattedObjects } from '../../../helpers/utils'
@@ -18,6 +19,7 @@ myVideosHistoryRouter.get('/me/history/videos',
18 authenticate, 19 authenticate,
19 paginationValidator, 20 paginationValidator,
20 setDefaultPagination, 21 setDefaultPagination,
22 userHistoryListValidator,
21 asyncMiddleware(listMyVideosHistory) 23 asyncMiddleware(listMyVideosHistory)
22) 24)
23 25
@@ -38,7 +40,7 @@ export {
38async function listMyVideosHistory (req: express.Request, res: express.Response) { 40async function listMyVideosHistory (req: express.Request, res: express.Response) {
39 const user = res.locals.oauth.token.User 41 const user = res.locals.oauth.token.User
40 42
41 const resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count) 43 const resultList = await UserVideoHistoryModel.listForApi(user, req.query.start, req.query.count, req.query.search)
42 44
43 return res.json(getFormattedObjects(resultList.data, resultList.total)) 45 return res.json(getFormattedObjects(resultList.data, resultList.total))
44} 46}
diff --git a/server/middlewares/validators/user-history.ts b/server/middlewares/validators/user-history.ts
index 2f1d3cc41..058bf7758 100644
--- a/server/middlewares/validators/user-history.ts
+++ b/server/middlewares/validators/user-history.ts
@@ -1,8 +1,22 @@
1import * as express from 'express' 1import * as express from 'express'
2import { body } from 'express-validator' 2import { body, query } from 'express-validator'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
5import { isDateValid } from '../../helpers/custom-validators/misc' 5import { exists, isDateValid } from '../../helpers/custom-validators/misc'
6
7const userHistoryListValidator = [
8 query('search')
9 .optional()
10 .custom(exists).withMessage('Should have a valid search'),
11
12 (req: express.Request, res: express.Response, next: express.NextFunction) => {
13 logger.debug('Checking userHistoryListValidator parameters', { parameters: req.query })
14
15 if (areValidationErrors(req, res)) return
16
17 return next()
18 }
19]
6 20
7const userHistoryRemoveValidator = [ 21const userHistoryRemoveValidator = [
8 body('beforeDate') 22 body('beforeDate')
@@ -21,5 +35,6 @@ const userHistoryRemoveValidator = [
21// --------------------------------------------------------------------------- 35// ---------------------------------------------------------------------------
22 36
23export { 37export {
38 userHistoryListValidator,
24 userHistoryRemoveValidator 39 userHistoryRemoveValidator
25} 40}
diff --git a/server/models/account/user-video-history.ts b/server/models/account/user-video-history.ts
index 45171fc60..6be1d65ea 100644
--- a/server/models/account/user-video-history.ts
+++ b/server/models/account/user-video-history.ts
@@ -55,10 +55,11 @@ export class UserVideoHistoryModel extends Model {
55 }) 55 })
56 User: UserModel 56 User: UserModel
57 57
58 static listForApi (user: MUserAccountId, start: number, count: number) { 58 static listForApi (user: MUserAccountId, start: number, count: number, search?: string) {
59 return VideoModel.listForApi({ 59 return VideoModel.listForApi({
60 start, 60 start,
61 count, 61 count,
62 search,
62 sort: '-"userVideoHistory"."updatedAt"', 63 sort: '-"userVideoHistory"."updatedAt"',
63 nsfw: null, // All 64 nsfw: null, // All
64 includeLocalVideos: true, 65 includeLocalVideos: true,
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index abf823d4b..5027e980d 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1087,6 +1087,7 @@ export class VideoModel extends Model {
1087 user?: MUserAccountId 1087 user?: MUserAccountId
1088 historyOfUser?: MUserId 1088 historyOfUser?: MUserId
1089 countVideos?: boolean 1089 countVideos?: boolean
1090 search?: string
1090 }) { 1091 }) {
1091 if ((options.filter === 'all-local' || options.filter === 'all') && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) { 1092 if ((options.filter === 'all-local' || options.filter === 'all') && !options.user.hasRight(UserRight.SEE_ALL_VIDEOS)) {
1092 throw new Error('Try to filter all-local but no user has not the see all videos right') 1093 throw new Error('Try to filter all-local but no user has not the see all videos right')
@@ -1123,7 +1124,8 @@ export class VideoModel extends Model {
1123 includeLocalVideos: options.includeLocalVideos, 1124 includeLocalVideos: options.includeLocalVideos,
1124 user: options.user, 1125 user: options.user,
1125 historyOfUser: options.historyOfUser, 1126 historyOfUser: options.historyOfUser,
1126 trendingDays 1127 trendingDays,
1128 search: options.search
1127 } 1129 }
1128 1130
1129 return VideoModel.getAvailableForApi(queryOptions, options.countVideos) 1131 return VideoModel.getAvailableForApi(queryOptions, options.countVideos)
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts
index 661d603cb..b25cff879 100644
--- a/server/tests/api/videos/videos-history.ts
+++ b/server/tests/api/videos/videos-history.ts
@@ -152,6 +152,15 @@ describe('Test videos history', function () {
152 expect(res.body.data).to.have.lengthOf(0) 152 expect(res.body.data).to.have.lengthOf(0)
153 }) 153 })
154 154
155 it('Should be able to search through videos in my history', async function () {
156 const res = await listMyVideosHistory(server.url, server.accessToken, '2')
157
158 expect(res.body.total).to.equal(1)
159
160 const videos: Video[] = res.body.data
161 expect(videos[0].name).to.equal('video 2')
162 })
163
155 it('Should clear my history', async function () { 164 it('Should clear my history', async function () {
156 await removeMyVideosHistory(server.url, server.accessToken, video3WatchedDate.toISOString()) 165 await removeMyVideosHistory(server.url, server.accessToken, video3WatchedDate.toISOString())
157 }) 166 })