diff options
author | Chocobozzz <me@florianbigard.com> | 2018-07-20 14:35:18 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-24 14:04:05 +0200 |
commit | d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9 (patch) | |
tree | 4305044c4a97bdf1275b241c63cb0e85151cfb6a /server/controllers/api | |
parent | 57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6 (diff) | |
download | PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.tar.gz PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.tar.zst PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.zip |
Add videos list filters
Diffstat (limited to 'server/controllers/api')
-rw-r--r-- | server/controllers/api/accounts.ts | 12 | ||||
-rw-r--r-- | server/controllers/api/search.ts | 16 | ||||
-rw-r--r-- | server/controllers/api/video-channel.ts | 12 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 12 |
4 files changed, 35 insertions, 17 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index 8e937276c..0117fc8c6 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { getFormattedObjects } from '../../helpers/utils' | 2 | import { getFormattedObjects } from '../../helpers/utils' |
3 | import { | 3 | import { |
4 | asyncMiddleware, | 4 | asyncMiddleware, commonVideosFiltersValidator, |
5 | listVideoAccountChannelsValidator, | 5 | listVideoAccountChannelsValidator, |
6 | optionalAuthenticate, | 6 | optionalAuthenticate, |
7 | paginationValidator, | 7 | paginationValidator, |
@@ -11,7 +11,7 @@ import { | |||
11 | import { accountsNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators' | 11 | import { accountsNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators' |
12 | import { AccountModel } from '../../models/account/account' | 12 | import { AccountModel } from '../../models/account/account' |
13 | import { VideoModel } from '../../models/video/video' | 13 | import { VideoModel } from '../../models/video/video' |
14 | import { isNSFWHidden } from '../../helpers/express-utils' | 14 | import { buildNSFWFilter } from '../../helpers/express-utils' |
15 | import { VideoChannelModel } from '../../models/video/video-channel' | 15 | import { VideoChannelModel } from '../../models/video/video-channel' |
16 | 16 | ||
17 | const accountsRouter = express.Router() | 17 | const accountsRouter = express.Router() |
@@ -36,6 +36,7 @@ accountsRouter.get('/:accountName/videos', | |||
36 | setDefaultSort, | 36 | setDefaultSort, |
37 | setDefaultPagination, | 37 | setDefaultPagination, |
38 | optionalAuthenticate, | 38 | optionalAuthenticate, |
39 | commonVideosFiltersValidator, | ||
39 | asyncMiddleware(listAccountVideos) | 40 | asyncMiddleware(listAccountVideos) |
40 | ) | 41 | ) |
41 | 42 | ||
@@ -77,7 +78,12 @@ async function listAccountVideos (req: express.Request, res: express.Response, n | |||
77 | start: req.query.start, | 78 | start: req.query.start, |
78 | count: req.query.count, | 79 | count: req.query.count, |
79 | sort: req.query.sort, | 80 | sort: req.query.sort, |
80 | hideNSFW: isNSFWHidden(res), | 81 | categoryOneOf: req.query.categoryOneOf, |
82 | licenceOneOf: req.query.licenceOneOf, | ||
83 | languageOneOf: req.query.languageOneOf, | ||
84 | tagsOneOf: req.query.tagsOneOf, | ||
85 | tagsAllOf: req.query.tagsAllOf, | ||
86 | nsfw: buildNSFWFilter(res, req.query.nsfw), | ||
81 | withFiles: false, | 87 | withFiles: false, |
82 | accountId: account.id | 88 | accountId: account.id |
83 | }) | 89 | }) |
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts index 2ff340b59..f810c7452 100644 --- a/server/controllers/api/search.ts +++ b/server/controllers/api/search.ts | |||
@@ -1,9 +1,10 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { isNSFWHidden } from '../../helpers/express-utils' | 2 | import { buildNSFWFilter } from '../../helpers/express-utils' |
3 | import { getFormattedObjects } from '../../helpers/utils' | 3 | import { getFormattedObjects } from '../../helpers/utils' |
4 | import { VideoModel } from '../../models/video/video' | 4 | import { VideoModel } from '../../models/video/video' |
5 | import { | 5 | import { |
6 | asyncMiddleware, | 6 | asyncMiddleware, |
7 | commonVideosFiltersValidator, | ||
7 | optionalAuthenticate, | 8 | optionalAuthenticate, |
8 | paginationValidator, | 9 | paginationValidator, |
9 | searchValidator, | 10 | searchValidator, |
@@ -11,6 +12,7 @@ import { | |||
11 | setDefaultSearchSort, | 12 | setDefaultSearchSort, |
12 | videosSearchSortValidator | 13 | videosSearchSortValidator |
13 | } from '../../middlewares' | 14 | } from '../../middlewares' |
15 | import { VideosSearchQuery } from '../../../shared/models/search' | ||
14 | 16 | ||
15 | const searchRouter = express.Router() | 17 | const searchRouter = express.Router() |
16 | 18 | ||
@@ -20,6 +22,7 @@ searchRouter.get('/videos', | |||
20 | videosSearchSortValidator, | 22 | videosSearchSortValidator, |
21 | setDefaultSearchSort, | 23 | setDefaultSearchSort, |
22 | optionalAuthenticate, | 24 | optionalAuthenticate, |
25 | commonVideosFiltersValidator, | ||
23 | searchValidator, | 26 | searchValidator, |
24 | asyncMiddleware(searchVideos) | 27 | asyncMiddleware(searchVideos) |
25 | ) | 28 | ) |
@@ -31,13 +34,10 @@ export { searchRouter } | |||
31 | // --------------------------------------------------------------------------- | 34 | // --------------------------------------------------------------------------- |
32 | 35 | ||
33 | async function searchVideos (req: express.Request, res: express.Response) { | 36 | async function searchVideos (req: express.Request, res: express.Response) { |
34 | const resultList = await VideoModel.searchAndPopulateAccountAndServer( | 37 | const query: VideosSearchQuery = req.query |
35 | req.query.search as string, | 38 | |
36 | req.query.start as number, | 39 | const options = Object.assign(query, { nsfw: buildNSFWFilter(res, query.nsfw) }) |
37 | req.query.count as number, | 40 | const resultList = await VideoModel.searchAndPopulateAccountAndServer(options) |
38 | req.query.sort as string, | ||
39 | isNSFWHidden(res) | ||
40 | ) | ||
41 | 41 | ||
42 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 42 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
43 | } | 43 | } |
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index 1707732ee..0488ba8f5 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts | |||
@@ -3,7 +3,7 @@ import { getFormattedObjects, resetSequelizeInstance } from '../../helpers/utils | |||
3 | import { | 3 | import { |
4 | asyncMiddleware, | 4 | asyncMiddleware, |
5 | asyncRetryTransactionMiddleware, | 5 | asyncRetryTransactionMiddleware, |
6 | authenticate, | 6 | authenticate, commonVideosFiltersValidator, |
7 | optionalAuthenticate, | 7 | optionalAuthenticate, |
8 | paginationValidator, | 8 | paginationValidator, |
9 | setDefaultPagination, | 9 | setDefaultPagination, |
@@ -19,7 +19,7 @@ import { videosSortValidator } from '../../middlewares/validators' | |||
19 | import { sendUpdateActor } from '../../lib/activitypub/send' | 19 | import { sendUpdateActor } from '../../lib/activitypub/send' |
20 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared' | 20 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared' |
21 | import { createVideoChannel } from '../../lib/video-channel' | 21 | import { createVideoChannel } from '../../lib/video-channel' |
22 | import { createReqFiles, isNSFWHidden } from '../../helpers/express-utils' | 22 | import { createReqFiles, buildNSFWFilter } from '../../helpers/express-utils' |
23 | import { setAsyncActorKeys } from '../../lib/activitypub' | 23 | import { setAsyncActorKeys } from '../../lib/activitypub' |
24 | import { AccountModel } from '../../models/account/account' | 24 | import { AccountModel } from '../../models/account/account' |
25 | import { CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers' | 25 | import { CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers' |
@@ -79,6 +79,7 @@ videoChannelRouter.get('/:id/videos', | |||
79 | setDefaultSort, | 79 | setDefaultSort, |
80 | setDefaultPagination, | 80 | setDefaultPagination, |
81 | optionalAuthenticate, | 81 | optionalAuthenticate, |
82 | commonVideosFiltersValidator, | ||
82 | asyncMiddleware(listVideoChannelVideos) | 83 | asyncMiddleware(listVideoChannelVideos) |
83 | ) | 84 | ) |
84 | 85 | ||
@@ -189,7 +190,12 @@ async function listVideoChannelVideos (req: express.Request, res: express.Respon | |||
189 | start: req.query.start, | 190 | start: req.query.start, |
190 | count: req.query.count, | 191 | count: req.query.count, |
191 | sort: req.query.sort, | 192 | sort: req.query.sort, |
192 | hideNSFW: isNSFWHidden(res), | 193 | categoryOneOf: req.query.categoryOneOf, |
194 | licenceOneOf: req.query.licenceOneOf, | ||
195 | languageOneOf: req.query.languageOneOf, | ||
196 | tagsOneOf: req.query.tagsOneOf, | ||
197 | tagsAllOf: req.query.tagsAllOf, | ||
198 | nsfw: buildNSFWFilter(res, req.query.nsfw), | ||
193 | withFiles: false, | 199 | withFiles: false, |
194 | videoChannelId: videoChannelInstance.id | 200 | videoChannelId: videoChannelInstance.id |
195 | }) | 201 | }) |
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index 547522123..101183eab 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -31,6 +31,7 @@ import { | |||
31 | asyncMiddleware, | 31 | asyncMiddleware, |
32 | asyncRetryTransactionMiddleware, | 32 | asyncRetryTransactionMiddleware, |
33 | authenticate, | 33 | authenticate, |
34 | commonVideosFiltersValidator, | ||
34 | optionalAuthenticate, | 35 | optionalAuthenticate, |
35 | paginationValidator, | 36 | paginationValidator, |
36 | setDefaultPagination, | 37 | setDefaultPagination, |
@@ -49,7 +50,7 @@ import { blacklistRouter } from './blacklist' | |||
49 | import { videoCommentRouter } from './comment' | 50 | import { videoCommentRouter } from './comment' |
50 | import { rateVideoRouter } from './rate' | 51 | import { rateVideoRouter } from './rate' |
51 | import { VideoFilter } from '../../../../shared/models/videos/video-query.type' | 52 | import { VideoFilter } from '../../../../shared/models/videos/video-query.type' |
52 | import { createReqFiles, isNSFWHidden } from '../../../helpers/express-utils' | 53 | import { createReqFiles, buildNSFWFilter } from '../../../helpers/express-utils' |
53 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' | 54 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' |
54 | import { videoCaptionsRouter } from './captions' | 55 | import { videoCaptionsRouter } from './captions' |
55 | 56 | ||
@@ -90,6 +91,7 @@ videosRouter.get('/', | |||
90 | setDefaultSort, | 91 | setDefaultSort, |
91 | setDefaultPagination, | 92 | setDefaultPagination, |
92 | optionalAuthenticate, | 93 | optionalAuthenticate, |
94 | commonVideosFiltersValidator, | ||
93 | asyncMiddleware(listVideos) | 95 | asyncMiddleware(listVideos) |
94 | ) | 96 | ) |
95 | videosRouter.put('/:id', | 97 | videosRouter.put('/:id', |
@@ -401,8 +403,12 @@ async function listVideos (req: express.Request, res: express.Response, next: ex | |||
401 | start: req.query.start, | 403 | start: req.query.start, |
402 | count: req.query.count, | 404 | count: req.query.count, |
403 | sort: req.query.sort, | 405 | sort: req.query.sort, |
404 | category: req.query.category, | 406 | categoryOneOf: req.query.categoryOneOf, |
405 | hideNSFW: isNSFWHidden(res), | 407 | licenceOneOf: req.query.licenceOneOf, |
408 | languageOneOf: req.query.languageOneOf, | ||
409 | tagsOneOf: req.query.tagsOneOf, | ||
410 | tagsAllOf: req.query.tagsAllOf, | ||
411 | nsfw: buildNSFWFilter(res, req.query.nsfw), | ||
406 | filter: req.query.filter as VideoFilter, | 412 | filter: req.query.filter as VideoFilter, |
407 | withFiles: false | 413 | withFiles: false |
408 | }) | 414 | }) |