"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VIDEO_PLAYLIST_TYPES = exports.VIDEO_IMPORT_TIMEOUT = exports.STATIC_PATHS = exports.STATIC_MAX_AGE = exports.NSFW_POLICY_TYPES = exports.DEFAULT_THEME_NAME = exports.JOB_TTL = exports.SORTABLE_COLUMNS = exports.ROUTE_CACHE_LIFETIME = exports.VIDEO_FILTERS = exports.PRIVATE_RSA_KEY_SIZE = exports.PLUGIN_GLOBAL_CSS_PATH = exports.PLUGIN_GLOBAL_CSS_FILE_NAME = exports.TWO_FACTOR_AUTH_REQUEST_TOKEN_LIFETIME = exports.SERVER_ACTOR_NAME = exports.DEFAULT_USER_THEME_NAME = exports.FOLLOW_STATES = exports.REMOTE_SCHEME = exports.PREVIEWS_SIZE = exports.ACTOR_FOLLOW_SCORE = exports.PAGINATION = exports.AUDIT_LOG_FILENAME = exports.BROADCAST_CONCURRENCY = exports.STATS_TIMESERIE = exports.CUSTOM_HTML_TAG_COMMENTS = exports.OAUTH_LIFETIME = exports.LAST_MIGRATION_VERSION = exports.AP_CLEANER = exports.JOB_ATTEMPTS = exports.JOB_CONCURRENCY = exports.REDUNDANCY = exports.EMBED_SIZE = exports.CONSTRAINTS_FIELDS = exports.LOG_FILENAME = exports.FILES_CACHE = exports.TRACKER_RATE_LIMITS = exports.BCRYPT_SALT_SIZE = exports.ACCEPT_HEADERS = exports.ACTOR_IMAGES_SIZE = exports.P2P_MEDIA_LOADER_PEER_VERSION = exports.RESUMABLE_UPLOAD_SESSION_LIFETIME = exports.DIRECTORIES = exports.SEARCH_INDEX = exports.OBJECT_STORAGE_PROXY_PATHS = exports.LAZY_STATIC_PATHS = exports.PEERTUBE_VERSION = exports.VIDEO_LIVE = exports.ENCRYPTION = exports.API_VERSION = exports.WEBSERVER = void 0;
exports.generateContentHash = exports.buildLanguages = exports.loadLanguages = exports.OTP = exports.FILES_CONTENT_HASH = exports.ASSETS_PATH = exports.PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = exports.VIDEO_PLAYLIST_PRIVACIES = exports.CONTACT_FORM_LIFETIME = exports.VIEW_LIFETIME = exports.VIDEO_CHANNEL_SYNC_STATE = exports.VIDEO_IMPORT_STATES = exports.HTTP_SIGNATURE = exports.JOB_REMOVAL_OPTIONS = exports.BINARY_CONTENT_TYPES = exports.DEFAULT_AUDIO_RESOLUTION = exports.CRAWL_REQUEST_CONCURRENCY = exports.MIMETYPES = exports.STATIC_DOWNLOAD_PATHS = exports.REPEAT_JOBS = exports.SCHEDULER_INTERVALS_MS = exports.OVERVIEWS = exports.USER_EMAIL_VERIFY_LIFETIME = exports.MEMOIZE_TTL = exports.USER_PASSWORD_CREATE_LIFETIME = exports.USER_PASSWORD_RESET_LIFETIME = exports.MAX_LOCAL_VIEWER_WATCH_SECTIONS = exports.REQUEST_TIMEOUTS = exports.LRU_CACHE = exports.ABUSE_STATES = exports.FFMPEG_NICE = exports.VIDEO_TRANSCODING_FPS = exports.JOB_PRIORITY = exports.VIDEO_RATE_TYPES = exports.WORKER_THREADS = exports.VIDEO_STATES = exports.VIDEO_LICENCES = exports.VIDEO_PRIVACIES = exports.VIDEO_LANGUAGES = exports.MEMOIZE_LENGTH = exports.VIDEO_CATEGORIES = exports.THUMBNAILS_SIZE = exports.ACTIVITY_PUB_ACTOR_TYPES = exports.ACTIVITY_PUB = exports.MAX_LOGS_OUTPUT_CHARACTERS = void 0;
const crypto_1 = require("crypto");
const lodash_1 = require("lodash");
const path_1 = require("path");
const core_utils_1 = require("../../shared/core-utils");
const core_utils_2 = require("../helpers/core-utils");
const config_1 = require("./config");
const LAST_MIGRATION_VERSION = 745;
exports.LAST_MIGRATION_VERSION = LAST_MIGRATION_VERSION;
const API_VERSION = 'v1';
exports.API_VERSION = API_VERSION;
const PEERTUBE_VERSION = require((0, path_1.join)((0, core_utils_1.root)(), 'package.json')).version;
exports.PEERTUBE_VERSION = PEERTUBE_VERSION;
const PAGINATION = {
    GLOBAL: {
        COUNT: {
            DEFAULT: 15,
            MAX: 100
        }
    },
    OUTBOX: {
        COUNT: {
            MAX: 50
        }
    }
};
exports.PAGINATION = PAGINATION;
const WEBSERVER = {
    URL: '',
    HOST: '',
    SCHEME: '',
    WS: '',
    HOSTNAME: '',
    PORT: 0,
    RTMP_URL: '',
    RTMPS_URL: ''
};
exports.WEBSERVER = WEBSERVER;
const SORTABLE_COLUMNS = {
    ADMIN_USERS: ['id', 'username', 'videoQuotaUsed', 'createdAt', 'lastLoginDate', 'role'],
    USER_SUBSCRIPTIONS: ['id', 'createdAt'],
    ACCOUNTS: ['createdAt'],
    JOBS: ['createdAt'],
    VIDEO_CHANNELS: ['id', 'name', 'updatedAt', 'createdAt'],
    VIDEO_IMPORTS: ['createdAt'],
    VIDEO_CHANNEL_SYNCS: ['externalChannelUrl', 'videoChannel', 'createdAt', 'lastSyncAt', 'state'],
    VIDEO_COMMENT_THREADS: ['createdAt', 'totalReplies'],
    VIDEO_COMMENTS: ['createdAt'],
    VIDEO_RATES: ['createdAt'],
    BLACKLISTS: ['id', 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid', 'createdAt'],
    INSTANCE_FOLLOWERS: ['createdAt', 'state', 'score'],
    INSTANCE_FOLLOWING: ['createdAt', 'redundancyAllowed', 'state'],
    ACCOUNT_FOLLOWERS: ['createdAt'],
    CHANNEL_FOLLOWERS: ['createdAt'],
    VIDEOS: ['name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'trending', 'hot', 'best'],
    VIDEOS_SEARCH: ['name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'match'],
    VIDEO_CHANNELS_SEARCH: ['match', 'displayName', 'createdAt'],
    VIDEO_PLAYLISTS_SEARCH: ['match', 'displayName', 'createdAt'],
    ABUSES: ['id', 'createdAt', 'state'],
    ACCOUNTS_BLOCKLIST: ['createdAt'],
    SERVERS_BLOCKLIST: ['createdAt'],
    USER_NOTIFICATIONS: ['createdAt', 'read'],
    VIDEO_PLAYLISTS: ['name', 'displayName', 'createdAt', 'updatedAt'],
    PLUGINS: ['name', 'createdAt', 'updatedAt'],
    AVAILABLE_PLUGINS: ['npmName', 'popularity'],
    VIDEO_REDUNDANCIES: ['name']
};
exports.SORTABLE_COLUMNS = SORTABLE_COLUMNS;
const OAUTH_LIFETIME = {
    ACCESS_TOKEN: 3600 * 24,
    REFRESH_TOKEN: 1209600
};
exports.OAUTH_LIFETIME = OAUTH_LIFETIME;
const ROUTE_CACHE_LIFETIME = {
    FEEDS: '15 minutes',
    ROBOTS: '2 hours',
    SITEMAP: '1 day',
    SECURITYTXT: '2 hours',
    NODEINFO: '10 minutes',
    DNT_POLICY: '1 week',
    ACTIVITY_PUB: {
        VIDEOS: '1 second'
    },
    STATS: '4 hours',
    WELL_KNOWN: '1 day'
};
exports.ROUTE_CACHE_LIFETIME = ROUTE_CACHE_LIFETIME;
const ACTOR_FOLLOW_SCORE = {
    PENALTY: -10,
    BONUS: 10,
    BASE: 1000,
    MAX: 10000
};
exports.ACTOR_FOLLOW_SCORE = ACTOR_FOLLOW_SCORE;
const FOLLOW_STATES = {
    PENDING: 'pending',
    ACCEPTED: 'accepted',
    REJECTED: 'rejected'
};
exports.FOLLOW_STATES = FOLLOW_STATES;
const REMOTE_SCHEME = {
    HTTP: 'https',
    WS: 'wss'
};
exports.REMOTE_SCHEME = REMOTE_SCHEME;
const JOB_ATTEMPTS = {
    'activitypub-http-broadcast': 1,
    'activitypub-http-broadcast-parallel': 1,
    'activitypub-http-unicast': 1,
    'activitypub-http-fetcher': 2,
    'activitypub-follow': 5,
    'activitypub-cleaner': 1,
    'video-file-import': 1,
    'video-transcoding': 1,
    'video-import': 1,
    'email': 5,
    'actor-keys': 3,
    'videos-views-stats': 1,
    'activitypub-refresher': 1,
    'video-redundancy': 1,
    'video-live-ending': 1,
    'video-studio-edition': 1,
    'manage-video-torrent': 1,
    'video-channel-import': 1,
    'after-video-channel-import': 1,
    'move-to-object-storage': 3,
    'notify': 1,
    'federate-video': 1
};
exports.JOB_ATTEMPTS = JOB_ATTEMPTS;
const JOB_CONCURRENCY = {
    'activitypub-http-broadcast': 1,
    'activitypub-http-broadcast-parallel': 30,
    'activitypub-http-unicast': 30,
    'activitypub-http-fetcher': 3,
    'activitypub-cleaner': 1,
    'activitypub-follow': 1,
    'video-file-import': 1,
    'email': 5,
    'actor-keys': 1,
    'videos-views-stats': 1,
    'activitypub-refresher': 1,
    'video-redundancy': 1,
    'video-live-ending': 10,
    'video-studio-edition': 1,
    'manage-video-torrent': 1,
    'move-to-object-storage': 1,
    'video-channel-import': 1,
    'after-video-channel-import': 1,
    'notify': 5,
    'federate-video': 3
};
exports.JOB_CONCURRENCY = JOB_CONCURRENCY;
const JOB_TTL = {
    'activitypub-http-broadcast': 60000 * 10,
    'activitypub-http-broadcast-parallel': 60000 * 10,
    'activitypub-http-unicast': 60000 * 10,
    'activitypub-http-fetcher': 1000 * 3600 * 10,
    'activitypub-follow': 60000 * 10,
    'activitypub-cleaner': 1000 * 3600,
    'video-file-import': 1000 * 3600,
    'video-transcoding': 1000 * 3600 * 48,
    'video-studio-edition': 1000 * 3600 * 10,
    'video-import': config_1.CONFIG.IMPORT.VIDEOS.TIMEOUT,
    'email': 60000 * 10,
    'actor-keys': 60000 * 20,
    'videos-views-stats': undefined,
    'activitypub-refresher': 60000 * 10,
    'video-redundancy': 1000 * 3600 * 3,
    'video-live-ending': 1000 * 60 * 10,
    'manage-video-torrent': 1000 * 3600 * 3,
    'move-to-object-storage': 1000 * 60 * 60 * 3,
    'video-channel-import': 1000 * 60 * 60 * 4,
    'after-video-channel-import': 60000 * 5,
    'notify': 60000 * 5,
    'federate-video': 60000 * 5
};
exports.JOB_TTL = JOB_TTL;
const REPEAT_JOBS = {
    'videos-views-stats': {
        cron: (0, core_utils_1.randomInt)(1, 20) + ' * * * *'
    },
    'activitypub-cleaner': {
        cron: '30 5 * * ' + (0, core_utils_1.randomInt)(0, 7)
    }
};
exports.REPEAT_JOBS = REPEAT_JOBS;
const JOB_PRIORITY = {
    TRANSCODING: 100
};
exports.JOB_PRIORITY = JOB_PRIORITY;
const BROADCAST_CONCURRENCY = 30;
exports.BROADCAST_CONCURRENCY = BROADCAST_CONCURRENCY;
const CRAWL_REQUEST_CONCURRENCY = 1;
exports.CRAWL_REQUEST_CONCURRENCY = CRAWL_REQUEST_CONCURRENCY;
const AP_CLEANER = {
    CONCURRENCY: 10,
    UNAVAILABLE_TRESHOLD: 3,
    PERIOD: (0, core_utils_2.parseDurationToMs)('1 week')
};
exports.AP_CLEANER = AP_CLEANER;
const REQUEST_TIMEOUTS = {
    DEFAULT: 7000,
    FILE: 30000,
    REDUNDANCY: JOB_TTL['video-redundancy']
};
exports.REQUEST_TIMEOUTS = REQUEST_TIMEOUTS;
const JOB_REMOVAL_OPTIONS = {
    COUNT: 10000,
    SUCCESS: {
        'DEFAULT': (0, core_utils_2.parseDurationToMs)('2 days'),
        'activitypub-http-broadcast-parallel': (0, core_utils_2.parseDurationToMs)('10 minutes'),
        'activitypub-http-unicast': (0, core_utils_2.parseDurationToMs)('1 hour'),
        'videos-views-stats': (0, core_utils_2.parseDurationToMs)('3 hours'),
        'activitypub-refresher': (0, core_utils_2.parseDurationToMs)('10 hours')
    },
    FAILURE: {
        DEFAULT: (0, core_utils_2.parseDurationToMs)('7 days')
    }
};
exports.JOB_REMOVAL_OPTIONS = JOB_REMOVAL_OPTIONS;
const VIDEO_IMPORT_TIMEOUT = Math.floor(JOB_TTL['video-import'] * 0.9);
exports.VIDEO_IMPORT_TIMEOUT = VIDEO_IMPORT_TIMEOUT;
const SCHEDULER_INTERVALS_MS = {
    ACTOR_FOLLOW_SCORES: 60000 * 60,
    REMOVE_OLD_JOBS: 60000 * 60,
    UPDATE_VIDEOS: 60000,
    YOUTUBE_DL_UPDATE: 60000 * 60 * 24,
    GEO_IP_UPDATE: 60000 * 60 * 24,
    VIDEO_VIEWS_BUFFER_UPDATE: config_1.CONFIG.VIEWS.VIDEOS.LOCAL_BUFFER_UPDATE_INTERVAL,
    CHECK_PLUGINS: config_1.CONFIG.PLUGINS.INDEX.CHECK_LATEST_VERSIONS_INTERVAL,
    CHECK_PEERTUBE_VERSION: 60000 * 60 * 24,
    AUTO_FOLLOW_INDEX_INSTANCES: 60000 * 60 * 24,
    REMOVE_OLD_VIEWS: 60000 * 60 * 24,
    REMOVE_OLD_HISTORY: 60000 * 60 * 24,
    UPDATE_INBOX_STATS: 1000 * 60,
    REMOVE_DANGLING_RESUMABLE_UPLOADS: 60000 * 60,
    CHANNEL_SYNC_CHECK_INTERVAL: config_1.CONFIG.IMPORT.VIDEO_CHANNEL_SYNCHRONIZATION.CHECK_INTERVAL
};
exports.SCHEDULER_INTERVALS_MS = SCHEDULER_INTERVALS_MS;
const CONSTRAINTS_FIELDS = {
    USERS: {
        NAME: { min: 1, max: 120 },
        DESCRIPTION: { min: 3, max: 1000 },
        USERNAME: { min: 1, max: 50 },
        PASSWORD: { min: 6, max: 255 },
        VIDEO_QUOTA: { min: -1 },
        VIDEO_QUOTA_DAILY: { min: -1 },
        VIDEO_LANGUAGES: { max: 500 },
        BLOCKED_REASON: { min: 3, max: 250 }
    },
    ABUSES: {
        REASON: { min: 2, max: 3000 },
        MODERATION_COMMENT: { min: 2, max: 3000 }
    },
    ABUSE_MESSAGES: {
        MESSAGE: { min: 2, max: 3000 }
    },
    VIDEO_BLACKLIST: {
        REASON: { min: 2, max: 300 }
    },
    VIDEO_CHANNELS: {
        NAME: { min: 1, max: 120 },
        DESCRIPTION: { min: 3, max: 1000 },
        SUPPORT: { min: 3, max: 1000 },
        EXTERNAL_CHANNEL_URL: { min: 3, max: 2000 },
        URL: { min: 3, max: 2000 }
    },
    VIDEO_CHANNEL_SYNCS: {
        EXTERNAL_CHANNEL_URL: { min: 3, max: 2000 }
    },
    VIDEO_CAPTIONS: {
        CAPTION_FILE: {
            EXTNAME: ['.vtt', '.srt'],
            FILE_SIZE: {
                max: 20 * 1024 * 1024
            }
        }
    },
    VIDEO_IMPORTS: {
        URL: { min: 3, max: 2000 },
        TORRENT_NAME: { min: 3, max: 255 },
        TORRENT_FILE: {
            EXTNAME: ['.torrent'],
            FILE_SIZE: {
                max: 1024 * 200
            }
        }
    },
    VIDEOS_REDUNDANCY: {
        URL: { min: 3, max: 2000 }
    },
    VIDEO_RATES: {
        URL: { min: 3, max: 2000 }
    },
    VIDEOS: {
        NAME: { min: 3, max: 120 },
        LANGUAGE: { min: 1, max: 10 },
        TRUNCATED_DESCRIPTION: { min: 3, max: 250 },
        DESCRIPTION: { min: 3, max: 10000 },
        SUPPORT: { min: 3, max: 1000 },
        IMAGE: {
            EXTNAME: ['.png', '.jpg', '.jpeg', '.webp'],
            FILE_SIZE: {
                max: 4 * 1024 * 1024
            }
        },
        EXTNAME: [],
        INFO_HASH: { min: 40, max: 40 },
        DURATION: { min: 0 },
        TAGS: { min: 0, max: 5 },
        TAG: { min: 2, max: 30 },
        VIEWS: { min: 0 },
        LIKES: { min: 0 },
        DISLIKES: { min: 0 },
        FILE_SIZE: { min: -1 },
        PARTIAL_UPLOAD_SIZE: { max: 50 * 1024 * 1024 * 1024 },
        URL: { min: 3, max: 2000 }
    },
    VIDEO_PLAYLISTS: {
        NAME: { min: 1, max: 120 },
        DESCRIPTION: { min: 3, max: 1000 },
        URL: { min: 3, max: 2000 },
        IMAGE: {
            EXTNAME: ['.jpg', '.jpeg'],
            FILE_SIZE: {
                max: 4 * 1024 * 1024
            }
        }
    },
    ACTORS: {
        PUBLIC_KEY: { min: 10, max: 5000 },
        PRIVATE_KEY: { min: 10, max: 5000 },
        URL: { min: 3, max: 2000 },
        IMAGE: {
            EXTNAME: ['.png', '.jpeg', '.jpg', '.gif', '.webp'],
            FILE_SIZE: {
                max: 4 * 1024 * 1024
            }
        }
    },
    VIDEO_EVENTS: {
        COUNT: { min: 0 }
    },
    VIDEO_COMMENTS: {
        TEXT: { min: 1, max: 10000 },
        URL: { min: 3, max: 2000 }
    },
    VIDEO_SHARE: {
        URL: { min: 3, max: 2000 }
    },
    CONTACT_FORM: {
        FROM_NAME: { min: 1, max: 120 },
        BODY: { min: 3, max: 5000 }
    },
    PLUGINS: {
        NAME: { min: 1, max: 214 },
        DESCRIPTION: { min: 1, max: 20000 }
    },
    COMMONS: {
        URL: { min: 5, max: 2000 }
    },
    VIDEO_STUDIO: {
        TASKS: { min: 1, max: 10 },
        CUT_TIME: { min: 0 }
    },
    LOGS: {
        CLIENT_MESSAGE: { min: 1, max: 1000 },
        CLIENT_STACK_TRACE: { min: 1, max: 15000 },
        CLIENT_META: { min: 1, max: 5000 },
        CLIENT_USER_AGENT: { min: 1, max: 200 }
    }
};
exports.CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS;
const VIEW_LIFETIME = {
    VIEW: config_1.CONFIG.VIEWS.VIDEOS.IP_VIEW_EXPIRATION,
    VIEWER_COUNTER: 60000 * 2,
    VIEWER_STATS: 60000 * 60
};
exports.VIEW_LIFETIME = VIEW_LIFETIME;
const MAX_LOCAL_VIEWER_WATCH_SECTIONS = 100;
exports.MAX_LOCAL_VIEWER_WATCH_SECTIONS = MAX_LOCAL_VIEWER_WATCH_SECTIONS;
let CONTACT_FORM_LIFETIME = 60000 * 60;
exports.CONTACT_FORM_LIFETIME = CONTACT_FORM_LIFETIME;
const VIDEO_TRANSCODING_FPS = {
    MIN: 1,
    STANDARD: [24, 25, 30],
    HD_STANDARD: [50, 60],
    AUDIO_MERGE: 25,
    AVERAGE: 30,
    MAX: 60,
    KEEP_ORIGIN_FPS_RESOLUTION_MIN: 720
};
exports.VIDEO_TRANSCODING_FPS = VIDEO_TRANSCODING_FPS;
const DEFAULT_AUDIO_RESOLUTION = 480;
exports.DEFAULT_AUDIO_RESOLUTION = DEFAULT_AUDIO_RESOLUTION;
const VIDEO_RATE_TYPES = {
    LIKE: 'like',
    DISLIKE: 'dislike'
};
exports.VIDEO_RATE_TYPES = VIDEO_RATE_TYPES;
const FFMPEG_NICE = {
    LIVE: 5,
    THUMBNAIL: 10,
    VOD: 15
};
exports.FFMPEG_NICE = FFMPEG_NICE;
const VIDEO_CATEGORIES = {
    1: 'Music',
    2: 'Films',
    3: 'Vehicles',
    4: 'Art',
    5: 'Sports',
    6: 'Travels',
    7: 'Gaming',
    8: 'People',
    9: 'Comedy',
    10: 'Entertainment',
    11: 'News & Politics',
    12: 'How To',
    13: 'Education',
    14: 'Activism',
    15: 'Science & Technology',
    16: 'Animals',
    17: 'Kids',
    18: 'Food'
};
exports.VIDEO_CATEGORIES = VIDEO_CATEGORIES;
const VIDEO_LICENCES = {
    1: 'Attribution',
    2: 'Attribution - Share Alike',
    3: 'Attribution - No Derivatives',
    4: 'Attribution - Non Commercial',
    5: 'Attribution - Non Commercial - Share Alike',
    6: 'Attribution - Non Commercial - No Derivatives',
    7: 'Public Domain Dedication'
};
exports.VIDEO_LICENCES = VIDEO_LICENCES;
const VIDEO_LANGUAGES = {};
exports.VIDEO_LANGUAGES = VIDEO_LANGUAGES;
const VIDEO_PRIVACIES = {
    [1]: 'Public',
    [2]: 'Unlisted',
    [3]: 'Private',
    [4]: 'Internal'
};
exports.VIDEO_PRIVACIES = VIDEO_PRIVACIES;
const VIDEO_STATES = {
    [1]: 'Published',
    [2]: 'To transcode',
    [3]: 'To import',
    [4]: 'Waiting for livestream',
    [5]: 'Livestream ended',
    [6]: 'To move to an external storage',
    [7]: 'Transcoding failed',
    [8]: 'External storage move failed',
    [9]: 'To edit*'
};
exports.VIDEO_STATES = VIDEO_STATES;
const VIDEO_IMPORT_STATES = {
    [3]: 'Failed',
    [1]: 'Pending',
    [2]: 'Success',
    [4]: 'Rejected',
    [5]: 'Cancelled',
    [6]: 'Processing'
};
exports.VIDEO_IMPORT_STATES = VIDEO_IMPORT_STATES;
const VIDEO_CHANNEL_SYNC_STATE = {
    [4]: 'Failed',
    [3]: 'Synchronized',
    [2]: 'Processing',
    [1]: 'Waiting first run'
};
exports.VIDEO_CHANNEL_SYNC_STATE = VIDEO_CHANNEL_SYNC_STATE;
const ABUSE_STATES = {
    [1]: 'Pending',
    [2]: 'Rejected',
    [3]: 'Accepted'
};
exports.ABUSE_STATES = ABUSE_STATES;
const VIDEO_PLAYLIST_PRIVACIES = {
    [1]: 'Public',
    [2]: 'Unlisted',
    [3]: 'Private'
};
exports.VIDEO_PLAYLIST_PRIVACIES = VIDEO_PLAYLIST_PRIVACIES;
const VIDEO_PLAYLIST_TYPES = {
    [1]: 'Regular',
    [2]: 'Watch later'
};
exports.VIDEO_PLAYLIST_TYPES = VIDEO_PLAYLIST_TYPES;
const MIMETYPES = {
    AUDIO: {
        MIMETYPE_EXT: {
            'audio/mpeg': '.mp3',
            'audio/mp3': '.mp3',
            'application/ogg': '.ogg',
            'audio/ogg': '.ogg',
            'audio/x-ms-wma': '.wma',
            'audio/wav': '.wav',
            'audio/x-wav': '.wav',
            'audio/x-flac': '.flac',
            'audio/flac': '.flac',
            'audio/vnd.dlna.adts': '.aac',
            'audio/aac': '.aac',
            'audio/m4a': '.m4a',
            'audio/mp4': '.m4a',
            'audio/x-m4a': '.m4a',
            'audio/vnd.dolby.dd-raw': '.ac3',
            'audio/ac3': '.ac3'
        },
        EXT_MIMETYPE: null
    },
    VIDEO: {
        MIMETYPE_EXT: null,
        MIMETYPES_REGEX: null,
        EXT_MIMETYPE: null
    },
    IMAGE: {
        MIMETYPE_EXT: {
            'image/png': '.png',
            'image/gif': '.gif',
            'image/webp': '.webp',
            'image/jpg': '.jpg',
            'image/jpeg': '.jpg'
        },
        EXT_MIMETYPE: null
    },
    VIDEO_CAPTIONS: {
        MIMETYPE_EXT: {
            'text/vtt': '.vtt',
            'application/x-subrip': '.srt',
            'text/plain': '.srt'
        }
    },
    TORRENT: {
        MIMETYPE_EXT: {
            'application/x-bittorrent': '.torrent'
        }
    }
};
exports.MIMETYPES = MIMETYPES;
MIMETYPES.AUDIO.EXT_MIMETYPE = (0, lodash_1.invert)(MIMETYPES.AUDIO.MIMETYPE_EXT);
MIMETYPES.IMAGE.EXT_MIMETYPE = (0, lodash_1.invert)(MIMETYPES.IMAGE.MIMETYPE_EXT);
const BINARY_CONTENT_TYPES = new Set([
    'binary/octet-stream',
    'application/octet-stream',
    'application/x-binary'
]);
exports.BINARY_CONTENT_TYPES = BINARY_CONTENT_TYPES;
const OVERVIEWS = {
    VIDEOS: {
        SAMPLE_THRESHOLD: 6,
        SAMPLES_COUNT: 20
    }
};
exports.OVERVIEWS = OVERVIEWS;
const SERVER_ACTOR_NAME = 'peertube';
exports.SERVER_ACTOR_NAME = SERVER_ACTOR_NAME;
const ACTIVITY_PUB = {
    POTENTIAL_ACCEPT_HEADERS: [
        'application/activity+json',
        'application/ld+json',
        'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
    ],
    ACCEPT_HEADER: 'application/activity+json, application/ld+json',
    PUBLIC: 'https://www.w3.org/ns/activitystreams#Public',
    COLLECTION_ITEMS_PER_PAGE: 10,
    FETCH_PAGE_LIMIT: 2000,
    URL_MIME_TYPES: {
        VIDEO: [],
        TORRENT: ['application/x-bittorrent'],
        MAGNET: ['application/x-bittorrent;x-scheme-handler/magnet']
    },
    MAX_RECURSION_COMMENTS: 100,
    ACTOR_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2,
    VIDEO_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2,
    VIDEO_PLAYLIST_REFRESH_INTERVAL: 3600 * 24 * 1000 * 2
};
exports.ACTIVITY_PUB = ACTIVITY_PUB;
const ACTIVITY_PUB_ACTOR_TYPES = {
    GROUP: 'Group',
    PERSON: 'Person',
    APPLICATION: 'Application',
    ORGANIZATION: 'Organization',
    SERVICE: 'Service'
};
exports.ACTIVITY_PUB_ACTOR_TYPES = ACTIVITY_PUB_ACTOR_TYPES;
const HTTP_SIGNATURE = {
    HEADER_NAME: 'signature',
    ALGORITHM: 'rsa-sha256',
    HEADERS_TO_SIGN: ['(request-target)', 'host', 'date', 'digest'],
    CLOCK_SKEW_SECONDS: 1800
};
exports.HTTP_SIGNATURE = HTTP_SIGNATURE;
let PRIVATE_RSA_KEY_SIZE = 2048;
exports.PRIVATE_RSA_KEY_SIZE = PRIVATE_RSA_KEY_SIZE;
const BCRYPT_SALT_SIZE = 10;
exports.BCRYPT_SALT_SIZE = BCRYPT_SALT_SIZE;
const ENCRYPTION = {
    ALGORITHM: 'aes-256-cbc',
    IV: 16,
    SALT: 'peertube',
    ENCODING: 'hex'
};
exports.ENCRYPTION = ENCRYPTION;
const USER_PASSWORD_RESET_LIFETIME = 60000 * 60;
exports.USER_PASSWORD_RESET_LIFETIME = USER_PASSWORD_RESET_LIFETIME;
const USER_PASSWORD_CREATE_LIFETIME = 60000 * 60 * 24 * 7;
exports.USER_PASSWORD_CREATE_LIFETIME = USER_PASSWORD_CREATE_LIFETIME;
const TWO_FACTOR_AUTH_REQUEST_TOKEN_LIFETIME = 60000 * 10;
exports.TWO_FACTOR_AUTH_REQUEST_TOKEN_LIFETIME = TWO_FACTOR_AUTH_REQUEST_TOKEN_LIFETIME;
const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60;
exports.USER_EMAIL_VERIFY_LIFETIME = USER_EMAIL_VERIFY_LIFETIME;
const NSFW_POLICY_TYPES = {
    DO_NOT_LIST: 'do_not_list',
    BLUR: 'blur',
    DISPLAY: 'display'
};
exports.NSFW_POLICY_TYPES = NSFW_POLICY_TYPES;
const STATIC_PATHS = {
    THUMBNAILS: '/static/thumbnails/',
    WEBSEED: '/static/webseed/',
    PRIVATE_WEBSEED: '/static/webseed/private/',
    REDUNDANCY: '/static/redundancy/',
    STREAMING_PLAYLISTS: {
        HLS: '/static/streaming-playlists/hls',
        PRIVATE_HLS: '/static/streaming-playlists/hls/private/'
    }
};
exports.STATIC_PATHS = STATIC_PATHS;
const STATIC_DOWNLOAD_PATHS = {
    TORRENTS: '/download/torrents/',
    VIDEOS: '/download/videos/',
    HLS_VIDEOS: '/download/streaming-playlists/hls/videos/'
};
exports.STATIC_DOWNLOAD_PATHS = STATIC_DOWNLOAD_PATHS;
const LAZY_STATIC_PATHS = {
    BANNERS: '/lazy-static/banners/',
    AVATARS: '/lazy-static/avatars/',
    PREVIEWS: '/lazy-static/previews/',
    VIDEO_CAPTIONS: '/lazy-static/video-captions/',
    TORRENTS: '/lazy-static/torrents/'
};
exports.LAZY_STATIC_PATHS = LAZY_STATIC_PATHS;
const OBJECT_STORAGE_PROXY_PATHS = {
    PRIVATE_WEBSEED: '/object-storage-proxy/webseed/private/',
    STREAMING_PLAYLISTS: {
        PRIVATE_HLS: '/object-storage-proxy/streaming-playlists/hls/private/'
    }
};
exports.OBJECT_STORAGE_PROXY_PATHS = OBJECT_STORAGE_PROXY_PATHS;
const STATIC_MAX_AGE = {
    SERVER: '2h',
    LAZY_SERVER: '2d',
    CLIENT: '30d'
};
exports.STATIC_MAX_AGE = STATIC_MAX_AGE;
const THUMBNAILS_SIZE = {
    width: 280,
    height: 157,
    minWidth: 150
};
exports.THUMBNAILS_SIZE = THUMBNAILS_SIZE;
const PREVIEWS_SIZE = {
    width: 850,
    height: 480,
    minWidth: 400
};
exports.PREVIEWS_SIZE = PREVIEWS_SIZE;
const ACTOR_IMAGES_SIZE = {
    [1]: [
        {
            width: 120,
            height: 120
        },
        {
            width: 48,
            height: 48
        }
    ],
    [2]: [
        {
            width: 1920,
            height: 317
        }
    ]
};
exports.ACTOR_IMAGES_SIZE = ACTOR_IMAGES_SIZE;
const EMBED_SIZE = {
    width: 560,
    height: 315
};
exports.EMBED_SIZE = EMBED_SIZE;
const FILES_CACHE = {
    PREVIEWS: {
        DIRECTORY: (0, path_1.join)(config_1.CONFIG.STORAGE.CACHE_DIR, 'previews'),
        MAX_AGE: 1000 * 3600 * 3
    },
    VIDEO_CAPTIONS: {
        DIRECTORY: (0, path_1.join)(config_1.CONFIG.STORAGE.CACHE_DIR, 'video-captions'),
        MAX_AGE: 1000 * 3600 * 3
    },
    TORRENTS: {
        DIRECTORY: (0, path_1.join)(config_1.CONFIG.STORAGE.CACHE_DIR, 'torrents'),
        MAX_AGE: 1000 * 3600 * 3
    }
};
exports.FILES_CACHE = FILES_CACHE;
const LRU_CACHE = {
    USER_TOKENS: {
        MAX_SIZE: 1000
    },
    ACTOR_IMAGE_STATIC: {
        MAX_SIZE: 500
    },
    STATIC_VIDEO_FILES_RIGHTS_CHECK: {
        MAX_SIZE: 5000,
        TTL: (0, core_utils_2.parseDurationToMs)('10 seconds')
    },
    VIDEO_TOKENS: {
        MAX_SIZE: 100000,
        TTL: (0, core_utils_2.parseDurationToMs)('8 hours')
    }
};
exports.LRU_CACHE = LRU_CACHE;
const DIRECTORIES = {
    RESUMABLE_UPLOAD: (0, path_1.join)(config_1.CONFIG.STORAGE.TMP_DIR, 'resumable-uploads'),
    HLS_STREAMING_PLAYLIST: {
        PUBLIC: (0, path_1.join)(config_1.CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls'),
        PRIVATE: (0, path_1.join)(config_1.CONFIG.STORAGE.STREAMING_PLAYLISTS_DIR, 'hls', 'private')
    },
    VIDEOS: {
        PUBLIC: config_1.CONFIG.STORAGE.VIDEOS_DIR,
        PRIVATE: (0, path_1.join)(config_1.CONFIG.STORAGE.VIDEOS_DIR, 'private')
    },
    HLS_REDUNDANCY: (0, path_1.join)(config_1.CONFIG.STORAGE.REDUNDANCY_DIR, 'hls')
};
exports.DIRECTORIES = DIRECTORIES;
const RESUMABLE_UPLOAD_SESSION_LIFETIME = SCHEDULER_INTERVALS_MS.REMOVE_DANGLING_RESUMABLE_UPLOADS;
exports.RESUMABLE_UPLOAD_SESSION_LIFETIME = RESUMABLE_UPLOAD_SESSION_LIFETIME;
const VIDEO_LIVE = {
    EXTENSION: '.ts',
    CLEANUP_DELAY: 1000 * 60 * 5,
    SEGMENT_TIME_SECONDS: {
        DEFAULT_LATENCY: 4,
        SMALL_LATENCY: 2
    },
    SEGMENTS_LIST_SIZE: 15,
    REPLAY_DIRECTORY: 'replay',
    EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION: 4,
    MAX_SOCKET_WAITING_DATA: 1024 * 1000 * 100,
    RTMP: {
        CHUNK_SIZE: 60000,
        GOP_CACHE: true,
        PING: 60,
        PING_TIMEOUT: 30,
        BASE_PATH: 'live'
    }
};
exports.VIDEO_LIVE = VIDEO_LIVE;
const MEMOIZE_TTL = {
    OVERVIEWS_SAMPLE: 1000 * 3600 * 4,
    INFO_HASH_EXISTS: 1000 * 60,
    VIDEO_DURATION: 1000 * 10,
    LIVE_ABLE_TO_UPLOAD: 1000 * 60,
    LIVE_CHECK_SOCKET_HEALTH: 1000 * 60,
    GET_STATS_FOR_OPEN_TELEMETRY_METRICS: 1000 * 60
};
exports.MEMOIZE_TTL = MEMOIZE_TTL;
const MEMOIZE_LENGTH = {
    INFO_HASH_EXISTS: 200,
    VIDEO_DURATION: 200
};
exports.MEMOIZE_LENGTH = MEMOIZE_LENGTH;
const WORKER_THREADS = {
    DOWNLOAD_IMAGE: {
        CONCURRENCY: 3,
        MAX_THREADS: 1
    },
    PROCESS_IMAGE: {
        CONCURRENCY: 1,
        MAX_THREADS: 5
    }
};
exports.WORKER_THREADS = WORKER_THREADS;
const REDUNDANCY = {
    VIDEOS: {
        RANDOMIZED_FACTOR: 5
    }
};
exports.REDUNDANCY = REDUNDANCY;
const ACCEPT_HEADERS = ['html', 'application/json'].concat(ACTIVITY_PUB.POTENTIAL_ACCEPT_HEADERS);
exports.ACCEPT_HEADERS = ACCEPT_HEADERS;
const OTP = {
    HEADER_NAME: 'x-peertube-otp',
    HEADER_REQUIRED_VALUE: 'required; app'
};
exports.OTP = OTP;
const ASSETS_PATH = {
    DEFAULT_AUDIO_BACKGROUND: (0, path_1.join)((0, core_utils_1.root)(), 'dist', 'server', 'assets', 'default-audio-background.jpg'),
    DEFAULT_LIVE_BACKGROUND: (0, path_1.join)((0, core_utils_1.root)(), 'dist', 'server', 'assets', 'default-live-background.jpg')
};
exports.ASSETS_PATH = ASSETS_PATH;
const CUSTOM_HTML_TAG_COMMENTS = {
    TITLE: '<!-- title tag -->',
    DESCRIPTION: '<!-- description tag -->',
    CUSTOM_CSS: '<!-- custom css tag -->',
    META_TAGS: '<!-- meta tags -->',
    SERVER_CONFIG: '<!-- server config -->'
};
exports.CUSTOM_HTML_TAG_COMMENTS = CUSTOM_HTML_TAG_COMMENTS;
const MAX_LOGS_OUTPUT_CHARACTERS = 10 * 1000 * 1000;
exports.MAX_LOGS_OUTPUT_CHARACTERS = MAX_LOGS_OUTPUT_CHARACTERS;
const LOG_FILENAME = 'peertube.log';
exports.LOG_FILENAME = LOG_FILENAME;
const AUDIT_LOG_FILENAME = 'peertube-audit.log';
exports.AUDIT_LOG_FILENAME = AUDIT_LOG_FILENAME;
const TRACKER_RATE_LIMITS = {
    INTERVAL: 60000 * 5,
    ANNOUNCES_PER_IP_PER_INFOHASH: 15,
    ANNOUNCES_PER_IP: 30,
    BLOCK_IP_LIFETIME: 60000 * 3
};
exports.TRACKER_RATE_LIMITS = TRACKER_RATE_LIMITS;
const P2P_MEDIA_LOADER_PEER_VERSION = 2;
exports.P2P_MEDIA_LOADER_PEER_VERSION = P2P_MEDIA_LOADER_PEER_VERSION;
const PLUGIN_GLOBAL_CSS_FILE_NAME = 'plugins-global.css';
exports.PLUGIN_GLOBAL_CSS_FILE_NAME = PLUGIN_GLOBAL_CSS_FILE_NAME;
const PLUGIN_GLOBAL_CSS_PATH = (0, path_1.join)(config_1.CONFIG.STORAGE.TMP_DIR, PLUGIN_GLOBAL_CSS_FILE_NAME);
exports.PLUGIN_GLOBAL_CSS_PATH = PLUGIN_GLOBAL_CSS_PATH;
let PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 1000 * 60 * 5;
exports.PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME;
const DEFAULT_THEME_NAME = 'default';
exports.DEFAULT_THEME_NAME = DEFAULT_THEME_NAME;
const DEFAULT_USER_THEME_NAME = 'instance-default';
exports.DEFAULT_USER_THEME_NAME = DEFAULT_USER_THEME_NAME;
const SEARCH_INDEX = {
    ROUTES: {
        VIDEOS: '/api/v1/search/videos',
        VIDEO_CHANNELS: '/api/v1/search/video-channels'
    }
};
exports.SEARCH_INDEX = SEARCH_INDEX;
const STATS_TIMESERIE = {
    MAX_DAYS: 365 * 10
};
exports.STATS_TIMESERIE = STATS_TIMESERIE;
if (process.env.PRODUCTION_CONSTANTS !== 'true') {
    if ((0, core_utils_2.isTestOrDevInstance)()) {
        exports.PRIVATE_RSA_KEY_SIZE = PRIVATE_RSA_KEY_SIZE = 1024;
        ACTOR_FOLLOW_SCORE.BASE = 20;
        REMOTE_SCHEME.HTTP = 'http';
        REMOTE_SCHEME.WS = 'ws';
        STATIC_MAX_AGE.SERVER = '0';
        SCHEDULER_INTERVALS_MS.ACTOR_FOLLOW_SCORES = 1000;
        SCHEDULER_INTERVALS_MS.REMOVE_OLD_JOBS = 10000;
        SCHEDULER_INTERVALS_MS.REMOVE_OLD_HISTORY = 5000;
        SCHEDULER_INTERVALS_MS.REMOVE_OLD_VIEWS = 5000;
        SCHEDULER_INTERVALS_MS.UPDATE_VIDEOS = 5000;
        SCHEDULER_INTERVALS_MS.AUTO_FOLLOW_INDEX_INSTANCES = 5000;
        SCHEDULER_INTERVALS_MS.UPDATE_INBOX_STATS = 5000;
        SCHEDULER_INTERVALS_MS.CHECK_PEERTUBE_VERSION = 2000;
        REPEAT_JOBS['videos-views-stats'] = { every: 5000 };
        REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 };
        AP_CLEANER.PERIOD = 5000;
        REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1;
        exports.CONTACT_FORM_LIFETIME = CONTACT_FORM_LIFETIME = 1000;
        JOB_ATTEMPTS['email'] = 1;
        FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000;
        MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000;
        MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000;
        OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2;
        exports.PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000;
        JOB_REMOVAL_OPTIONS.SUCCESS['videos-views-stats'] = 10000;
    }
    if ((0, core_utils_2.isTestInstance)()) {
        ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2;
        ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000;
        ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000;
        ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000;
        CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max = 100 * 1024;
        CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max = 400 * 1024;
        VIEW_LIFETIME.VIEWER_COUNTER = 1000 * 5;
        VIEW_LIFETIME.VIEWER_STATS = 1000 * 5;
        VIDEO_LIVE.CLEANUP_DELAY = (_a = getIntEnv('PEERTUBE_TEST_CONSTANTS_VIDEO_LIVE_CLEANUP_DELAY')) !== null && _a !== void 0 ? _a : 5000;
        VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY = 2;
        VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY = 1;
        VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1;
    }
}
updateWebserverUrls();
updateWebserverConfig();
(0, config_1.registerConfigChangedHandler)(() => {
    updateWebserverUrls();
    updateWebserverConfig();
});
const FILES_CONTENT_HASH = {
    MANIFEST: generateContentHash(),
    FAVICON: generateContentHash(),
    LOGO: generateContentHash()
};
exports.FILES_CONTENT_HASH = FILES_CONTENT_HASH;
const VIDEO_FILTERS = {
    WATERMARK: {
        SIZE_RATIO: 1 / 10,
        HORIZONTAL_MARGIN_RATIO: 1 / 20,
        VERTICAL_MARGIN_RATIO: 1 / 20
    }
};
exports.VIDEO_FILTERS = VIDEO_FILTERS;
function buildVideoMimetypeExt() {
    const data = {
        'video/webm': '.webm',
        'video/ogg': ['.ogv'],
        'video/mp4': '.mp4'
    };
    if (config_1.CONFIG.TRANSCODING.ENABLED) {
        if (config_1.CONFIG.TRANSCODING.ALLOW_ADDITIONAL_EXTENSIONS) {
            data['video/ogg'].push('.ogg');
            Object.assign(data, {
                'video/x-matroska': '.mkv',
                'video/quicktime': ['.mov', '.qt', '.mqv'],
                'video/x-m4v': '.m4v',
                'video/m4v': '.m4v',
                'video/x-flv': '.flv',
                'video/x-f4v': '.f4v',
                'video/x-ms-wmv': '.wmv',
                'video/x-msvideo': '.avi',
                'video/avi': '.avi',
                'video/3gpp': ['.3gp', '.3gpp'],
                'video/3gpp2': ['.3g2', '.3gpp2'],
                'application/x-nut': '.nut',
                'video/mp2t': '.mts',
                'video/vnd.dlna.mpeg-tts': '.mts',
                'video/m2ts': '.m2ts',
                'video/mpv': '.mpv',
                'video/mpeg2': '.m2v',
                'video/mpeg': ['.m1v', '.mpg', '.mpe', '.mpeg', '.vob'],
                'video/dvd': '.vob',
                'application/octet-stream': null,
                'application/mxf': '.mxf'
            });
        }
        if (config_1.CONFIG.TRANSCODING.ALLOW_AUDIO_FILES) {
            Object.assign(data, MIMETYPES.AUDIO.MIMETYPE_EXT);
        }
    }
    return data;
}
function updateWebserverUrls() {
    WEBSERVER.URL = (0, core_utils_2.sanitizeUrl)(config_1.CONFIG.WEBSERVER.SCHEME + '://' + config_1.CONFIG.WEBSERVER.HOSTNAME + ':' + config_1.CONFIG.WEBSERVER.PORT);
    WEBSERVER.HOST = (0, core_utils_2.sanitizeHost)(config_1.CONFIG.WEBSERVER.HOSTNAME + ':' + config_1.CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP);
    WEBSERVER.WS = config_1.CONFIG.WEBSERVER.WS;
    WEBSERVER.SCHEME = config_1.CONFIG.WEBSERVER.SCHEME;
    WEBSERVER.HOSTNAME = config_1.CONFIG.WEBSERVER.HOSTNAME;
    WEBSERVER.PORT = config_1.CONFIG.WEBSERVER.PORT;
    const rtmpHostname = config_1.CONFIG.LIVE.RTMP.PUBLIC_HOSTNAME || config_1.CONFIG.WEBSERVER.HOSTNAME;
    const rtmpsHostname = config_1.CONFIG.LIVE.RTMPS.PUBLIC_HOSTNAME || config_1.CONFIG.WEBSERVER.HOSTNAME;
    WEBSERVER.RTMP_URL = 'rtmp://' + rtmpHostname + ':' + config_1.CONFIG.LIVE.RTMP.PORT + '/' + VIDEO_LIVE.RTMP.BASE_PATH;
    WEBSERVER.RTMPS_URL = 'rtmps://' + rtmpsHostname + ':' + config_1.CONFIG.LIVE.RTMPS.PORT + '/' + VIDEO_LIVE.RTMP.BASE_PATH;
}
function updateWebserverConfig() {
    MIMETYPES.VIDEO.MIMETYPE_EXT = buildVideoMimetypeExt();
    MIMETYPES.VIDEO.MIMETYPES_REGEX = buildMimetypesRegex(MIMETYPES.VIDEO.MIMETYPE_EXT);
    ACTIVITY_PUB.URL_MIME_TYPES.VIDEO = Object.keys(MIMETYPES.VIDEO.MIMETYPE_EXT);
    MIMETYPES.VIDEO.EXT_MIMETYPE = buildVideoExtMimetype(MIMETYPES.VIDEO.MIMETYPE_EXT);
    CONSTRAINTS_FIELDS.VIDEOS.EXTNAME = Object.keys(MIMETYPES.VIDEO.EXT_MIMETYPE);
}
function buildVideoExtMimetype(obj) {
    const result = {};
    for (const mimetype of Object.keys(obj)) {
        const value = obj[mimetype];
        if (!value)
            continue;
        const extensions = Array.isArray(value) ? value : [value];
        for (const extension of extensions) {
            result[extension] = mimetype;
        }
    }
    return result;
}
function buildMimetypesRegex(obj) {
    return Object.keys(obj)
        .map(m => `(${m})`)
        .join('|');
}
function loadLanguages() {
    Object.assign(VIDEO_LANGUAGES, buildLanguages());
}
exports.loadLanguages = loadLanguages;
function buildLanguages() {
    const iso639 = require('iso-639-3');
    const languages = {};
    const additionalLanguages = {
        sgn: true,
        ase: true,
        asq: true,
        sdl: true,
        bfi: true,
        bzs: true,
        csl: true,
        cse: true,
        dsl: true,
        fsl: true,
        gsg: true,
        pks: true,
        jsl: true,
        sfs: true,
        swl: true,
        rsl: true,
        kab: true,
        lat: true,
        epo: true,
        tlh: true,
        jbo: true,
        avk: true,
        zxx: true
    };
    iso639
        .filter(l => {
        return (l.iso6391 !== undefined && l.type === 'living') ||
            additionalLanguages[l.iso6393] === true;
    })
        .forEach(l => { languages[l.iso6391 || l.iso6393] = l.name; });
    languages['oc'] = 'Occitan';
    languages['el'] = 'Greek';
    languages['tok'] = 'Toki Pona';
    languages['zh-Hans'] = 'Simplified Chinese';
    languages['zh-Hant'] = 'Traditional Chinese';
    return languages;
}
exports.buildLanguages = buildLanguages;
function generateContentHash() {
    return (0, crypto_1.randomBytes)(20).toString('hex');
}
exports.generateContentHash = generateContentHash;
function getIntEnv(path) {
    if (process.env[path])
        return parseInt(process.env[path]);
    return undefined;
}
//# sourceMappingURL=constants.js.map