]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/search.ts
Translated using Weblate (Spanish)
[github/Chocobozzz/PeerTube.git] / server / lib / search.ts
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'
7
8 function 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.IS_DEFAULT_SEARCH && !query.searchTarget) return true
16
17 return false
18 }
19
20 async 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
39 function isURISearch (search: string) {
40 if (!search) return false
41
42 return search.startsWith('http://') || search.startsWith('https://')
43 }
44
45 export {
46 isSearchIndexSearch,
47 buildMutedForSearchIndex,
48 isURISearch
49 }