]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/initializers/checker.ts
Remove "function" in favor of () => {}
[github/Chocobozzz/PeerTube.git] / server / initializers / checker.ts
index 0ee01b0e3720e1e153c2910fa19efb6ecb520b4e..e4ca26f9c683d7a1117906bc26667348d16839d3 100644 (file)
@@ -1,7 +1,8 @@
-import config = require('config')
+import * as config from 'config'
 
 import { database as db } from './database'
 import { CONFIG } from './constants'
+import { promisify0 } from '../helpers/core-utils'
 
 // Some checks on configuration files
 function checkConfig () {
@@ -23,7 +24,7 @@ function checkMissedConfig () {
     'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews',
     'admin.email', 'signup.enabled', 'transcoding.enabled', 'transcoding.threads'
   ]
-  const miss = []
+  const miss: string[] = []
 
   for (const key of required) {
     if (!config.has(key)) {
@@ -35,41 +36,36 @@ function checkMissedConfig () {
 }
 
 // Check the available codecs
-function checkFFmpeg (callback) {
+function checkFFmpeg () {
   const Ffmpeg = require('fluent-ffmpeg')
-
-  Ffmpeg.getAvailableCodecs(function (err, codecs) {
-    if (err) return callback(err)
-    if (CONFIG.TRANSCODING.ENABLED === false) return callback(null)
-
-    const canEncode = [ 'libx264' ]
-    canEncode.forEach(function (codec) {
-      if (codecs[codec] === undefined) {
-        return callback(new Error('Unknown codec ' + codec + ' in FFmpeg.'))
-      }
-
-      if (codecs[codec].canEncode !== true) {
-        return callback(new Error('Unavailable encode codec ' + codec + ' in FFmpeg'))
-      }
+  const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs)
+
+  getAvailableCodecsPromise()
+    .then(codecs => {
+      if (CONFIG.TRANSCODING.ENABLED === false) return undefined
+
+      const canEncode = [ 'libx264' ]
+      canEncode.forEach(codec => {
+        if (codecs[codec] === undefined) {
+          throw new Error('Unknown codec ' + codec + ' in FFmpeg.')
+        }
+
+        if (codecs[codec].canEncode !== true) {
+          throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg')
+        }
+      })
     })
-
-    return callback(null)
-  })
 }
 
-function clientsExist (callback) {
-  db.OAuthClient.countTotal(function (err, totalClients) {
-    if (err) return callback(err)
-
-    return callback(null, totalClients !== 0)
+function clientsExist () {
+  return db.OAuthClient.countTotal().then(totalClients => {
+    return totalClients !== 0
   })
 }
 
-function usersExist (callback) {
-  db.User.countTotal(function (err, totalUsers) {
-    if (err) return callback(err)
-
-    return callback(null, totalUsers !== 0)
+function usersExist () {
+  return db.User.countTotal().then(totalUsers => {
+    return totalUsers !== 0
   })
 }