]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/search.ts
Add joblog at the end of ci
[github/Chocobozzz/PeerTube.git] / server / controllers / api / search.ts
index a0da5e30cfbee0e3dff45556d7eb762bfee76437..7e1b7b230b9ec9381a9917e967de982350a53301 100644 (file)
@@ -6,6 +6,7 @@ import { getOrCreateVideoAndAccountAndChannel } from '@server/lib/activitypub/vi
 import { AccountBlocklistModel } from '@server/models/account/account-blocklist'
 import { getServerActor } from '@server/models/application/application'
 import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
+import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
 import { ResultList, Video, VideoChannel } from '@shared/models'
 import { SearchTargetQuery } from '@shared/models/search/search-target-query.model'
 import { VideoChannelsSearchQuery, VideosSearchQuery } from '../../../shared/models/search'
@@ -22,13 +23,13 @@ import {
   setDefaultPagination,
   setDefaultSearchSort,
   videoChannelsSearchSortValidator,
-  videoChannelsSearchValidator,
+  videoChannelsListSearchValidator,
   videosSearchSortValidator,
   videosSearchValidator
 } from '../../middlewares'
 import { VideoModel } from '../../models/video/video'
 import { VideoChannelModel } from '../../models/video/video-channel'
-import { MChannelAccountDefault, MVideoAccountLightBlacklistAllFiles } from '../../typings/models'
+import { MChannelAccountDefault, MVideoAccountLightBlacklistAllFiles } from '../../types/models'
 
 const searchRouter = express.Router()
 
@@ -49,7 +50,7 @@ searchRouter.get('/video-channels',
   videoChannelsSearchSortValidator,
   setDefaultSearchSort,
   optionalAuthenticate,
-  videoChannelsSearchValidator,
+  videoChannelsListSearchValidator,
   asyncMiddleware(searchVideoChannels)
 )
 
@@ -84,8 +85,6 @@ function searchVideoChannels (req: express.Request, res: express.Response) {
 }
 
 async function searchVideoChannelsIndex (query: VideoChannelsSearchQuery, res: express.Response) {
-  logger.debug('Doing channels search on search index.')
-
   const result = await buildMutedForSearchIndex(res)
 
   const body = Object.assign(query, result)
@@ -93,13 +92,15 @@ async function searchVideoChannelsIndex (query: VideoChannelsSearchQuery, res: e
   const url = sanitizeUrl(CONFIG.SEARCH.SEARCH_INDEX.URL) + '/api/v1/search/video-channels'
 
   try {
+    logger.debug('Doing video channels search index request on %s.', url, { body })
+
     const searchIndexResult = await doRequest<ResultList<VideoChannel>>({ uri: url, body, json: true })
 
     return res.json(searchIndexResult.body)
   } catch (err) {
     logger.warn('Cannot use search index to make video channels search.', { err })
 
-    return res.sendStatus(500)
+    return res.sendStatus(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
   }
 }
 
@@ -165,8 +166,6 @@ function searchVideos (req: express.Request, res: express.Response) {
 }
 
 async function searchVideosIndex (query: VideosSearchQuery, res: express.Response) {
-  logger.debug('Doing videos search on search index.')
-
   const result = await buildMutedForSearchIndex(res)
 
   const body: VideosSearchQuery = Object.assign(query, result)
@@ -185,13 +184,15 @@ async function searchVideosIndex (query: VideosSearchQuery, res: express.Respons
   const url = sanitizeUrl(CONFIG.SEARCH.SEARCH_INDEX.URL) + '/api/v1/search/videos'
 
   try {
+    logger.debug('Doing videos search index request on %s.', url, { body })
+
     const searchIndexResult = await doRequest<ResultList<Video>>({ uri: url, body, json: true })
 
     return res.json(searchIndexResult.body)
   } catch (err) {
     logger.warn('Cannot use search index to make video search.', { err })
 
-    return res.sendStatus(500)
+    return res.sendStatus(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
   }
 }