diff options
-rw-r--r-- | server.ts | 23 | ||||
-rw-r--r-- | server/initializers/checker.ts | 21 | ||||
-rw-r--r-- | server/initializers/installer.ts | 4 |
3 files changed, 26 insertions, 22 deletions
@@ -23,28 +23,29 @@ process.title = 'peertube' | |||
23 | // Create our main app | 23 | // Create our main app |
24 | const app = express() | 24 | const app = express() |
25 | 25 | ||
26 | // ----------- Database ----------- | 26 | // ----------- Core checker ----------- |
27 | // Do not use barrels because we don't want to load all modules here (we need to initialize database first) | ||
28 | import { logger } from './server/helpers/logger' | ||
29 | import { API_VERSION, CONFIG, STATIC_PATHS } from './server/initializers/constants' | ||
30 | // Initialize database and models | ||
31 | import { database as db } from './server/initializers/database' | ||
32 | db.init(false).then(() => onDatabaseInitDone()) | ||
33 | |||
34 | // ----------- Checker ----------- | ||
35 | import { checkMissedConfig, checkFFmpeg, checkConfig } from './server/initializers/checker' | 27 | import { checkMissedConfig, checkFFmpeg, checkConfig } from './server/initializers/checker' |
36 | 28 | ||
37 | const missed = checkMissedConfig() | 29 | const missed = checkMissedConfig() |
38 | if (missed.length !== 0) { | 30 | if (missed.length !== 0) { |
39 | throw new Error('Miss some configurations keys : ' + missed) | 31 | throw new Error('Your configuration files miss keys: ' + missed) |
40 | } | 32 | } |
41 | checkFFmpeg() | 33 | |
34 | import { API_VERSION, CONFIG, STATIC_PATHS } from './server/initializers/constants' | ||
35 | checkFFmpeg(CONFIG) | ||
42 | 36 | ||
43 | const errorMessage = checkConfig() | 37 | const errorMessage = checkConfig() |
44 | if (errorMessage !== null) { | 38 | if (errorMessage !== null) { |
45 | throw new Error(errorMessage) | 39 | throw new Error(errorMessage) |
46 | } | 40 | } |
47 | 41 | ||
42 | // ----------- Database ----------- | ||
43 | // Do not use barrels because we don't want to load all modules here (we need to initialize database first) | ||
44 | import { logger } from './server/helpers/logger' | ||
45 | // Initialize database and models | ||
46 | import { database as db } from './server/initializers/database' | ||
47 | db.init(false).then(() => onDatabaseInitDone()) | ||
48 | |||
48 | // ----------- PeerTube modules ----------- | 49 | // ----------- PeerTube modules ----------- |
49 | import { migrate, installApplication } from './server/initializers' | 50 | import { migrate, installApplication } from './server/initializers' |
50 | import { JobScheduler, activateSchedulers, VideosPreviewCache } from './server/lib' | 51 | import { JobScheduler, activateSchedulers, VideosPreviewCache } from './server/lib' |
diff --git a/server/initializers/checker.ts b/server/initializers/checker.ts index e4ca26f9c..97606ef31 100644 --- a/server/initializers/checker.ts +++ b/server/initializers/checker.ts | |||
@@ -1,8 +1,8 @@ | |||
1 | import * as config from 'config' | 1 | import * as config from 'config' |
2 | 2 | ||
3 | import { database as db } from './database' | ||
4 | import { CONFIG } from './constants' | ||
5 | import { promisify0 } from '../helpers/core-utils' | 3 | import { promisify0 } from '../helpers/core-utils' |
4 | import { OAuthClientModel } from '../models/oauth/oauth-client-interface' | ||
5 | import { UserModel } from '../models/user/user-interface' | ||
6 | 6 | ||
7 | // Some checks on configuration files | 7 | // Some checks on configuration files |
8 | function checkConfig () { | 8 | function checkConfig () { |
@@ -21,8 +21,8 @@ function checkMissedConfig () { | |||
21 | const required = [ 'listen.port', | 21 | const required = [ 'listen.port', |
22 | 'webserver.https', 'webserver.hostname', 'webserver.port', | 22 | 'webserver.https', 'webserver.hostname', 'webserver.port', |
23 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', | 23 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', |
24 | 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', | 24 | 'storage.certs', 'storage.videos', 'storage.logs', 'storage.thumbnails', 'storage.previews', 'storage.torrents', 'storage.cache', |
25 | 'admin.email', 'signup.enabled', 'transcoding.enabled', 'transcoding.threads' | 25 | 'cache.previews.size', 'admin.email', 'signup.enabled', 'signup.limit', 'transcoding.enabled', 'transcoding.threads' |
26 | ] | 26 | ] |
27 | const miss: string[] = [] | 27 | const miss: string[] = [] |
28 | 28 | ||
@@ -36,7 +36,8 @@ function checkMissedConfig () { | |||
36 | } | 36 | } |
37 | 37 | ||
38 | // Check the available codecs | 38 | // Check the available codecs |
39 | function checkFFmpeg () { | 39 | // We get CONFIG by param to not import it in this file (import orders) |
40 | function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) { | ||
40 | const Ffmpeg = require('fluent-ffmpeg') | 41 | const Ffmpeg = require('fluent-ffmpeg') |
41 | const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) | 42 | const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) |
42 | 43 | ||
@@ -57,14 +58,16 @@ function checkFFmpeg () { | |||
57 | }) | 58 | }) |
58 | } | 59 | } |
59 | 60 | ||
60 | function clientsExist () { | 61 | // We get db by param to not import it in this file (import orders) |
61 | return db.OAuthClient.countTotal().then(totalClients => { | 62 | function clientsExist (OAuthClient: OAuthClientModel) { |
63 | return OAuthClient.countTotal().then(totalClients => { | ||
62 | return totalClients !== 0 | 64 | return totalClients !== 0 |
63 | }) | 65 | }) |
64 | } | 66 | } |
65 | 67 | ||
66 | function usersExist () { | 68 | // We get db by param to not import it in this file (import orders) |
67 | return db.User.countTotal().then(totalUsers => { | 69 | function usersExist (User: UserModel) { |
70 | return User.countTotal().then(totalUsers => { | ||
68 | return totalUsers !== 0 | 71 | return totalUsers !== 0 |
69 | }) | 72 | }) |
70 | } | 73 | } |
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 26e92be0b..43b5adfed 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts | |||
@@ -57,7 +57,7 @@ function createDirectoriesIfNotExist () { | |||
57 | } | 57 | } |
58 | 58 | ||
59 | function createOAuthClientIfNotExist () { | 59 | function createOAuthClientIfNotExist () { |
60 | return clientsExist().then(exist => { | 60 | return clientsExist(db.OAuthClient).then(exist => { |
61 | // Nothing to do, clients already exist | 61 | // Nothing to do, clients already exist |
62 | if (exist === true) return undefined | 62 | if (exist === true) return undefined |
63 | 63 | ||
@@ -82,7 +82,7 @@ function createOAuthClientIfNotExist () { | |||
82 | } | 82 | } |
83 | 83 | ||
84 | function createOAuthAdminIfNotExist () { | 84 | function createOAuthAdminIfNotExist () { |
85 | return usersExist().then(exist => { | 85 | return usersExist(db.User).then(exist => { |
86 | // Nothing to do, users already exist | 86 | // Nothing to do, users already exist |
87 | if (exist === true) return undefined | 87 | if (exist === true) return undefined |
88 | 88 | ||