]>
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', |
490b595a | 23 | 'trust_proxy', |
b769007f | 24 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', |
a465bf5f C |
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', | |
28 | 'log.level', | |
29 | 'user.video_quota', | |
ecb4e35f | 30 | 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads', |
a465bf5f | 31 | 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route' |
56835348 | 32 | ] |
69818c93 | 33 | const miss: string[] = [] |
9f10b292 | 34 | |
f0f5567b | 35 | for (const key of required) { |
9f10b292 C |
36 | if (!config.has(key)) { |
37 | miss.push(key) | |
8c308c2b | 38 | } |
8c308c2b C |
39 | } |
40 | ||
9f10b292 C |
41 | return miss |
42 | } | |
43 | ||
e5b88539 | 44 | // Check the available codecs |
3482688c | 45 | // We get CONFIG by param to not import it in this file (import orders) |
f5028693 | 46 | async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) { |
e5b88539 | 47 | const Ffmpeg = require('fluent-ffmpeg') |
6fcd19ba C |
48 | const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) |
49 | ||
f5028693 C |
50 | const codecs = await getAvailableCodecsPromise() |
51 | if (CONFIG.TRANSCODING.ENABLED === false) return undefined | |
52 | ||
53 | const canEncode = [ 'libx264' ] | |
54 | for (const codec of canEncode) { | |
55 | if (codecs[codec] === undefined) { | |
56 | throw new Error('Unknown codec ' + codec + ' in FFmpeg.') | |
57 | } | |
58 | ||
59 | if (codecs[codec].canEncode !== true) { | |
60 | throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg') | |
61 | } | |
62 | } | |
e5b88539 C |
63 | } |
64 | ||
3482688c | 65 | // We get db by param to not import it in this file (import orders) |
3fd3ab2d C |
66 | async function clientsExist () { |
67 | const totalClients = await OAuthClientModel.countTotal() | |
f5028693 C |
68 | |
69 | return totalClients !== 0 | |
37dc07b2 C |
70 | } |
71 | ||
3482688c | 72 | // We get db by param to not import it in this file (import orders) |
3fd3ab2d C |
73 | async function usersExist () { |
74 | const totalUsers = await UserModel.countTotal() | |
f5028693 C |
75 | |
76 | return totalUsers !== 0 | |
9f10b292 | 77 | } |
8c308c2b | 78 | |
350e31d6 | 79 | // We get db by param to not import it in this file (import orders) |
3fd3ab2d C |
80 | async function applicationExist () { |
81 | const totalApplication = await ApplicationModel.countTotal() | |
350e31d6 C |
82 | |
83 | return totalApplication !== 0 | |
84 | } | |
85 | ||
9f10b292 | 86 | // --------------------------------------------------------------------------- |
c45f7f84 | 87 | |
65fcc311 C |
88 | export { |
89 | checkConfig, | |
90 | checkFFmpeg, | |
91 | checkMissedConfig, | |
92 | clientsExist, | |
350e31d6 C |
93 | usersExist, |
94 | applicationExist | |
65fcc311 | 95 | } |