1 import express from 'express'
2 import { CONFIG } from '@server/initializers/config'
3 import { AccountBlocklistModel } from '@server/models/account/account-blocklist'
4 import { getServerActor } from '@server/models/application/application'
5 import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
6 import { SearchTargetQuery } from '@shared/models'
8 function isSearchIndexSearch (query: SearchTargetQuery) {
9 if (query.searchTarget === 'search-index') return true
11 const searchIndexConfig = CONFIG.SEARCH.SEARCH_INDEX
13 if (searchIndexConfig.ENABLED !== true) return false
15 if (searchIndexConfig.IS_DEFAULT_SEARCH && !query.searchTarget) return true
20 async function buildMutedForSearchIndex (res: express.Response) {
21 const serverActor = await getServerActor()
22 const accountIds = [ serverActor.Account.id ]
24 if (res.locals.oauth) {
25 accountIds.push(res.locals.oauth.token.User.Account.id)
28 const [ blockedHosts, blockedAccounts ] = await Promise.all([
29 ServerBlocklistModel.listHostsBlockedBy(accountIds),
30 AccountBlocklistModel.listHandlesBlockedBy(accountIds)
39 function isURISearch (search: string) {
40 if (!search) return false
42 return search.startsWith('http://') || search.startsWith('https://')
47 buildMutedForSearchIndex,