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