]>
Commit | Line | Data |
---|---|---|
4d4e5cd4 | 1 | import * as config from 'config' |
da854ddd | 2 | import { promisify0 } from '../helpers/core-utils' |
3fd3ab2d C |
3 | import { UserModel } from '../models/account/user' |
4 | import { ApplicationModel } from '../models/application/application' | |
5 | import { OAuthClientModel } from '../models/oauth/oauth-client' | |
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', |
23e27dd5 | 24 | 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', 'storage.torrents', 'storage.cache', 'log.level', |
ecb4e35f C |
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' | |
56835348 | 27 | ] |
69818c93 | 28 | const miss: string[] = [] |
9f10b292 | 29 | |
f0f5567b | 30 | for (const key of required) { |
9f10b292 C |
31 | if (!config.has(key)) { |
32 | miss.push(key) | |
8c308c2b | 33 | } |
8c308c2b C |
34 | } |
35 | ||
9f10b292 C |
36 | return miss |
37 | } | |
38 | ||
e5b88539 | 39 | // Check the available codecs |
3482688c | 40 | // We get CONFIG by param to not import it in this file (import orders) |
f5028693 | 41 | async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) { |
e5b88539 | 42 | const Ffmpeg = require('fluent-ffmpeg') |
6fcd19ba C |
43 | const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) |
44 | ||
f5028693 C |
45 | const codecs = await getAvailableCodecsPromise() |
46 | if (CONFIG.TRANSCODING.ENABLED === false) return undefined | |
47 | ||
48 | const canEncode = [ 'libx264' ] | |
49 | for (const codec of canEncode) { | |
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 C |
58 | } |
59 | ||
3482688c | 60 | // We get db by param to not import it in this file (import orders) |
3fd3ab2d C |
61 | async function clientsExist () { |
62 | const totalClients = await OAuthClientModel.countTotal() | |
f5028693 C |
63 | |
64 | return totalClients !== 0 | |
37dc07b2 C |
65 | } |
66 | ||
3482688c | 67 | // We get db by param to not import it in this file (import orders) |
3fd3ab2d C |
68 | async function usersExist () { |
69 | const totalUsers = await UserModel.countTotal() | |
f5028693 C |
70 | |
71 | return totalUsers !== 0 | |
9f10b292 | 72 | } |
8c308c2b | 73 | |
350e31d6 | 74 | // We get db by param to not import it in this file (import orders) |
3fd3ab2d C |
75 | async function applicationExist () { |
76 | const totalApplication = await ApplicationModel.countTotal() | |
350e31d6 C |
77 | |
78 | return totalApplication !== 0 | |
79 | } | |
80 | ||
9f10b292 | 81 | // --------------------------------------------------------------------------- |
c45f7f84 | 82 | |
65fcc311 C |
83 | export { |
84 | checkConfig, | |
85 | checkFFmpeg, | |
86 | checkMissedConfig, | |
87 | clientsExist, | |
350e31d6 C |
88 | usersExist, |
89 | applicationExist | |
65fcc311 | 90 | } |