]>
Commit | Line | Data |
---|---|---|
4d4e5cd4 | 1 | import * as config from 'config' |
9f10b292 | 2 | |
e02643f3 | 3 | import { database as db } from './database' |
65fcc311 | 4 | import { CONFIG } from './constants' |
9f10b292 | 5 | |
b65c27aa | 6 | // Some checks on configuration files |
9f10b292 | 7 | function checkConfig () { |
b65c27aa C |
8 | if (config.has('webserver.host')) { |
9 | let errorMessage = '`host` config key was renamed to `hostname` but it seems you still have a `host` key in your configuration files!' | |
10 | errorMessage += ' Please ensure to rename your `host` configuration to `hostname`.' | |
11 | ||
12 | return errorMessage | |
13 | } | |
14 | ||
15 | return null | |
16 | } | |
17 | ||
18 | // Check the config files | |
19 | function checkMissedConfig () { | |
f0f5567b | 20 | const required = [ 'listen.port', |
3737bbaf | 21 | 'webserver.https', 'webserver.hostname', 'webserver.port', |
b769007f | 22 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', |
4793c343 | 23 | 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', |
227d02fe | 24 | 'admin.email', 'signup.enabled', 'transcoding.enabled', 'transcoding.threads' |
56835348 | 25 | ] |
f0f5567b | 26 | const miss = [] |
9f10b292 | 27 | |
f0f5567b | 28 | for (const key of required) { |
9f10b292 C |
29 | if (!config.has(key)) { |
30 | miss.push(key) | |
8c308c2b | 31 | } |
8c308c2b C |
32 | } |
33 | ||
9f10b292 C |
34 | return miss |
35 | } | |
36 | ||
e5b88539 C |
37 | // Check the available codecs |
38 | function checkFFmpeg (callback) { | |
39 | const Ffmpeg = require('fluent-ffmpeg') | |
40 | ||
41 | Ffmpeg.getAvailableCodecs(function (err, codecs) { | |
42 | if (err) return callback(err) | |
65fcc311 | 43 | if (CONFIG.TRANSCODING.ENABLED === false) return callback(null) |
e5b88539 C |
44 | |
45 | const canEncode = [ 'libx264' ] | |
46 | canEncode.forEach(function (codec) { | |
47 | if (codecs[codec] === undefined) { | |
48 | return callback(new Error('Unknown codec ' + codec + ' in FFmpeg.')) | |
49 | } | |
50 | ||
51 | if (codecs[codec].canEncode !== true) { | |
52 | return callback(new Error('Unavailable encode codec ' + codec + ' in FFmpeg')) | |
53 | } | |
54 | }) | |
55 | ||
56 | return callback(null) | |
57 | }) | |
58 | } | |
59 | ||
37dc07b2 | 60 | function clientsExist (callback) { |
4712081f | 61 | db.OAuthClient.countTotal(function (err, totalClients) { |
37dc07b2 | 62 | if (err) return callback(err) |
9f10b292 | 63 | |
4712081f | 64 | return callback(null, totalClients !== 0) |
37dc07b2 C |
65 | }) |
66 | } | |
67 | ||
68 | function usersExist (callback) { | |
feb4bdfd | 69 | db.User.countTotal(function (err, totalUsers) { |
37dc07b2 C |
70 | if (err) return callback(err) |
71 | ||
089ff2f2 | 72 | return callback(null, totalUsers !== 0) |
37dc07b2 | 73 | }) |
9f10b292 | 74 | } |
8c308c2b | 75 | |
9f10b292 | 76 | // --------------------------------------------------------------------------- |
c45f7f84 | 77 | |
65fcc311 C |
78 | export { |
79 | checkConfig, | |
80 | checkFFmpeg, | |
81 | checkMissedConfig, | |
82 | clientsExist, | |
83 | usersExist | |
84 | } |