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 // Return an error message, or null if everything is okay
9 function checkConfig () {
10 const defaultNSFWPolicy = config.get<string>('instance.default_nsfw_policy')
12 if ([ 'do_not_list', 'blur', 'display' ].indexOf(defaultNSFWPolicy) === -1) {
13 return 'NSFW policy setting should be "do_not_list" or "blur" or "display" instead of ' + defaultNSFWPolicy
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',
32 'instance.default_nsfw_policy', 'instance.robots',
33 'services.twitter.username', 'services.twitter.whitelisted'
35 const miss: string[] = []
37 for (const key of required) {
38 if (!config.has(key)) {
46 // Check the available codecs
47 // We get CONFIG by param to not import it in this file (import orders)
48 async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
49 const Ffmpeg = require('fluent-ffmpeg')
50 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
52 const codecs = await getAvailableCodecsPromise()
53 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
55 const canEncode = [ 'libx264' ]
56 for (const codec of canEncode) {
57 if (codecs[codec] === undefined) {
58 throw new Error('Unknown codec ' + codec + ' in FFmpeg.')
61 if (codecs[codec].canEncode !== true) {
62 throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg')
67 // We get db by param to not import it in this file (import orders)
68 async function clientsExist () {
69 const totalClients = await OAuthClientModel.countTotal()
71 return totalClients !== 0
74 // We get db by param to not import it in this file (import orders)
75 async function usersExist () {
76 const totalUsers = await UserModel.countTotal()
78 return totalUsers !== 0
81 // We get db by param to not import it in this file (import orders)
82 async function applicationExist () {
83 const totalApplication = await ApplicationModel.countTotal()
85 return totalApplication !== 0
88 // ---------------------------------------------------------------------------