aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-20 14:35:18 +0200
committerChocobozzz <me@florianbigard.com>2018-07-24 14:04:05 +0200
commitd525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9 (patch)
tree4305044c4a97bdf1275b241c63cb0e85151cfb6a /server/controllers
parent57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6 (diff)
downloadPeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.tar.gz
PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.tar.zst
PeerTube-d525fc399a14a8b16eaad6d4c0bc0a9c4093c3c9.zip
Add videos list filters
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/api/accounts.ts12
-rw-r--r--server/controllers/api/search.ts16
-rw-r--r--server/controllers/api/video-channel.ts12
-rw-r--r--server/controllers/api/videos/index.ts12
-rw-r--r--server/controllers/feeds.ts5
5 files changed, 38 insertions, 19 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { getFormattedObjects } from '../../helpers/utils' 2import { getFormattedObjects } from '../../helpers/utils'
3import { 3import {
4 asyncMiddleware, 4 asyncMiddleware, commonVideosFiltersValidator,
5 listVideoAccountChannelsValidator, 5 listVideoAccountChannelsValidator,
6 optionalAuthenticate, 6 optionalAuthenticate,
7 paginationValidator, 7 paginationValidator,
@@ -11,7 +11,7 @@ import {
11import { accountsNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators' 11import { accountsNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators'
12import { AccountModel } from '../../models/account/account' 12import { AccountModel } from '../../models/account/account'
13import { VideoModel } from '../../models/video/video' 13import { VideoModel } from '../../models/video/video'
14import { isNSFWHidden } from '../../helpers/express-utils' 14import { buildNSFWFilter } from '../../helpers/express-utils'
15import { VideoChannelModel } from '../../models/video/video-channel' 15import { VideoChannelModel } from '../../models/video/video-channel'
16 16
17const accountsRouter = express.Router() 17const 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { isNSFWHidden } from '../../helpers/express-utils' 2import { buildNSFWFilter } from '../../helpers/express-utils'
3import { getFormattedObjects } from '../../helpers/utils' 3import { getFormattedObjects } from '../../helpers/utils'
4import { VideoModel } from '../../models/video/video' 4import { VideoModel } from '../../models/video/video'
5import { 5import {
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'
15import { VideosSearchQuery } from '../../../shared/models/search'
14 16
15const searchRouter = express.Router() 17const 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
33async function searchVideos (req: express.Request, res: express.Response) { 36async 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
3import { 3import {
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'
19import { sendUpdateActor } from '../../lib/activitypub/send' 19import { sendUpdateActor } from '../../lib/activitypub/send'
20import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared' 20import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
21import { createVideoChannel } from '../../lib/video-channel' 21import { createVideoChannel } from '../../lib/video-channel'
22import { createReqFiles, isNSFWHidden } from '../../helpers/express-utils' 22import { createReqFiles, buildNSFWFilter } from '../../helpers/express-utils'
23import { setAsyncActorKeys } from '../../lib/activitypub' 23import { setAsyncActorKeys } from '../../lib/activitypub'
24import { AccountModel } from '../../models/account/account' 24import { AccountModel } from '../../models/account/account'
25import { CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers' 25import { 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'
49import { videoCommentRouter } from './comment' 50import { videoCommentRouter } from './comment'
50import { rateVideoRouter } from './rate' 51import { rateVideoRouter } from './rate'
51import { VideoFilter } from '../../../../shared/models/videos/video-query.type' 52import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
52import { createReqFiles, isNSFWHidden } from '../../../helpers/express-utils' 53import { createReqFiles, buildNSFWFilter } from '../../../helpers/express-utils'
53import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' 54import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update'
54import { videoCaptionsRouter } from './captions' 55import { 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)
95videosRouter.put('/:id', 97videosRouter.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 })
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts
index ff6b423d9..682f4abda 100644
--- a/server/controllers/feeds.ts
+++ b/server/controllers/feeds.ts
@@ -8,6 +8,7 @@ import { AccountModel } from '../models/account/account'
8import { cacheRoute } from '../middlewares/cache' 8import { cacheRoute } from '../middlewares/cache'
9import { VideoChannelModel } from '../models/video/video-channel' 9import { VideoChannelModel } from '../models/video/video-channel'
10import { VideoCommentModel } from '../models/video/video-comment' 10import { VideoCommentModel } from '../models/video/video-comment'
11import { buildNSFWFilter } from '../helpers/express-utils'
11 12
12const feedsRouter = express.Router() 13const feedsRouter = express.Router()
13 14
@@ -73,7 +74,7 @@ async function generateVideoFeed (req: express.Request, res: express.Response, n
73 74
74 const account: AccountModel = res.locals.account 75 const account: AccountModel = res.locals.account
75 const videoChannel: VideoChannelModel = res.locals.videoChannel 76 const videoChannel: VideoChannelModel = res.locals.videoChannel
76 const hideNSFW = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY === 'do_not_list' 77 const nsfw = buildNSFWFilter(res, req.query.nsfw)
77 78
78 let name: string 79 let name: string
79 let description: string 80 let description: string
@@ -95,7 +96,7 @@ async function generateVideoFeed (req: express.Request, res: express.Response, n
95 start, 96 start,
96 count: FEEDS.COUNT, 97 count: FEEDS.COUNT,
97 sort: req.query.sort, 98 sort: req.query.sort,
98 hideNSFW, 99 nsfw,
99 filter: req.query.filter, 100 filter: req.query.filter,
100 withFiles: true, 101 withFiles: true,
101 accountId: account ? account.id : null, 102 accountId: account ? account.id : null,