]> 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 1dea77d2925fed81f351316295090571afa6d606..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)
 )
 
@@ -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'