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', 'listen.hostname',
22 'webserver.https', 'webserver.hostname', 'webserver.port',
24 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password',
25 'redis.hostname', 'redis.port', 'redis.auth',
26 'smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address',
27 'storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache',
30 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads',
31 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route'
33 const miss: string[] = []
35 for (const key of required) {
36 if (!config.has(key)) {
44 // Check the available codecs
45 // We get CONFIG by param to not import it in this file (import orders)
46 async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
47 const Ffmpeg = require('fluent-ffmpeg')
48 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
50 const codecs = await getAvailableCodecsPromise()
51 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
53 const canEncode = [ 'libx264' ]
54 for (const codec of canEncode) {
55 if (codecs[codec] === undefined) {
56 throw new Error('Unknown codec ' + codec + ' in FFmpeg.')
59 if (codecs[codec].canEncode !== true) {
60 throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg')
65 // We get db by param to not import it in this file (import orders)
66 async function clientsExist () {
67 const totalClients = await OAuthClientModel.countTotal()
69 return totalClients !== 0
72 // We get db by param to not import it in this file (import orders)
73 async function usersExist () {
74 const totalUsers = await UserModel.countTotal()
76 return totalUsers !== 0
79 // We get db by param to not import it in this file (import orders)
80 async function applicationExist () {
81 const totalApplication = await ApplicationModel.countTotal()
83 return totalApplication !== 0
86 // ---------------------------------------------------------------------------