]>
Commit | Line | Data |
---|---|---|
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' | |
6 | ||
7 | // Some checks on configuration files | |
8 | function checkConfig () { | |
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 () { | |
21 | const required = [ 'listen.port', | |
22 | 'webserver.https', 'webserver.hostname', 'webserver.port', | |
23 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', | |
24 | 'redis.hostname', 'redis.port', 'redis.auth', | |
25 | 'smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address', | |
26 | 'storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache', | |
27 | 'log.level', | |
28 | 'user.video_quota', | |
29 | 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads', | |
30 | 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route' | |
31 | ] | |
32 | const miss: string[] = [] | |
33 | ||
34 | for (const key of required) { | |
35 | if (!config.has(key)) { | |
36 | miss.push(key) | |
37 | } | |
38 | } | |
39 | ||
40 | return miss | |
41 | } | |
42 | ||
43 | // Check the available codecs | |
44 | // We get CONFIG by param to not import it in this file (import orders) | |
45 | async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) { | |
46 | const Ffmpeg = require('fluent-ffmpeg') | |
47 | const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) | |
48 | ||
49 | const codecs = await getAvailableCodecsPromise() | |
50 | if (CONFIG.TRANSCODING.ENABLED === false) return undefined | |
51 | ||
52 | const canEncode = [ 'libx264' ] | |
53 | for (const codec of canEncode) { | |
54 | if (codecs[codec] === undefined) { | |
55 | throw new Error('Unknown codec ' + codec + ' in FFmpeg.') | |
56 | } | |
57 | ||
58 | if (codecs[codec].canEncode !== true) { | |
59 | throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg') | |
60 | } | |
61 | } | |
62 | } | |
63 | ||
64 | // We get db by param to not import it in this file (import orders) | |
65 | async function clientsExist () { | |
66 | const totalClients = await OAuthClientModel.countTotal() | |
67 | ||
68 | return totalClients !== 0 | |
69 | } | |
70 | ||
71 | // We get db by param to not import it in this file (import orders) | |
72 | async function usersExist () { | |
73 | const totalUsers = await UserModel.countTotal() | |
74 | ||
75 | return totalUsers !== 0 | |
76 | } | |
77 | ||
78 | // We get db by param to not import it in this file (import orders) | |
79 | async function applicationExist () { | |
80 | const totalApplication = await ApplicationModel.countTotal() | |
81 | ||
82 | return totalApplication !== 0 | |
83 | } | |
84 | ||
85 | // --------------------------------------------------------------------------- | |
86 | ||
87 | export { | |
88 | checkConfig, | |
89 | checkFFmpeg, | |
90 | checkMissedConfig, | |
91 | clientsExist, | |
92 | usersExist, | |
93 | applicationExist | |
94 | } |