1 import * as config from 'config'
3 import { promisify0 } from '../helpers/core-utils'
4 import { OAuthClientModel } from '../models/oauth/oauth-client-interface'
5 import { UserModel } from '../models/user/user-interface'
7 // Some checks on configuration files
8 function checkConfig () {
9 if (config.has('webserver.host')) {
10 let errorMessage = '`host` config key was renamed to `hostname` but it seems you still have a `host` key in your configuration files!'
11 errorMessage += ' Please ensure to rename your `host` configuration to `hostname`.'
19 // Check the config files
20 function checkMissedConfig () {
21 const required = [ 'listen.port',
22 'webserver.https', 'webserver.hostname', 'webserver.port',
23 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password',
24 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', 'storage.torrents', 'storage.cache',
25 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads', 'user.video_quota'
27 const miss: string[] = []
29 for (const key of required) {
30 if (!config.has(key)) {
38 // Check the available codecs
39 // We get CONFIG by param to not import it in this file (import orders)
40 function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
41 const Ffmpeg = require('fluent-ffmpeg')
42 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
44 getAvailableCodecsPromise()
46 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
48 const canEncode = [ 'libx264' ]
49 canEncode.forEach(codec => {
50 if (codecs[codec] === undefined) {
51 throw new Error('Unknown codec ' + codec + ' in FFmpeg.')
54 if (codecs[codec].canEncode !== true) {
55 throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg')
61 // We get db by param to not import it in this file (import orders)
62 function clientsExist (OAuthClient: OAuthClientModel) {
63 return OAuthClient.countTotal().then(totalClients => {
64 return totalClients !== 0
68 // We get db by param to not import it in this file (import orders)
69 function usersExist (User: UserModel) {
70 return User.countTotal().then(totalUsers => {
71 return totalUsers !== 0
75 // ---------------------------------------------------------------------------