]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/search.ts
Fix unregister default value
[github/Chocobozzz/PeerTube.git] / server / lib / search.ts
CommitLineData
41fb13c3 1import express from 'express'
37a44fc9
C
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
37a44fc9
C
15 if (searchIndexConfig.IS_DEFAULT_SEARCH && !query.searchTarget) return true
16
17 return false
18}
19
20async function buildMutedForSearchIndex (res: express.Response) {
21 const serverActor = await getServerActor()
22 const accountIds = [ serverActor.Account.id ]
23
24 if (res.locals.oauth) {
25 accountIds.push(res.locals.oauth.token.User.Account.id)
26 }
27
28 const [ blockedHosts, blockedAccounts ] = await Promise.all([
29 ServerBlocklistModel.listHostsBlockedBy(accountIds),
30 AccountBlocklistModel.listHandlesBlockedBy(accountIds)
31 ])
32
33 return {
34 blockedHosts,
35 blockedAccounts
36 }
37}
38
39function isURISearch (search: string) {
40 if (!search) return false
41
42 return search.startsWith('http://') || search.startsWith('https://')
43}
44
45export {
46 isSearchIndexSearch,
47 buildMutedForSearchIndex,
48 isURISearch
49}