]>
Commit | Line | Data |
---|---|---|
e5565833 | 1 | import * as config from 'config' |
d1105b97 | 2 | import { isProdInstance, isTestInstance } from '../helpers/core-utils' |
e5565833 | 3 | import { UserModel } from '../models/account/user' |
8dc8a34e | 4 | import { getServerActor, ApplicationModel } from '../models/application/application' |
e5565833 | 5 | import { OAuthClientModel } from '../models/oauth/oauth-client' |
a1587156 | 6 | import { URL } from 'url' |
4c1c1709 | 7 | import { CONFIG, isEmailEnabled } from './config' |
e5565833 | 8 | import { logger } from '../helpers/logger' |
d1105b97 | 9 | import { RecentlyAddedStrategy } from '../../shared/models/redundancy' |
e5565833 C |
10 | import { isArray } from '../helpers/custom-validators/misc' |
11 | import { uniq } from 'lodash' | |
6dd9de95 | 12 | import { WEBSERVER } from './constants' |
8c9e7875 | 13 | import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' |
e5565833 C |
14 | |
15 | async function checkActivityPubUrls () { | |
16 | const actor = await getServerActor() | |
17 | ||
a1587156 | 18 | const parsed = new URL(actor.url) |
6dd9de95 | 19 | if (WEBSERVER.HOST !== parsed.host) { |
e5565833 C |
20 | const NODE_ENV = config.util.getEnv('NODE_ENV') |
21 | const NODE_CONFIG_DIR = config.util.getEnv('NODE_CONFIG_DIR') | |
22 | ||
23 | logger.warn( | |
24 | 'It seems PeerTube was started (and created some data) with another domain name. ' + | |
25 | 'This means you will not be able to federate! ' + | |
26 | 'Please use %s %s npm run update-host to fix this.', | |
27 | NODE_CONFIG_DIR ? `NODE_CONFIG_DIR=${NODE_CONFIG_DIR}` : '', | |
28 | NODE_ENV ? `NODE_ENV=${NODE_ENV}` : '' | |
29 | ) | |
30 | } | |
31 | } | |
32 | ||
33 | // Some checks on configuration files | |
34 | // Return an error message, or null if everything is okay | |
35 | function checkConfig () { | |
d3e56c0c | 36 | |
539d3f4f C |
37 | // Moved configuration keys |
38 | if (config.has('services.csp-logger')) { | |
39 | logger.warn('services.csp-logger configuration has been renamed to csp.report_uri. Please update your configuration file.') | |
40 | } | |
41 | ||
42 | // Email verification | |
4c1c1709 | 43 | if (!isEmailEnabled()) { |
d3e56c0c C |
44 | if (CONFIG.SIGNUP.ENABLED && CONFIG.SIGNUP.REQUIRES_EMAIL_VERIFICATION) { |
45 | return 'Emailer is disabled but you require signup email verification.' | |
46 | } | |
47 | ||
48 | if (CONFIG.CONTACT_FORM.ENABLED) { | |
49 | logger.warn('Emailer is disabled so the contact form will not work.') | |
50 | } | |
51 | } | |
e5565833 C |
52 | |
53 | // NSFW policy | |
d3e56c0c | 54 | const defaultNSFWPolicy = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY |
e5565833 C |
55 | { |
56 | const available = [ 'do_not_list', 'blur', 'display' ] | |
bdd428a6 | 57 | if (available.includes(defaultNSFWPolicy) === false) { |
e5565833 C |
58 | return 'NSFW policy setting should be ' + available.join(' or ') + ' instead of ' + defaultNSFWPolicy |
59 | } | |
60 | } | |
61 | ||
62 | // Redundancies | |
63 | const redundancyVideos = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES | |
64 | if (isArray(redundancyVideos)) { | |
65 | const available = [ 'most-views', 'trending', 'recently-added' ] | |
66 | for (const r of redundancyVideos) { | |
bdd428a6 | 67 | if (available.includes(r.strategy) === false) { |
e5565833 C |
68 | return 'Videos redundancy should have ' + available.join(' or ') + ' strategy instead of ' + r.strategy |
69 | } | |
70 | ||
71 | // Lifetime should not be < 10 hours | |
72 | if (!isTestInstance() && r.minLifetime < 1000 * 3600 * 10) { | |
73 | return 'Video redundancy minimum lifetime should be >= 10 hours for strategy ' + r.strategy | |
74 | } | |
75 | } | |
76 | ||
77 | const filtered = uniq(redundancyVideos.map(r => r.strategy)) | |
78 | if (filtered.length !== redundancyVideos.length) { | |
79 | return 'Redundancy video entries should have unique strategies' | |
80 | } | |
81 | ||
82 | const recentlyAddedStrategy = redundancyVideos.find(r => r.strategy === 'recently-added') as RecentlyAddedStrategy | |
83 | if (recentlyAddedStrategy && isNaN(recentlyAddedStrategy.minViews)) { | |
84 | return 'Min views in recently added strategy is not a number' | |
85 | } | |
d85798c4 C |
86 | } else { |
87 | return 'Videos redundancy should be an array (you must uncomment lines containing - too)' | |
e5565833 C |
88 | } |
89 | ||
8c9e7875 C |
90 | // Remote redundancies |
91 | const acceptFrom = CONFIG.REMOTE_REDUNDANCY.VIDEOS.ACCEPT_FROM | |
92 | const acceptFromValues = new Set<VideoRedundancyConfigFilter>([ 'nobody', 'anybody', 'followings' ]) | |
93 | if (acceptFromValues.has(acceptFrom) === false) { | |
94 | return 'remote_redundancy.videos.accept_from has an incorrect value' | |
95 | } | |
96 | ||
d3e56c0c | 97 | // Check storage directory locations |
e5565833 C |
98 | if (isProdInstance()) { |
99 | const configStorage = config.get('storage') | |
100 | for (const key of Object.keys(configStorage)) { | |
101 | if (configStorage[key].startsWith('storage/')) { | |
102 | logger.warn( | |
103 | 'Directory of %s should not be in the production directory of PeerTube. Please check your production configuration file.', | |
104 | key | |
105 | ) | |
106 | } | |
107 | } | |
108 | } | |
109 | ||
d7a25329 C |
110 | // Transcoding |
111 | if (CONFIG.TRANSCODING.ENABLED) { | |
112 | if (CONFIG.TRANSCODING.WEBTORRENT.ENABLED === false && CONFIG.TRANSCODING.HLS.ENABLED === false) { | |
113 | return 'You need to enable at least WebTorrent transcoding or HLS transcoding.' | |
114 | } | |
115 | } | |
116 | ||
2034c3aa C |
117 | if (CONFIG.STORAGE.VIDEOS_DIR === CONFIG.STORAGE.REDUNDANCY_DIR) { |
118 | logger.warn('Redundancy directory should be different than the videos folder.') | |
119 | } | |
120 | ||
e5565833 C |
121 | return null |
122 | } | |
123 | ||
124 | // We get db by param to not import it in this file (import orders) | |
125 | async function clientsExist () { | |
126 | const totalClients = await OAuthClientModel.countTotal() | |
127 | ||
128 | return totalClients !== 0 | |
129 | } | |
130 | ||
131 | // We get db by param to not import it in this file (import orders) | |
132 | async function usersExist () { | |
133 | const totalUsers = await UserModel.countTotal() | |
134 | ||
135 | return totalUsers !== 0 | |
136 | } | |
137 | ||
138 | // We get db by param to not import it in this file (import orders) | |
139 | async function applicationExist () { | |
140 | const totalApplication = await ApplicationModel.countTotal() | |
141 | ||
142 | return totalApplication !== 0 | |
143 | } | |
144 | ||
145 | // --------------------------------------------------------------------------- | |
146 | ||
147 | export { | |
148 | checkConfig, | |
149 | clientsExist, | |
150 | usersExist, | |
151 | applicationExist, | |
152 | checkActivityPubUrls | |
153 | } |