]>
Commit | Line | Data |
---|---|---|
4d4e5cd4 | 1 | import * as config from 'config' |
da854ddd | 2 | import { promisify0 } from '../helpers/core-utils' |
3fd3ab2d C |
3 | import { UserModel } from '../models/account/user' |
4 | import { ApplicationModel } from '../models/application/application' | |
5 | import { OAuthClientModel } from '../models/oauth/oauth-client' | |
23687332 C |
6 | import { parse } from 'url' |
7 | import { CONFIG } from './constants' | |
8 | import { logger } from '../helpers/logger' | |
9 | import { getServerActor } from '../helpers/utils' | |
10 | ||
11 | async function checkActivityPubUrls () { | |
12 | const actor = await getServerActor() | |
13 | ||
14 | const parsed = parse(actor.url) | |
15 | if (CONFIG.WEBSERVER.HOST !== parsed.host) { | |
16 | const NODE_ENV = config.util.getEnv('NODE_ENV') | |
17 | const NODE_CONFIG_DIR = config.util.getEnv('NODE_CONFIG_DIR') | |
18 | ||
19 | logger.warn( | |
20 | 'It seems PeerTube was started (and created some data) with another domain name. ' + | |
21 | 'This means you will not be able to federate! ' + | |
22 | 'Please use %s %s npm run update-host to fix this.', | |
23 | NODE_CONFIG_DIR ? `NODE_CONFIG_DIR=${NODE_CONFIG_DIR}` : '', | |
24 | NODE_ENV ? `NODE_ENV=${NODE_ENV}` : '' | |
25 | ) | |
26 | } | |
27 | } | |
9f10b292 | 28 | |
b65c27aa | 29 | // Some checks on configuration files |
0883b324 | 30 | // Return an error message, or null if everything is okay |
9f10b292 | 31 | function checkConfig () { |
0883b324 | 32 | const defaultNSFWPolicy = config.get<string>('instance.default_nsfw_policy') |
b65c27aa | 33 | |
0883b324 C |
34 | if ([ 'do_not_list', 'blur', 'display' ].indexOf(defaultNSFWPolicy) === -1) { |
35 | return 'NSFW policy setting should be "do_not_list" or "blur" or "display" instead of ' + defaultNSFWPolicy | |
b65c27aa C |
36 | } |
37 | ||
38 | return null | |
39 | } | |
40 | ||
41 | // Check the config files | |
42 | function checkMissedConfig () { | |
cff8b272 | 43 | const required = [ 'listen.port', 'listen.hostname', |
3737bbaf | 44 | 'webserver.https', 'webserver.hostname', 'webserver.port', |
490b595a | 45 | 'trust_proxy', |
b769007f | 46 | 'database.hostname', 'database.port', 'database.suffix', 'database.username', 'database.password', |
30c82f0d | 47 | 'redis.hostname', 'redis.port', 'redis.auth', 'redis.db', |
a465bf5f C |
48 | 'smtp.hostname', 'smtp.port', 'smtp.username', 'smtp.password', 'smtp.tls', 'smtp.from_address', |
49 | 'storage.avatars', 'storage.videos', 'storage.logs', 'storage.previews', 'storage.thumbnails', 'storage.torrents', 'storage.cache', | |
50 | 'log.level', | |
51 | 'user.video_quota', | |
ff2c1fe8 RK |
52 | 'cache.previews.size', 'admin.email', |
53 | 'signup.enabled', 'signup.limit', 'signup.filters.cidr.whitelist', 'signup.filters.cidr.blacklist', | |
54 | 'transcoding.enabled', 'transcoding.threads', | |
0883b324 | 55 | 'instance.name', 'instance.short_description', 'instance.description', 'instance.terms', 'instance.default_client_route', |
ac235c37 | 56 | 'instance.default_nsfw_policy', 'instance.robots', |
8be1afa1 | 57 | 'services.twitter.username', 'services.twitter.whitelisted' |
56835348 | 58 | ] |
69818c93 | 59 | const miss: string[] = [] |
9f10b292 | 60 | |
f0f5567b | 61 | for (const key of required) { |
9f10b292 C |
62 | if (!config.has(key)) { |
63 | miss.push(key) | |
8c308c2b | 64 | } |
8c308c2b C |
65 | } |
66 | ||
9f10b292 C |
67 | return miss |
68 | } | |
69 | ||
e5b88539 | 70 | // Check the available codecs |
3482688c | 71 | // We get CONFIG by param to not import it in this file (import orders) |
f5028693 | 72 | async function checkFFmpeg (CONFIG: { TRANSCODING: { ENABLED: boolean } }) { |
e5b88539 | 73 | const Ffmpeg = require('fluent-ffmpeg') |
6fcd19ba C |
74 | const getAvailableCodecsPromise = promisify0(Ffmpeg.getAvailableCodecs) |
75 | ||
f5028693 C |
76 | const codecs = await getAvailableCodecsPromise() |
77 | if (CONFIG.TRANSCODING.ENABLED === false) return undefined | |
78 | ||
79 | const canEncode = [ 'libx264' ] | |
80 | for (const codec of canEncode) { | |
81 | if (codecs[codec] === undefined) { | |
82 | throw new Error('Unknown codec ' + codec + ' in FFmpeg.') | |
83 | } | |
84 | ||
85 | if (codecs[codec].canEncode !== true) { | |
86 | throw new Error('Unavailable encode codec ' + codec + ' in FFmpeg') | |
87 | } | |
88 | } | |
e5b88539 C |
89 | } |
90 | ||
3482688c | 91 | // We get db by param to not import it in this file (import orders) |
3fd3ab2d C |
92 | async function clientsExist () { |
93 | const totalClients = await OAuthClientModel.countTotal() | |
f5028693 C |
94 | |
95 | return totalClients !== 0 | |
37dc07b2 C |
96 | } |
97 | ||
3482688c | 98 | // We get db by param to not import it in this file (import orders) |
3fd3ab2d C |
99 | async function usersExist () { |
100 | const totalUsers = await UserModel.countTotal() | |
f5028693 C |
101 | |
102 | return totalUsers !== 0 | |
9f10b292 | 103 | } |
8c308c2b | 104 | |
350e31d6 | 105 | // We get db by param to not import it in this file (import orders) |
3fd3ab2d C |
106 | async function applicationExist () { |
107 | const totalApplication = await ApplicationModel.countTotal() | |
350e31d6 C |
108 | |
109 | return totalApplication !== 0 | |
110 | } | |
111 | ||
9f10b292 | 112 | // --------------------------------------------------------------------------- |
c45f7f84 | 113 | |
65fcc311 C |
114 | export { |
115 | checkConfig, | |
116 | checkFFmpeg, | |
117 | checkMissedConfig, | |
118 | clientsExist, | |
350e31d6 | 119 | usersExist, |
23687332 C |
120 | applicationExist, |
121 | checkActivityPubUrls | |
65fcc311 | 122 | } |