2020-02-13 11:49:03 +01:00
|
|
|
import * as config from 'config'
|
|
|
|
import { isTestInstance } from '../helpers/core-utils'
|
|
|
|
|
|
|
|
const API_VERSION = 'v1'
|
|
|
|
|
|
|
|
const CONFIG = {
|
|
|
|
LISTEN: {
|
|
|
|
PORT: config.get<number>('listen.port')
|
|
|
|
},
|
2020-06-05 11:19:50 +02:00
|
|
|
WEBSERVER: {
|
|
|
|
SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
|
|
|
|
HOSTNAME: config.get<string>('webserver.hostname'),
|
|
|
|
PORT: config.get<number>('webserver.port')
|
|
|
|
},
|
2020-02-13 11:49:03 +01:00
|
|
|
ELASTIC_SEARCH: {
|
2021-02-03 11:49:26 +01:00
|
|
|
HTTP: config.get<string>('elastic-search.http'),
|
2021-02-04 08:55:02 +01:00
|
|
|
AUTH: {
|
|
|
|
USERNAME: config.get<string>('elastic-search.auth.username'),
|
|
|
|
PASSWORD: config.get<string>('elastic-search.auth.password')
|
|
|
|
},
|
2021-02-03 11:49:26 +01:00
|
|
|
SSL: {
|
|
|
|
CA: config.get<string>('elastic-search.ssl.ca')
|
|
|
|
},
|
2020-09-18 16:29:32 +02:00
|
|
|
HOSTNAME: config.get<string>('elastic-search.hostname'),
|
|
|
|
PORT: config.get<number>('elastic-search.port'),
|
2020-02-13 11:49:03 +01:00
|
|
|
INDEXES: {
|
2020-09-18 16:29:32 +02:00
|
|
|
VIDEOS: config.get<string>('elastic-search.indexes.videos'),
|
2021-06-24 15:18:54 +02:00
|
|
|
CHANNELS: config.get<string>('elastic-search.indexes.channels'),
|
|
|
|
PLAYLISTS: config.get<string>('elastic-search.indexes.playlists')
|
2020-02-13 11:49:03 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
LOG: {
|
|
|
|
LEVEL: config.get<string>('log.level')
|
|
|
|
},
|
2020-08-27 14:44:21 +02:00
|
|
|
SEARCH_INSTANCE: {
|
2020-09-02 14:07:22 +02:00
|
|
|
NAME: config.get<string>('search-instance.name'),
|
2020-09-18 16:29:32 +02:00
|
|
|
NAME_IMAGE: config.get<string>('search-instance.name_image'),
|
|
|
|
SEARCH_IMAGE: config.get<string>('search-instance.search_image'),
|
2020-09-02 14:07:22 +02:00
|
|
|
DESCRIPTION: config.get<string>('search-instance.description'),
|
2020-09-18 16:29:32 +02:00
|
|
|
LEGAL_NOTICES_URL: config.get<string>('search-instance.legal_notices_url'),
|
|
|
|
THEME: config.get<string>('search-instance.theme')
|
2020-08-27 14:44:21 +02:00
|
|
|
},
|
2020-09-23 11:17:43 +02:00
|
|
|
VIDEOS_SEARCH: {
|
|
|
|
BOOST_LANGUAGES: {
|
|
|
|
ENABLED: config.get<boolean>('videos-search.boost-languages.enabled')
|
2020-10-23 10:14:44 +02:00
|
|
|
},
|
|
|
|
SEARCH_FIELDS: {
|
|
|
|
NAME: {
|
|
|
|
FIELD_NAME: 'name',
|
|
|
|
BOOST: config.get<number>('videos-search.search-fields.name.boost')
|
|
|
|
},
|
|
|
|
DESCRIPTION: {
|
|
|
|
FIELD_NAME: 'description',
|
|
|
|
BOOST: config.get<number>('videos-search.search-fields.description.boost')
|
|
|
|
},
|
|
|
|
TAGS: {
|
|
|
|
FIELD_NAME: 'tags',
|
|
|
|
BOOST: config.get<number>('videos-search.search-fields.tags.boost')
|
|
|
|
},
|
|
|
|
ACCOUNT_DISPLAY_NAME: {
|
|
|
|
FIELD_NAME: 'account.displayName',
|
|
|
|
BOOST: config.get<number>('videos-search.search-fields.account-display-name.boost')
|
|
|
|
},
|
|
|
|
CHANNEL_DISPLAY_NAME: {
|
|
|
|
FIELD_NAME: 'channel.displayName',
|
|
|
|
BOOST: config.get<number>('videos-search.search-fields.channel-display-name.boost')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
CHANNELS_SEARCH: {
|
|
|
|
SEARCH_FIELDS: {
|
|
|
|
NAME: {
|
|
|
|
FIELD_NAME: 'name',
|
|
|
|
BOOST: config.get<number>('channels-search.search-fields.name.boost')
|
|
|
|
},
|
|
|
|
DESCRIPTION: {
|
|
|
|
FIELD_NAME: 'description',
|
|
|
|
BOOST: config.get<number>('channels-search.search-fields.description.boost')
|
|
|
|
},
|
|
|
|
DISPLAY_NAME: {
|
|
|
|
FIELD_NAME: 'displayName',
|
|
|
|
BOOST: config.get<number>('channels-search.search-fields.display-name.boost')
|
|
|
|
},
|
|
|
|
ACCOUNT_DISPLAY_NAME: {
|
|
|
|
FIELD_NAME: 'ownerAccount.displayName',
|
|
|
|
BOOST: config.get<number>('channels-search.search-fields.account-display-name.boost')
|
|
|
|
}
|
2020-09-23 11:17:43 +02:00
|
|
|
}
|
|
|
|
},
|
2021-06-24 15:18:54 +02:00
|
|
|
PLAYLISTS_SEARCH: {
|
|
|
|
SEARCH_FIELDS: {
|
2021-06-24 16:53:43 +02:00
|
|
|
DISPLAY_NAME: {
|
|
|
|
FIELD_NAME: 'displayName',
|
|
|
|
BOOST: config.get<number>('playlists-search.search-fields.display-name.boost')
|
2021-06-24 15:18:54 +02:00
|
|
|
},
|
|
|
|
DESCRIPTION: {
|
|
|
|
FIELD_NAME: 'description',
|
|
|
|
BOOST: config.get<number>('playlists-search.search-fields.description.boost')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-02-14 14:09:31 +01:00
|
|
|
INSTANCES_INDEX: {
|
2020-06-11 11:04:00 +02:00
|
|
|
URL: config.get<string>('instances-index.url'),
|
2020-09-02 10:17:50 +02:00
|
|
|
PUBLIC_URL: config.get<string>('instances-index.public_url'),
|
2020-06-11 11:04:00 +02:00
|
|
|
WHITELIST: {
|
|
|
|
ENABLED: config.get<boolean>('instances-index.whitelist.enabled'),
|
|
|
|
HOSTS: config.get<string[]>('instances-index.whitelist.hosts')
|
|
|
|
}
|
2020-05-28 15:00:37 +02:00
|
|
|
},
|
2020-06-11 11:04:00 +02:00
|
|
|
API: {
|
|
|
|
BLACKLIST: {
|
|
|
|
ENABLED: config.get<boolean>('api.blacklist.enabled'),
|
|
|
|
HOSTS: config.get<string[]>('api.blacklist.hosts')
|
|
|
|
}
|
2020-02-13 11:49:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const SORTABLE_COLUMNS = {
|
2020-05-29 09:28:48 +02:00
|
|
|
VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'match' ],
|
2021-06-24 15:18:54 +02:00
|
|
|
CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ],
|
|
|
|
PLAYLISTS_SEARCH: [ 'match', 'displayName', 'createdAt' ]
|
2020-02-13 11:49:03 +01:00
|
|
|
}
|
|
|
|
|
2021-08-02 15:54:29 +02:00
|
|
|
const PAGINATION_COUNT = {
|
|
|
|
DEFAULT: 20,
|
|
|
|
MAX: 500
|
|
|
|
}
|
2020-02-13 11:49:03 +01:00
|
|
|
|
2020-02-13 16:06:52 +01:00
|
|
|
const SCHEDULER_INTERVALS_MS = {
|
2021-06-24 16:53:43 +02:00
|
|
|
indexation: 60000 * 60 * 24 // 24 hours
|
2020-02-13 16:06:52 +01:00
|
|
|
}
|
|
|
|
|
2021-06-24 15:18:54 +02:00
|
|
|
const INDEXER_COUNT = 10
|
|
|
|
const INDEXER_LIMIT = 500000
|
2020-02-13 11:49:03 +01:00
|
|
|
|
2021-06-24 16:53:43 +02:00
|
|
|
const INDEXER_HOST_CONCURRENCY = 3
|
2020-03-04 15:32:39 +01:00
|
|
|
const INDEXER_QUEUE_CONCURRENCY = 3
|
|
|
|
|
|
|
|
const REQUESTS = {
|
|
|
|
MAX_RETRIES: 10,
|
|
|
|
WAIT: 10000 // 10 seconds
|
|
|
|
}
|
|
|
|
|
2020-09-23 10:35:23 +02:00
|
|
|
const ELASTIC_SEARCH_QUERY = {
|
2020-09-23 11:17:43 +02:00
|
|
|
FUZZINESS: 'AUTO:4,7',
|
2020-10-23 10:14:44 +02:00
|
|
|
BOOST_LANGUAGE_VALUE: 2,
|
|
|
|
VIDEOS_MULTI_MATCH_FIELDS: buildMultiMatchFields(CONFIG.VIDEOS_SEARCH.SEARCH_FIELDS),
|
2021-06-24 15:18:54 +02:00
|
|
|
CHANNELS_MULTI_MATCH_FIELDS: buildMultiMatchFields(CONFIG.CHANNELS_SEARCH.SEARCH_FIELDS),
|
|
|
|
PLAYLISTS_MULTI_MATCH_FIELDS: buildMultiMatchFields(CONFIG.PLAYLISTS_SEARCH.SEARCH_FIELDS)
|
2020-09-23 10:35:23 +02:00
|
|
|
}
|
|
|
|
|
2020-09-02 16:24:25 +02:00
|
|
|
function getWebserverUrl () {
|
|
|
|
if (CONFIG.WEBSERVER.PORT === 80 || CONFIG.WEBSERVER.PORT === 443) {
|
|
|
|
return CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME
|
|
|
|
}
|
|
|
|
|
|
|
|
return CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
|
|
|
|
}
|
|
|
|
|
2020-10-23 10:14:44 +02:00
|
|
|
function buildMultiMatchFields (fields: { [name: string]: { BOOST: number, FIELD_NAME: string } }) {
|
|
|
|
return Object.keys(fields)
|
|
|
|
.map(id => {
|
|
|
|
const obj = fields[id]
|
|
|
|
if (obj.BOOST <= 0) return ''
|
|
|
|
|
|
|
|
return `${obj.FIELD_NAME}^${obj.BOOST}`
|
|
|
|
})
|
|
|
|
.filter(v => !!v)
|
|
|
|
}
|
|
|
|
|
2020-02-13 11:49:03 +01:00
|
|
|
if (isTestInstance()) {
|
2021-06-24 16:53:43 +02:00
|
|
|
SCHEDULER_INTERVALS_MS.indexation = 1000 * 60 * 5 // 5 minutes
|
2020-02-13 11:49:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
2020-09-02 16:24:25 +02:00
|
|
|
getWebserverUrl,
|
|
|
|
|
2020-02-13 11:49:03 +01:00
|
|
|
CONFIG,
|
|
|
|
API_VERSION,
|
2021-08-02 15:54:29 +02:00
|
|
|
PAGINATION_COUNT,
|
2020-02-13 11:49:03 +01:00
|
|
|
SORTABLE_COLUMNS,
|
2020-03-04 15:32:39 +01:00
|
|
|
INDEXER_QUEUE_CONCURRENCY,
|
2020-02-13 16:06:52 +01:00
|
|
|
SCHEDULER_INTERVALS_MS,
|
2021-06-24 16:53:43 +02:00
|
|
|
INDEXER_HOST_CONCURRENCY,
|
2020-03-04 15:32:39 +01:00
|
|
|
INDEXER_COUNT,
|
2021-06-24 15:18:54 +02:00
|
|
|
INDEXER_LIMIT,
|
2020-09-23 10:35:23 +02:00
|
|
|
REQUESTS,
|
|
|
|
ELASTIC_SEARCH_QUERY
|
2020-02-13 11:49:03 +01:00
|
|
|
}
|