import * as config from 'config' import { isTestInstance } from '../helpers/core-utils' const API_VERSION = 'v1' const CONFIG = { LISTEN: { PORT: config.get('listen.port') }, WEBSERVER: { SCHEME: config.get('webserver.https') === true ? 'https' : 'http', HOSTNAME: config.get('webserver.hostname'), PORT: config.get('webserver.port') }, ELASTIC_SEARCH: { HTTP: config.get('elastic-search.http'), AUTH: { USERNAME: config.get('elastic-search.auth.username'), PASSWORD: config.get('elastic-search.auth.password') }, SSL: { CA: config.get('elastic-search.ssl.ca') }, HOSTNAME: config.get('elastic-search.hostname'), PORT: config.get('elastic-search.port'), INDEXES: { VIDEOS: config.get('elastic-search.indexes.videos'), CHANNELS: config.get('elastic-search.indexes.channels'), PLAYLISTS: config.get('elastic-search.indexes.playlists') } }, LOG: { LEVEL: config.get('log.level') }, SEARCH_INSTANCE: { NAME: config.get('search-instance.name'), NAME_IMAGE: config.get('search-instance.name_image'), SEARCH_IMAGE: config.get('search-instance.search_image'), DESCRIPTION: config.get('search-instance.description'), LEGAL_NOTICES_URL: config.get('search-instance.legal_notices_url'), THEME: config.get('search-instance.theme') }, VIDEOS_SEARCH: { BOOST_LANGUAGES: { ENABLED: config.get('videos-search.boost-languages.enabled') }, SEARCH_FIELDS: { NAME: { FIELD_NAME: 'name', BOOST: config.get('videos-search.search-fields.name.boost') }, DESCRIPTION: { FIELD_NAME: 'description', BOOST: config.get('videos-search.search-fields.description.boost') }, TAGS: { FIELD_NAME: 'tags', BOOST: config.get('videos-search.search-fields.tags.boost') }, ACCOUNT_DISPLAY_NAME: { FIELD_NAME: 'account.displayName', BOOST: config.get('videos-search.search-fields.account-display-name.boost') }, CHANNEL_DISPLAY_NAME: { FIELD_NAME: 'channel.displayName', BOOST: config.get('videos-search.search-fields.channel-display-name.boost') } } }, CHANNELS_SEARCH: { SEARCH_FIELDS: { NAME: { FIELD_NAME: 'name', BOOST: config.get('channels-search.search-fields.name.boost') }, DESCRIPTION: { FIELD_NAME: 'description', BOOST: config.get('channels-search.search-fields.description.boost') }, DISPLAY_NAME: { FIELD_NAME: 'displayName', BOOST: config.get('channels-search.search-fields.display-name.boost') }, ACCOUNT_DISPLAY_NAME: { FIELD_NAME: 'ownerAccount.displayName', BOOST: config.get('channels-search.search-fields.account-display-name.boost') } } }, PLAYLISTS_SEARCH: { SEARCH_FIELDS: { DISPLAY_NAME: { FIELD_NAME: 'displayName', BOOST: config.get('playlists-search.search-fields.display-name.boost') }, DESCRIPTION: { FIELD_NAME: 'description', BOOST: config.get('playlists-search.search-fields.description.boost') } } }, INSTANCES_INDEX: { URL: config.get('instances-index.url'), PUBLIC_URL: config.get('instances-index.public_url'), WHITELIST: { ENABLED: config.get('instances-index.whitelist.enabled'), HOSTS: config.get('instances-index.whitelist.hosts') } }, API: { BLACKLIST: { ENABLED: config.get('api.blacklist.enabled'), HOSTS: config.get('api.blacklist.hosts') } } } const SORTABLE_COLUMNS = { VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'match' ], CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ], PLAYLISTS_SEARCH: [ 'match', 'displayName', 'createdAt' ] } const PAGINATION_START = { MAX: 9000 } const PAGINATION_COUNT = { DEFAULT: 20, MAX: 500 } const SCHEDULER_INTERVALS_MS = { indexation: 60000 * 60 * 24 // 24 hours } const INDEXER_COUNT = 10 const INDEXER_LIMIT = 500000 const INDEXER_HOST_CONCURRENCY = 3 const INDEXER_QUEUE_CONCURRENCY = 3 const REQUESTS = { MAX_RETRIES: 10, WAIT: 10000 // 10 seconds } const ELASTIC_SEARCH_QUERY = { FUZZINESS: 'AUTO:4,7', BOOST_LANGUAGE_VALUE: 2, VIDEOS_MULTI_MATCH_FIELDS: buildMultiMatchFields(CONFIG.VIDEOS_SEARCH.SEARCH_FIELDS), CHANNELS_MULTI_MATCH_FIELDS: buildMultiMatchFields(CONFIG.CHANNELS_SEARCH.SEARCH_FIELDS), PLAYLISTS_MULTI_MATCH_FIELDS: buildMultiMatchFields(CONFIG.PLAYLISTS_SEARCH.SEARCH_FIELDS) } 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 } 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) } if (isTestInstance()) { SCHEDULER_INTERVALS_MS.indexation = 1000 * 60 * 5 // 5 minutes } export { getWebserverUrl, CONFIG, API_VERSION, PAGINATION_COUNT, PAGINATION_START, SORTABLE_COLUMNS, INDEXER_QUEUE_CONCURRENCY, SCHEDULER_INTERVALS_MS, INDEXER_HOST_CONCURRENCY, INDEXER_COUNT, INDEXER_LIMIT, REQUESTS, ELASTIC_SEARCH_QUERY }