1 import * as config from 'config'
2 import { isProdInstance, isTestInstance } from '../helpers/core-utils'
3 import { UserModel } from '../models/account/user'
4 import { ApplicationModel } from '../models/application/application'
5 import { OAuthClientModel } from '../models/oauth/oauth-client'
6 import { parse } from 'url'
7 import { CONFIG } from './config'
8 import { logger } from '../helpers/logger'
9 import { getServerActor } from '../helpers/utils'
10 import { RecentlyAddedStrategy } from '../../shared/models/redundancy'
11 import { isArray } from '../helpers/custom-validators/misc'
12 import { uniq } from 'lodash'
13 import { Emailer } from '../lib/emailer'
14 import { WEBSERVER } from './constants'
16 async function checkActivityPubUrls () {
17 const actor = await getServerActor()
19 const parsed = parse(actor.url)
20 if (WEBSERVER.HOST !== parsed.host) {
21 const NODE_ENV = config.util.getEnv('NODE_ENV')
22 const NODE_CONFIG_DIR = config.util.getEnv('NODE_CONFIG_DIR')
25 'It seems PeerTube was started (and created some data) with another domain name. ' +
26 'This means you will not be able to federate! ' +
27 'Please use %s %s npm run update-host to fix this.',
28 NODE_CONFIG_DIR ? `NODE_CONFIG_DIR=${NODE_CONFIG_DIR}` : '',
29 NODE_ENV ? `NODE_ENV=${NODE_ENV}` : ''
34 // Some checks on configuration files
35 // Return an error message, or null if everything is okay
36 function checkConfig () {
38 // Moved configuration keys
39 if (config.has('services.csp-logger')) {
40 logger.warn('services.csp-logger configuration has been renamed to csp.report_uri. Please update your configuration file.')
44 if (!Emailer.isEnabled()) {
45 if (CONFIG.SIGNUP.ENABLED && CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) {
46 return 'Emailer is disabled but you require signup email verification.'
49 if (CONFIG.CONTACT_FORM.ENABLED) {
50 logger.warn('Emailer is disabled so the contact form will not work.')
55 const defaultNSFWPolicy = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY
57 const available = [ 'do_not_list', 'blur', 'display' ]
58 if (available.indexOf(defaultNSFWPolicy) === -1) {
59 return 'NSFW policy setting should be ' + available.join(' or ') + ' instead of ' + defaultNSFWPolicy
64 const redundancyVideos = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES
65 if (isArray(redundancyVideos)) {
66 const available = [ 'most-views', 'trending', 'recently-added' ]
67 for (const r of redundancyVideos) {
68 if (available.indexOf(r.strategy) === -1) {
69 return 'Videos redundancy should have ' + available.join(' or ') + ' strategy instead of ' + r.strategy
72 // Lifetime should not be < 10 hours
73 if (!isTestInstance() && r.minLifetime < 1000 * 3600 * 10) {
74 return 'Video redundancy minimum lifetime should be >= 10 hours for strategy ' + r.strategy
78 const filtered = uniq(redundancyVideos.map(r => r.strategy))
79 if (filtered.length !== redundancyVideos.length) {
80 return 'Redundancy video entries should have unique strategies'
83 const recentlyAddedStrategy = redundancyVideos.find(r => r.strategy === 'recently-added') as RecentlyAddedStrategy
84 if (recentlyAddedStrategy && isNaN(recentlyAddedStrategy.minViews)) {
85 return 'Min views in recently added strategy is not a number'
88 return 'Videos redundancy should be an array (you must uncomment lines containing - too)'
91 // Check storage directory locations
92 if (isProdInstance()) {
93 const configStorage = config.get('storage')
94 for (const key of Object.keys(configStorage)) {
95 if (configStorage[key].startsWith('storage/')) {
97 'Directory of %s should not be in the production directory of PeerTube. Please check your production configuration file.',
107 // We get db by param to not import it in this file (import orders)
108 async function clientsExist () {
109 const totalClients = await OAuthClientModel.countTotal()
111 return totalClients !== 0
114 // We get db by param to not import it in this file (import orders)
115 async function usersExist () {
116 const totalUsers = await UserModel.countTotal()
118 return totalUsers !== 0
121 // We get db by param to not import it in this file (import orders)
122 async function applicationExist () {
123 const totalApplication = await ApplicationModel.countTotal()
125 return totalApplication !== 0
128 // ---------------------------------------------------------------------------