blob: b643a4055e7227d0a72cdb65d395d20ad6b62a9d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
import * as express from 'express'
import { CONFIG } from '@server/initializers/config'
import { AccountBlocklistModel } from '@server/models/account/account-blocklist'
import { getServerActor } from '@server/models/application/application'
import { ServerBlocklistModel } from '@server/models/server/server-blocklist'
import { SearchTargetQuery } from '@shared/models'
function isSearchIndexSearch (query: SearchTargetQuery) {
if (query.searchTarget === 'search-index') return true
const searchIndexConfig = CONFIG.SEARCH.SEARCH_INDEX
if (searchIndexConfig.ENABLED !== true) return false
if (searchIndexConfig.DISABLE_LOCAL_SEARCH) return true
if (searchIndexConfig.IS_DEFAULT_SEARCH && !query.searchTarget) return true
return false
}
async function buildMutedForSearchIndex (res: express.Response) {
const serverActor = await getServerActor()
const accountIds = [ serverActor.Account.id ]
if (res.locals.oauth) {
accountIds.push(res.locals.oauth.token.User.Account.id)
}
const [ blockedHosts, blockedAccounts ] = await Promise.all([
ServerBlocklistModel.listHostsBlockedBy(accountIds),
AccountBlocklistModel.listHandlesBlockedBy(accountIds)
])
return {
blockedHosts,
blockedAccounts
}
}
function isURISearch (search: string) {
if (!search) return false
return search.startsWith('http://') || search.startsWith('https://')
}
export {
isSearchIndexSearch,
buildMutedForSearchIndex,
isURISearch
}
|