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'
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)
}
}
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)
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)
}
}
return searchVideoURI(search, res)
}
- if (isSearchIndexEnabled(query)) {
+ if (isSearchIndexSearch(query)) {
return searchVideosIndex(query, res)
}
}
async function searchVideosIndex (query: VideosSearchQuery, res: express.Response) {
- logger.debug('Doing videos search on search index.')
-
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'
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)
}
}
})
}
-function isSearchIndexEnabled (query: SearchTargetQuery) {
+function isSearchIndexSearch (query: SearchTargetQuery) {
if (query.searchTarget === 'search-index') return true
const searchIndexConfig = CONFIG.SEARCH.SEARCH_INDEX