]>
Commit | Line | Data |
---|---|---|
4d4e5cd4 | 1 | import * as config from 'config' |
9f10b292 | 2 | |
6fcd19ba | 3 | import { promisify0 } from '../helpers/core-utils' |
3482688c C |
4 | import { OAuthClientModel } from '../models/oauth/oauth-client-interface' |
5 | import { UserModel } from '../models/user/user-interface' | |
9f10b292 | 6 | |
b65c27aa | 7 | // Some checks on configuration files |
9f10b292 | 8 | function checkConfig () { |
b65c27aa C |
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`.' | |
12 | ||
13 | return errorMessage | |
14 | } | |
15 | ||
16 | return null | |
17 | } | |
18 | ||
19 | // Check the config files | |
20 | function checkMissedConfig () { | |
f0f5567b | 21 | const required = [ 'listen.port', |
3737bbaf | 22 | 'webserver.https', 'webserver.hostname', 'webserver.port', |
b769007f | 23 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', |
3482688c | 24 | 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', 'storage.torrents', 'storage.cache', |
77a5501f | 25 | 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads', 'user.video_quota' |
56835348 | 26 | ] |
69818c93 | 27 | const miss: string[] = [] |
9f10b292 | 28 | |
f0f5567b | 29 | for (const key of required) { |
9f10b292 C |
30 | if (!config.has(key)) { |
31 | miss.push(key) | |
8c308c2b | 32 | } |
8c308c2b C |
33 | } |
34 | ||
9f10b292 C |
35 | return miss |
36 | } | |
37 | ||
e5b88539 | 38 | // Check the available codecs |
3482688c C |
39 | // We get CONFIG by param to not import it in this file (import orders) |
40 | function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) { | |
e5b88539 | 41 | const Ffmpeg = require('fluent-ffmpeg') |
6fcd19ba C |
42 | const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) |
43 | ||
44 | getAvailableCodecsPromise() | |
45 | .then(codecs => { | |
46 | if (CONFIG.TRANSCODING.ENABLED === false) return undefined | |
47 | ||
48 | const canEncode = [ 'libx264' ] | |
075f16ca | 49 | canEncode.forEach(codec => { |
6fcd19ba C |
50 | if (codecs[codec] === undefined) { |
51 | throw new Error('Unknown codec ' + codec + ' in FFmpeg.') | |
52 | } | |
53 | ||
54 | if (codecs[codec].canEncode !== true) { | |
55 | throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg') | |
56 | } | |
57 | }) | |
e5b88539 | 58 | }) |
e5b88539 C |
59 | } |
60 | ||
3482688c C |
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 => { | |
6fcd19ba | 64 | return totalClients !== 0 |
37dc07b2 C |
65 | }) |
66 | } | |
67 | ||
3482688c C |
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 => { | |
6fcd19ba | 71 | return totalUsers !== 0 |
37dc07b2 | 72 | }) |
9f10b292 | 73 | } |
8c308c2b | 74 | |
9f10b292 | 75 | // --------------------------------------------------------------------------- |
c45f7f84 | 76 | |
65fcc311 C |
77 | export { |
78 | checkConfig, | |
79 | checkFFmpeg, | |
80 | checkMissedConfig, | |
81 | clientsExist, | |
82 | usersExist | |
83 | } |