diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-15 22:22:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-20 09:57:40 +0200 |
commit | 65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch) | |
tree | 4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/initializers/checker.ts | |
parent | d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff) | |
download | PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip |
First typescript iteration
Diffstat (limited to 'server/initializers/checker.ts')
-rw-r--r-- | server/initializers/checker.ts | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts new file mode 100644 index 000000000..370dff2d4 --- /dev/null +++ b/server/initializers/checker.ts | |||
@@ -0,0 +1,84 @@ | |||
1 | import config = require('config') | ||
2 | |||
3 | const db = require('./database') | ||
4 | import { CONFIG } from './constants' | ||
5 | |||
6 | // Some checks on configuration files | ||
7 | function checkConfig () { | ||
8 | if (config.has('webserver.host')) { | ||
9 | let errorMessage = '`host` config key was renamed to `hostname` but it seems you still have a `host` key in your configuration files!' | ||
10 | errorMessage += ' Please ensure to rename your `host` configuration to `hostname`.' | ||
11 | |||
12 | return errorMessage | ||
13 | } | ||
14 | |||
15 | return null | ||
16 | } | ||
17 | |||
18 | // Check the config files | ||
19 | function checkMissedConfig () { | ||
20 | const required = [ 'listen.port', | ||
21 | 'webserver.https', 'webserver.hostname', 'webserver.port', | ||
22 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', | ||
23 | 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', | ||
24 | 'admin.email', 'signup.enabled', 'transcoding.enabled', 'transcoding.threads' | ||
25 | ] | ||
26 | const miss = [] | ||
27 | |||
28 | for (const key of required) { | ||
29 | if (!config.has(key)) { | ||
30 | miss.push(key) | ||
31 | } | ||
32 | } | ||
33 | |||
34 | return miss | ||
35 | } | ||
36 | |||
37 | // Check the available codecs | ||
38 | function checkFFmpeg (callback) { | ||
39 | const Ffmpeg = require('fluent-ffmpeg') | ||
40 | |||
41 | Ffmpeg.getAvailableCodecs(function (err, codecs) { | ||
42 | if (err) return callback(err) | ||
43 | if (CONFIG.TRANSCODING.ENABLED === false) return callback(null) | ||
44 | |||
45 | const canEncode = [ 'libx264' ] | ||
46 | canEncode.forEach(function (codec) { | ||
47 | if (codecs[codec] === undefined) { | ||
48 | return callback(new Error('Unknown codec ' + codec + ' in FFmpeg.')) | ||
49 | } | ||
50 | |||
51 | if (codecs[codec].canEncode !== true) { | ||
52 | return callback(new Error('Unavailable encode codec ' + codec + ' in FFmpeg')) | ||
53 | } | ||
54 | }) | ||
55 | |||
56 | return callback(null) | ||
57 | }) | ||
58 | } | ||
59 | |||
60 | function clientsExist (callback) { | ||
61 | db.OAuthClient.countTotal(function (err, totalClients) { | ||
62 | if (err) return callback(err) | ||
63 | |||
64 | return callback(null, totalClients !== 0) | ||
65 | }) | ||
66 | } | ||
67 | |||
68 | function usersExist (callback) { | ||
69 | db.User.countTotal(function (err, totalUsers) { | ||
70 | if (err) return callback(err) | ||
71 | |||
72 | return callback(null, totalUsers !== 0) | ||
73 | }) | ||
74 | } | ||
75 | |||
76 | // --------------------------------------------------------------------------- | ||
77 | |||
78 | export { | ||
79 | checkConfig, | ||
80 | checkFFmpeg, | ||
81 | checkMissedConfig, | ||
82 | clientsExist, | ||
83 | usersExist | ||
84 | } | ||