aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/search.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/search.ts')
-rw-r--r--server/lib/search.ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/server/lib/search.ts b/server/lib/search.ts
new file mode 100644
index 000000000..b643a4055
--- /dev/null
+++ b/server/lib/search.ts
@@ -0,0 +1,50 @@
1import * as express from 'express'
2import { CONFIG } from '@server/initializers/config'
3import { AccountBlocklistModel } from '@server/models/account/account-blocklist'
4import { getServerActor } from '@server/models/application/application'
5import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
6import { SearchTargetQuery } from '@shared/models'
7
8function isSearchIndexSearch (query: SearchTargetQuery) {
9 if (query.searchTarget === 'search-index') return true
10
11 const searchIndexConfig = CONFIG.SEARCH.SEARCH_INDEX
12
13 if (searchIndexConfig.ENABLED !== true) return false
14
15 if (searchIndexConfig.DISABLE_LOCAL_SEARCH) return true
16 if (searchIndexConfig.IS_DEFAULT_SEARCH && !query.searchTarget) return true
17
18 return false
19}
20
21async function buildMutedForSearchIndex (res: express.Response) {
22 const serverActor = await getServerActor()
23 const accountIds = [ serverActor.Account.id ]
24
25 if (res.locals.oauth) {
26 accountIds.push(res.locals.oauth.token.User.Account.id)
27 }
28
29 const [ blockedHosts, blockedAccounts ] = await Promise.all([
30 ServerBlocklistModel.listHostsBlockedBy(accountIds),
31 AccountBlocklistModel.listHandlesBlockedBy(accountIds)
32 ])
33
34 return {
35 blockedHosts,
36 blockedAccounts
37 }
38}
39
40function isURISearch (search: string) {
41 if (!search) return false
42
43 return search.startsWith('http://') || search.startsWith('https://')
44}
45
46export {
47 isSearchIndexSearch,
48 buildMutedForSearchIndex,
49 isURISearch
50}