1 import * as config from 'config'
2 import { promisify0 } from '../helpers/core-utils'
3 import { UserModel } from '../models/account/user'
4 import { ApplicationModel } from '../models/application/application'
5 import { OAuthClientModel } from '../models/oauth/oauth-client'
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.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', 'storage.torrents', 'storage.cache', 'log.level',
25 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads',
26 'user.video_quota', 'smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address',
27 'instance.name', 'instance.description', 'instance.terms'
29 const miss: string[] = []
31 for (const key of required) {
32 if (!config.has(key)) {
40 // Check the available codecs
41 // We get CONFIG by param to not import it in this file (import orders)
42 async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
43 const Ffmpeg = require('fluent-ffmpeg')
44 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
46 const codecs = await getAvailableCodecsPromise()
47 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
49 const canEncode = [ 'libx264' ]
50 for (const codec of canEncode) {
51 if (codecs[codec] === undefined) {
52 throw new Error('Unknown codec ' + codec + ' in FFmpeg.')
55 if (codecs[codec].canEncode !== true) {
56 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 async function clientsExist () {
63 const totalClients = await OAuthClientModel.countTotal()
65 return totalClients !== 0
68 // We get db by param to not import it in this file (import orders)
69 async function usersExist () {
70 const totalUsers = await UserModel.countTotal()
72 return totalUsers !== 0
75 // We get db by param to not import it in this file (import orders)
76 async function applicationExist () {
77 const totalApplication = await ApplicationModel.countTotal()
79 return totalApplication !== 0
82 // ---------------------------------------------------------------------------