diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-07-15 11:17:03 +0200 |
---|---|---|
committer | Rigel Kent <par@rigelk.eu> | 2020-07-29 18:15:53 +0200 |
commit | bc99dfe54e093e69ba8fd06d36b36fbbda3f45de (patch) | |
tree | 2c13497b77928c2593310746e3ec33333e2b4d66 /server | |
parent | 654a188f80fc1f089aa14837084664c908fe27d2 (diff) | |
download | PeerTube-bc99dfe54e093e69ba8fd06d36b36fbbda3f45de.tar.gz PeerTube-bc99dfe54e093e69ba8fd06d36b36fbbda3f45de.tar.zst PeerTube-bc99dfe54e093e69ba8fd06d36b36fbbda3f45de.zip |
variable columns for users list, more columns possible, badge display for statuses
Diffstat (limited to 'server')
-rw-r--r-- | server/controllers/api/video-channel.ts | 11 | ||||
-rw-r--r-- | server/middlewares/validators/search.ts | 15 | ||||
-rw-r--r-- | server/models/video/video-channel.ts | 19 |
3 files changed, 37 insertions, 8 deletions
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts index 4d8cfa340..d96998209 100644 --- a/server/controllers/api/video-channel.ts +++ b/server/controllers/api/video-channel.ts | |||
@@ -16,7 +16,7 @@ import { | |||
16 | videoPlaylistsSortValidator | 16 | videoPlaylistsSortValidator |
17 | } from '../../middlewares' | 17 | } from '../../middlewares' |
18 | import { VideoChannelModel } from '../../models/video/video-channel' | 18 | import { VideoChannelModel } from '../../models/video/video-channel' |
19 | import { videoChannelsNameWithHostValidator, videosSortValidator } from '../../middlewares/validators' | 19 | import { videoChannelsNameWithHostValidator, videosSortValidator, videoChannelsOwnSearchValidator } from '../../middlewares/validators' |
20 | import { sendUpdateActor } from '../../lib/activitypub/send' | 20 | import { sendUpdateActor } from '../../lib/activitypub/send' |
21 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared' | 21 | import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared' |
22 | import { createLocalVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel' | 22 | import { createLocalVideoChannel, federateAllVideosOfChannel } from '../../lib/video-channel' |
@@ -48,6 +48,7 @@ videoChannelRouter.get('/', | |||
48 | videoChannelsSortValidator, | 48 | videoChannelsSortValidator, |
49 | setDefaultSort, | 49 | setDefaultSort, |
50 | setDefaultPagination, | 50 | setDefaultPagination, |
51 | videoChannelsOwnSearchValidator, | ||
51 | asyncMiddleware(listVideoChannels) | 52 | asyncMiddleware(listVideoChannels) |
52 | ) | 53 | ) |
53 | 54 | ||
@@ -114,7 +115,13 @@ export { | |||
114 | 115 | ||
115 | async function listVideoChannels (req: express.Request, res: express.Response) { | 116 | async function listVideoChannels (req: express.Request, res: express.Response) { |
116 | const serverActor = await getServerActor() | 117 | const serverActor = await getServerActor() |
117 | const resultList = await VideoChannelModel.listForApi(serverActor.id, req.query.start, req.query.count, req.query.sort) | 118 | const resultList = await VideoChannelModel.listForApi({ |
119 | actorId: serverActor.id, | ||
120 | start: req.query.start, | ||
121 | count: req.query.count, | ||
122 | sort: req.query.sort, | ||
123 | search: req.query.search | ||
124 | }) | ||
118 | 125 | ||
119 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 126 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
120 | } | 127 | } |
diff --git a/server/middlewares/validators/search.ts b/server/middlewares/validators/search.ts index b4faa8894..7313bc055 100644 --- a/server/middlewares/validators/search.ts +++ b/server/middlewares/validators/search.ts | |||
@@ -41,9 +41,22 @@ const videoChannelsSearchValidator = [ | |||
41 | } | 41 | } |
42 | ] | 42 | ] |
43 | 43 | ||
44 | const videoChannelsOwnSearchValidator = [ | ||
45 | query('search').optional().not().isEmpty().withMessage('Should have a valid search'), | ||
46 | |||
47 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
48 | logger.debug('Checking video channels search query', { parameters: req.query }) | ||
49 | |||
50 | if (areValidationErrors(req, res)) return | ||
51 | |||
52 | return next() | ||
53 | } | ||
54 | ] | ||
55 | |||
44 | // --------------------------------------------------------------------------- | 56 | // --------------------------------------------------------------------------- |
45 | 57 | ||
46 | export { | 58 | export { |
59 | videosSearchValidator, | ||
47 | videoChannelsSearchValidator, | 60 | videoChannelsSearchValidator, |
48 | videosSearchValidator | 61 | videoChannelsOwnSearchValidator |
49 | } | 62 | } |
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 03a3cdf81..f3401fb9c 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts | |||
@@ -54,6 +54,7 @@ export enum ScopeNames { | |||
54 | 54 | ||
55 | type AvailableForListOptions = { | 55 | type AvailableForListOptions = { |
56 | actorId: number | 56 | actorId: number |
57 | search?: string | ||
57 | } | 58 | } |
58 | 59 | ||
59 | type AvailableWithStatsOptions = { | 60 | type AvailableWithStatsOptions = { |
@@ -309,15 +310,23 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
309 | return VideoChannelModel.count(query) | 310 | return VideoChannelModel.count(query) |
310 | } | 311 | } |
311 | 312 | ||
312 | static listForApi (actorId: number, start: number, count: number, sort: string) { | 313 | static listForApi (parameters: { |
314 | actorId: number | ||
315 | start: number | ||
316 | count: number | ||
317 | sort: string | ||
318 | search?: string | ||
319 | }) { | ||
320 | const { actorId, search } = parameters | ||
321 | |||
313 | const query = { | 322 | const query = { |
314 | offset: start, | 323 | offset: parameters.start, |
315 | limit: count, | 324 | limit: parameters.count, |
316 | order: getSort(sort) | 325 | order: getSort(parameters.sort) |
317 | } | 326 | } |
318 | 327 | ||
319 | const scopes = { | 328 | const scopes = { |
320 | method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ] | 329 | method: [ ScopeNames.FOR_API, { actorId, search } as AvailableForListOptions ] |
321 | } | 330 | } |
322 | return VideoChannelModel | 331 | return VideoChannelModel |
323 | .scope(scopes) | 332 | .scope(scopes) |