]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/controllers/api/search.ts
Add inspect to test script
[github/Chocobozzz/PeerTube.git] / server / controllers / api / search.ts
index e08e1d79fa15baea1ec64193c49e30e9e6d31cdc..6e2d11d93750e9ab0b44720dd83879582fb12fd9 100644 (file)
@@ -22,13 +22,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 +49,7 @@ searchRouter.get('/video-channels',
   videoChannelsSearchSortValidator,
   setDefaultSearchSort,
   optionalAuthenticate,
-  videoChannelsSearchValidator,
+  videoChannelsListSearchValidator,
   asyncMiddleware(searchVideoChannels)
 )
 
@@ -76,7 +76,7 @@ function searchVideoChannels (req: express.Request, res: express.Response) {
   // @username -> username to search in DB
   if (query.search.startsWith('@')) query.search = query.search.replace(/^@/, '')
 
-  if (isSearchIndexEnabled(query)) {
+  if (isSearchIndexSearch(query)) {
     return searchVideoChannelsIndex(query, res)
   }
 
@@ -157,7 +157,7 @@ function searchVideos (req: express.Request, res: express.Response) {
     return searchVideoURI(search, res)
   }
 
-  if (isSearchIndexEnabled(query)) {
+  if (isSearchIndexSearch(query)) {
     return searchVideosIndex(query, res)
   }
 
@@ -169,7 +169,18 @@ async function searchVideosIndex (query: VideosSearchQuery, res: express.Respons
 
   const result = await buildMutedForSearchIndex(res)
 
-  const body = Object.assign(query, result)
+  const body: VideosSearchQuery = Object.assign(query, result)
+
+  // Use the default instance NSFW policy if not specified
+  if (!body.nsfw) {
+    const nsfwPolicy = res.locals.oauth
+      ? res.locals.oauth.token.User.nsfwPolicy
+      : CONFIG.INSTANCE.DEFAULT_NSFW_POLICY
+
+    body.nsfw = nsfwPolicy === 'do_not_list'
+      ? 'false'
+      : 'both'
+  }
 
   const url = sanitizeUrl(CONFIG.SEARCH.SEARCH_INDEX.URL) + '/api/v1/search/videos'
 
@@ -226,7 +237,7 @@ async function searchVideoURI (url: string, res: express.Response) {
   })
 }
 
-function isSearchIndexEnabled (query: SearchTargetQuery) {
+function isSearchIndexSearch (query: SearchTargetQuery) {
   if (query.searchTarget === 'search-index') return true
 
   const searchIndexConfig = CONFIG.SEARCH.SEARCH_INDEX