]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/checker.ts
Merge branch 'develop' of github.com:Chocobozzz/PeerTube into develop
[github/Chocobozzz/PeerTube.git] / server / initializers / checker.ts
CommitLineData
4d4e5cd4 1import * as config from 'config'
da854ddd 2import { promisify0 } from '../helpers/core-utils'
3fd3ab2d
C
3import { UserModel } from '../models/account/user'
4import { ApplicationModel } from '../models/application/application'
5import { OAuthClientModel } from '../models/oauth/oauth-client'
9f10b292 6
b65c27aa 7// Some checks on configuration files
9f10b292 8function 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
20function 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',
a465bf5f
C
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',
ecb4e35f 29 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads',
a465bf5f 30 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route'
56835348 31 ]
69818c93 32 const miss: string[] = []
9f10b292 33
f0f5567b 34 for (const key of required) {
9f10b292
C
35 if (!config.has(key)) {
36 miss.push(key)
8c308c2b 37 }
8c308c2b
C
38 }
39
9f10b292
C
40 return miss
41}
42
e5b88539 43// Check the available codecs
3482688c 44// We get CONFIG by param to not import it in this file (import orders)
f5028693 45async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
e5b88539 46 const Ffmpeg = require('fluent-ffmpeg')
6fcd19ba
C
47 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
48
f5028693
C
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 }
e5b88539
C
62}
63
3482688c 64// We get db by param to not import it in this file (import orders)
3fd3ab2d
C
65async function clientsExist () {
66 const totalClients = await OAuthClientModel.countTotal()
f5028693
C
67
68 return totalClients !== 0
37dc07b2
C
69}
70
3482688c 71// We get db by param to not import it in this file (import orders)
3fd3ab2d
C
72async function usersExist () {
73 const totalUsers = await UserModel.countTotal()
f5028693
C
74
75 return totalUsers !== 0
9f10b292 76}
8c308c2b 77
350e31d6 78// We get db by param to not import it in this file (import orders)
3fd3ab2d
C
79async function applicationExist () {
80 const totalApplication = await ApplicationModel.countTotal()
350e31d6
C
81
82 return totalApplication !== 0
83}
84
9f10b292 85// ---------------------------------------------------------------------------
c45f7f84 86
65fcc311
C
87export {
88 checkConfig,
89 checkFFmpeg,
90 checkMissedConfig,
91 clientsExist,
350e31d6
C
92 usersExist,
93 applicationExist
65fcc311 94}