+async function searchVideosIndex (query: VideosSearchQuery, res: express.Response) {
+ const result = await buildMutedForSearchIndex(res)
+
+ 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'
+
+ 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(HttpStatusCode.INTERNAL_SERVER_ERROR_500)
+ }
+}
+