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()
videoChannelsSearchSortValidator,
setDefaultSearchSort,
optionalAuthenticate,
- videoChannelsSearchValidator,
+ videoChannelsListSearchValidator,
asyncMiddleware(searchVideoChannels)
)
// @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)
}
return searchVideoURI(search, res)
}
- if (isSearchIndexEnabled(query)) {
+ if (isSearchIndexSearch(query)) {
return searchVideosIndex(query, res)
}
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'
})
}
-function isSearchIndexEnabled (query: SearchTargetQuery) {
+function isSearchIndexSearch (query: SearchTargetQuery) {
if (query.searchTarget === 'search-index') return true
const searchIndexConfig = CONFIG.SEARCH.SEARCH_INDEX