diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/index.ts | 2 | ||||
-rw-r--r-- | server/controllers/api/search.ts | 43 | ||||
-rw-r--r-- | server/controllers/api/videos/index.ts | 23 | ||||
-rw-r--r-- | server/controllers/client.ts | 10 |
4 files changed, 53 insertions, 25 deletions
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts index c386a6710..e928a7478 100644 --- a/server/controllers/api/index.ts +++ b/server/controllers/api/index.ts | |||
@@ -9,6 +9,7 @@ import { videosRouter } from './videos' | |||
9 | import { badRequest } from '../../helpers/express-utils' | 9 | import { badRequest } from '../../helpers/express-utils' |
10 | import { videoChannelRouter } from './video-channel' | 10 | import { videoChannelRouter } from './video-channel' |
11 | import * as cors from 'cors' | 11 | import * as cors from 'cors' |
12 | import { searchRouter } from './search' | ||
12 | 13 | ||
13 | const apiRouter = express.Router() | 14 | const apiRouter = express.Router() |
14 | 15 | ||
@@ -26,6 +27,7 @@ apiRouter.use('/accounts', accountsRouter) | |||
26 | apiRouter.use('/video-channels', videoChannelRouter) | 27 | apiRouter.use('/video-channels', videoChannelRouter) |
27 | apiRouter.use('/videos', videosRouter) | 28 | apiRouter.use('/videos', videosRouter) |
28 | apiRouter.use('/jobs', jobsRouter) | 29 | apiRouter.use('/jobs', jobsRouter) |
30 | apiRouter.use('/search', searchRouter) | ||
29 | apiRouter.use('/ping', pong) | 31 | apiRouter.use('/ping', pong) |
30 | apiRouter.use('/*', badRequest) | 32 | apiRouter.use('/*', badRequest) |
31 | 33 | ||
diff --git a/server/controllers/api/search.ts b/server/controllers/api/search.ts new file mode 100644 index 000000000..2ff340b59 --- /dev/null +++ b/server/controllers/api/search.ts | |||
@@ -0,0 +1,43 @@ | |||
1 | import * as express from 'express' | ||
2 | import { isNSFWHidden } from '../../helpers/express-utils' | ||
3 | import { getFormattedObjects } from '../../helpers/utils' | ||
4 | import { VideoModel } from '../../models/video/video' | ||
5 | import { | ||
6 | asyncMiddleware, | ||
7 | optionalAuthenticate, | ||
8 | paginationValidator, | ||
9 | searchValidator, | ||
10 | setDefaultPagination, | ||
11 | setDefaultSearchSort, | ||
12 | videosSearchSortValidator | ||
13 | } from '../../middlewares' | ||
14 | |||
15 | const searchRouter = express.Router() | ||
16 | |||
17 | searchRouter.get('/videos', | ||
18 | paginationValidator, | ||
19 | setDefaultPagination, | ||
20 | videosSearchSortValidator, | ||
21 | setDefaultSearchSort, | ||
22 | optionalAuthenticate, | ||
23 | searchValidator, | ||
24 | asyncMiddleware(searchVideos) | ||
25 | ) | ||
26 | |||
27 | // --------------------------------------------------------------------------- | ||
28 | |||
29 | export { searchRouter } | ||
30 | |||
31 | // --------------------------------------------------------------------------- | ||
32 | |||
33 | async function searchVideos (req: express.Request, res: express.Response) { | ||
34 | const resultList = await VideoModel.searchAndPopulateAccountAndServer( | ||
35 | req.query.search as string, | ||
36 | req.query.start as number, | ||
37 | req.query.count as number, | ||
38 | req.query.sort as string, | ||
39 | isNSFWHidden(res) | ||
40 | ) | ||
41 | |||
42 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | ||
43 | } | ||
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts index bbb5b8b4c..547522123 100644 --- a/server/controllers/api/videos/index.ts +++ b/server/controllers/api/videos/index.ts | |||
@@ -38,7 +38,6 @@ import { | |||
38 | videosAddValidator, | 38 | videosAddValidator, |
39 | videosGetValidator, | 39 | videosGetValidator, |
40 | videosRemoveValidator, | 40 | videosRemoveValidator, |
41 | videosSearchValidator, | ||
42 | videosSortValidator, | 41 | videosSortValidator, |
43 | videosUpdateValidator | 42 | videosUpdateValidator |
44 | } from '../../../middlewares' | 43 | } from '../../../middlewares' |
@@ -50,7 +49,6 @@ import { blacklistRouter } from './blacklist' | |||
50 | import { videoCommentRouter } from './comment' | 49 | import { videoCommentRouter } from './comment' |
51 | import { rateVideoRouter } from './rate' | 50 | import { rateVideoRouter } from './rate' |
52 | import { VideoFilter } from '../../../../shared/models/videos/video-query.type' | 51 | import { VideoFilter } from '../../../../shared/models/videos/video-query.type' |
53 | import { VideoSortField } from '../../../../client/src/app/shared/video/sort-field.type' | ||
54 | import { createReqFiles, isNSFWHidden } from '../../../helpers/express-utils' | 52 | import { createReqFiles, isNSFWHidden } from '../../../helpers/express-utils' |
55 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' | 53 | import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update' |
56 | import { videoCaptionsRouter } from './captions' | 54 | import { videoCaptionsRouter } from './captions' |
@@ -94,15 +92,6 @@ videosRouter.get('/', | |||
94 | optionalAuthenticate, | 92 | optionalAuthenticate, |
95 | asyncMiddleware(listVideos) | 93 | asyncMiddleware(listVideos) |
96 | ) | 94 | ) |
97 | videosRouter.get('/search', | ||
98 | videosSearchValidator, | ||
99 | paginationValidator, | ||
100 | videosSortValidator, | ||
101 | setDefaultSort, | ||
102 | setDefaultPagination, | ||
103 | optionalAuthenticate, | ||
104 | asyncMiddleware(searchVideos) | ||
105 | ) | ||
106 | videosRouter.put('/:id', | 95 | videosRouter.put('/:id', |
107 | authenticate, | 96 | authenticate, |
108 | reqVideoFileUpdate, | 97 | reqVideoFileUpdate, |
@@ -432,15 +421,3 @@ async function removeVideo (req: express.Request, res: express.Response) { | |||
432 | 421 | ||
433 | return res.type('json').status(204).end() | 422 | return res.type('json').status(204).end() |
434 | } | 423 | } |
435 | |||
436 | async function searchVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | ||
437 | const resultList = await VideoModel.searchAndPopulateAccountAndServer( | ||
438 | req.query.search as string, | ||
439 | req.query.start as number, | ||
440 | req.query.count as number, | ||
441 | req.query.sort as VideoSortField, | ||
442 | isNSFWHidden(res) | ||
443 | ) | ||
444 | |||
445 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | ||
446 | } | ||
diff --git a/server/controllers/client.ts b/server/controllers/client.ts index 352d45fbf..bbb518c1b 100644 --- a/server/controllers/client.ts +++ b/server/controllers/client.ts | |||
@@ -5,6 +5,7 @@ import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers' | |||
5 | import { asyncMiddleware } from '../middlewares' | 5 | import { asyncMiddleware } from '../middlewares' |
6 | import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n' | 6 | import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n' |
7 | import { ClientHtml } from '../lib/client-html' | 7 | import { ClientHtml } from '../lib/client-html' |
8 | import { logger } from '../helpers/logger' | ||
8 | 9 | ||
9 | const clientsRouter = express.Router() | 10 | const clientsRouter = express.Router() |
10 | 11 | ||
@@ -66,9 +67,14 @@ clientsRouter.use('/client/*', (req: express.Request, res: express.Response, nex | |||
66 | 67 | ||
67 | // Always serve index client page (the client is a single page application, let it handle routing) | 68 | // Always serve index client page (the client is a single page application, let it handle routing) |
68 | // Try to provide the right language index.html | 69 | // Try to provide the right language index.html |
69 | clientsRouter.use('/(:language)?', function (req, res) { | 70 | clientsRouter.use('/(:language)?', async function (req, res) { |
70 | if (req.accepts(ACCEPT_HEADERS) === 'html') { | 71 | if (req.accepts(ACCEPT_HEADERS) === 'html') { |
71 | return generateHTMLPage(req, res, req.params.language) | 72 | try { |
73 | await generateHTMLPage(req, res, req.params.language) | ||
74 | return | ||
75 | } catch (err) { | ||
76 | logger.error('Cannot generate HTML page.', err) | ||
77 | } | ||
72 | } | 78 | } |
73 | 79 | ||
74 | return res.status(404).end() | 80 | return res.status(404).end() |