]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/initializers/checker.ts
Add tests for open graph tags
[github/Chocobozzz/PeerTube.git] / server / initializers / checker.ts
... / ...
CommitLineData
1import * as config from 'config'
2
3import { database as db } from './database'
4import { CONFIG } from './constants'
5import { promisify0 } from '../helpers/core-utils'
6
7// Some checks on configuration files
8function 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
20function 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.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews',
25 'admin.email', 'signup.enabled', 'transcoding.enabled', 'transcoding.threads'
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
39function checkFFmpeg () {
40 const Ffmpeg = require('fluent-ffmpeg')
41 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
42
43 getAvailableCodecsPromise()
44 .then(codecs => {
45 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
46
47 const canEncode = [ 'libx264' ]
48 canEncode.forEach(function (codec) {
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
60function clientsExist () {
61 return db.OAuthClient.countTotal().then(totalClients => {
62 return totalClients !== 0
63 })
64}
65
66function usersExist () {
67 return db.User.countTotal().then(totalUsers => {
68 return totalUsers !== 0
69 })
70}
71
72// ---------------------------------------------------------------------------
73
74export {
75 checkConfig,
76 checkFFmpeg,
77 checkMissedConfig,
78 clientsExist,
79 usersExist
80}