]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/checker.ts
7cfbc123de19d1490a687363ffd654f12f3a0c5e
[github/Chocobozzz/PeerTube.git] / server / initializers / checker.ts
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 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', 'storage.torrents', 'storage.cache',
25 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads', 'user.video_quota'
26 ]
27 const miss: string[] = []
28
29 for (const key of required) {
30 if (!config.has(key)) {
31 miss.push(key)
32 }
33 }
34
35 return miss
36 }
37
38 // Check the available codecs
39 // We get CONFIG by param to not import it in this file (import orders)
40 async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
41 const Ffmpeg = require('fluent-ffmpeg')
42 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
43
44 const codecs = await getAvailableCodecsPromise()
45 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
46
47 const canEncode = [ 'libx264' ]
48 for (const codec of canEncode) {
49 if (codecs[codec] === undefined) {
50 throw new Error('Unknown codec ' + codec + ' in FFmpeg.')
51 }
52
53 if (codecs[codec].canEncode !== true) {
54 throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg')
55 }
56 }
57 }
58
59 // We get db by param to not import it in this file (import orders)
60 async function clientsExist () {
61 const totalClients = await OAuthClientModel.countTotal()
62
63 return totalClients !== 0
64 }
65
66 // We get db by param to not import it in this file (import orders)
67 async function usersExist () {
68 const totalUsers = await UserModel.countTotal()
69
70 return totalUsers !== 0
71 }
72
73 // We get db by param to not import it in this file (import orders)
74 async function applicationExist () {
75 const totalApplication = await ApplicationModel.countTotal()
76
77 return totalApplication !== 0
78 }
79
80 // ---------------------------------------------------------------------------
81
82 export {
83 checkConfig,
84 checkFFmpeg,
85 checkMissedConfig,
86 clientsExist,
87 usersExist,
88 applicationExist
89 }