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