]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/initializers/checker.ts
Add french
[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
0883b324 8// Return an error message, or null if everything is okay
9f10b292 9function checkConfig () {
0883b324 10 const defaultNSFWPolicy = config.get<string>('instance.default_nsfw_policy')
b65c27aa 11
0883b324
C
12 if ([ 'do_not_list', 'blur', 'display' ].indexOf(defaultNSFWPolicy) === -1) {
13 return 'NSFW policy setting should be "do_not_list" or "blur" or "display" instead of ' + defaultNSFWPolicy
b65c27aa
C
14 }
15
16 return null
17}
18
19// Check the config files
20function checkMissedConfig () {
cff8b272 21 const required = [ 'listen.port', 'listen.hostname',
3737bbaf 22 'webserver.https', 'webserver.hostname', 'webserver.port',
490b595a 23 'trust_proxy',
b769007f 24 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password',
30c82f0d 25 'redis.hostname', 'redis.port', 'redis.auth', 'redis.db',
a465bf5f
C
26 'smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address',
27 'storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache',
28 'log.level',
29 'user.video_quota',
ff2c1fe8
RK
30 'cache.previews.size', 'admin.email',
31 'signup.enabled', 'signup.limit', 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist',
32 'transcoding.enabled', 'transcoding.threads',
0883b324 33 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route',
ac235c37 34 'instance.default_nsfw_policy', 'instance.robots',
8be1afa1 35 'services.twitter.username', 'services.twitter.whitelisted'
56835348 36 ]
69818c93 37 const miss: string[] = []
9f10b292 38
f0f5567b 39 for (const key of required) {
9f10b292
C
40 if (!config.has(key)) {
41 miss.push(key)
8c308c2b 42 }
8c308c2b
C
43 }
44
9f10b292
C
45 return miss
46}
47
e5b88539 48// Check the available codecs
3482688c 49// We get CONFIG by param to not import it in this file (import orders)
f5028693 50async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) {
e5b88539 51 const Ffmpeg = require('fluent-ffmpeg')
6fcd19ba
C
52 const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
53
f5028693
C
54 const codecs = await getAvailableCodecsPromise()
55 if (CONFIG.TRANSCODING.ENABLED === false) return undefined
56
57 const canEncode = [ 'libx264' ]
58 for (const codec of canEncode) {
59 if (codecs[codec] === undefined) {
60 throw new Error('Unknown codec ' + codec + ' in FFmpeg.')
61 }
62
63 if (codecs[codec].canEncode !== true) {
64 throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg')
65 }
66 }
e5b88539
C
67}
68
3482688c 69// We get db by param to not import it in this file (import orders)
3fd3ab2d
C
70async function clientsExist () {
71 const totalClients = await OAuthClientModel.countTotal()
f5028693
C
72
73 return totalClients !== 0
37dc07b2
C
74}
75
3482688c 76// We get db by param to not import it in this file (import orders)
3fd3ab2d
C
77async function usersExist () {
78 const totalUsers = await UserModel.countTotal()
f5028693
C
79
80 return totalUsers !== 0
9f10b292 81}
8c308c2b 82
350e31d6 83// We get db by param to not import it in this file (import orders)
3fd3ab2d
C
84async function applicationExist () {
85 const totalApplication = await ApplicationModel.countTotal()
350e31d6
C
86
87 return totalApplication !== 0
88}
89
9f10b292 90// ---------------------------------------------------------------------------
c45f7f84 91
65fcc311
C
92export {
93 checkConfig,
94 checkFFmpeg,
95 checkMissedConfig,
96 clientsExist,
350e31d6
C
97 usersExist,
98 applicationExist
65fcc311 99}