diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-25 16:03:33 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-26 09:11:38 +0200 |
commit | f5028693a896a3076dd286ac0030e3d8f78f5ebf (patch) | |
tree | 09144ed6357e49ea575fb110247f933283ad235e /server/initializers/checker.ts | |
parent | eb08047657e739bcd9e592d76307befa3998482b (diff) | |
download | PeerTube-f5028693a896a3076dd286ac0030e3d8f78f5ebf.tar.gz PeerTube-f5028693a896a3076dd286ac0030e3d8f78f5ebf.tar.zst PeerTube-f5028693a896a3076dd286ac0030e3d8f78f5ebf.zip |
Use async/await in lib and initializers
Diffstat (limited to 'server/initializers/checker.ts')
-rw-r--r-- | server/initializers/checker.ts | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts index eb9e9e280..9eaef1695 100644 --- a/server/initializers/checker.ts +++ b/server/initializers/checker.ts | |||
@@ -37,39 +37,37 @@ function checkMissedConfig () { | |||
37 | 37 | ||
38 | // Check the available codecs | 38 | // Check the available codecs |
39 | // We get CONFIG by param to not import it in this file (import orders) | 39 | // We get CONFIG by param to not import it in this file (import orders) |
40 | function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) { | 40 | async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) { |
41 | const Ffmpeg = require('fluent-ffmpeg') | 41 | const Ffmpeg = require('fluent-ffmpeg') |
42 | const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) | 42 | const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) |
43 | 43 | ||
44 | getAvailableCodecsPromise() | 44 | const codecs = await getAvailableCodecsPromise() |
45 | .then(codecs => { | 45 | if (CONFIG.TRANSCODING.ENABLED === false) return undefined |
46 | if (CONFIG.TRANSCODING.ENABLED === false) return undefined | 46 | |
47 | 47 | const canEncode = [ 'libx264' ] | |
48 | const canEncode = [ 'libx264' ] | 48 | for (const codec of canEncode) { |
49 | canEncode.forEach(codec => { | 49 | if (codecs[codec] === undefined) { |
50 | if (codecs[codec] === undefined) { | 50 | throw new Error('Unknown codec ' + codec + ' in FFmpeg.') |
51 | throw new Error('Unknown codec ' + codec + ' in FFmpeg.') | 51 | } |
52 | } | 52 | |
53 | 53 | if (codecs[codec].canEncode !== true) { | |
54 | if (codecs[codec].canEncode !== true) { | 54 | throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg') |
55 | throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg') | 55 | } |
56 | } | 56 | } |
57 | }) | ||
58 | }) | ||
59 | } | 57 | } |
60 | 58 | ||
61 | // We get db by param to not import it in this file (import orders) | 59 | // We get db by param to not import it in this file (import orders) |
62 | function clientsExist (OAuthClient: OAuthClientModel) { | 60 | async function clientsExist (OAuthClient: OAuthClientModel) { |
63 | return OAuthClient.countTotal().then(totalClients => { | 61 | const totalClients = await OAuthClient.countTotal() |
64 | return totalClients !== 0 | 62 | |
65 | }) | 63 | return totalClients !== 0 |
66 | } | 64 | } |
67 | 65 | ||
68 | // We get db by param to not import it in this file (import orders) | 66 | // We get db by param to not import it in this file (import orders) |
69 | function usersExist (User: UserModel) { | 67 | async function usersExist (User: UserModel) { |
70 | return User.countTotal().then(totalUsers => { | 68 | const totalUsers = await User.countTotal() |
71 | return totalUsers !== 0 | 69 | |
72 | }) | 70 | return totalUsers !== 0 |
73 | } | 71 | } |
74 | 72 | ||
75 | // --------------------------------------------------------------------------- | 73 | // --------------------------------------------------------------------------- |