|
1 | 1 | import * as config from 'config'
|
2 |
| -import { promisify0, isProdInstance } 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 './constants' |
8 |
| -import { logger } from '../helpers/logger' |
9 |
| -import { getServerActor } from '../helpers/utils' |
10 |
| -import { RecentlyAddedStrategy, VideosRedundancy } from '../../shared/models/redundancy' |
| 2 | +import { promisify0 } from '../helpers/core-utils' |
11 | 3 | import { isArray } from '../helpers/custom-validators/misc'
|
12 |
| -import { uniq } from 'lodash' |
13 |
| - |
14 |
| -async function checkActivityPubUrls () { |
15 |
| - const actor = await getServerActor() |
16 |
| - |
17 |
| - const parsed = parse(actor.url) |
18 |
| - if (CONFIG.WEBSERVER.HOST !== parsed.host) { |
19 |
| - const NODE_ENV = config.util.getEnv('NODE_ENV') |
20 |
| - const NODE_CONFIG_DIR = config.util.getEnv('NODE_CONFIG_DIR') |
21 |
| - |
22 |
| - logger.warn( |
23 |
| - 'It seems PeerTube was started (and created some data) with another domain name. ' + |
24 |
| - 'This means you will not be able to federate! ' + |
25 |
| - 'Please use %s %s npm run update-host to fix this.', |
26 |
| - NODE_CONFIG_DIR ? `NODE_CONFIG_DIR=${NODE_CONFIG_DIR}` : '', |
27 |
| - NODE_ENV ? `NODE_ENV=${NODE_ENV}` : '' |
28 |
| - ) |
29 |
| - } |
30 |
| -} |
31 | 4 |
|
32 |
| -// Some checks on configuration files |
33 |
| -// Return an error message, or null if everything is okay |
34 |
| -function checkConfig () { |
35 |
| - const defaultNSFWPolicy = config.get<string>('instance.default_nsfw_policy') |
36 |
| - |
37 |
| - // NSFW policy |
38 |
| - if ([ 'do_not_list', 'blur', 'display' ].indexOf(defaultNSFWPolicy) === -1) { |
39 |
| - return 'NSFW policy setting should be "do_not_list" or "blur" or "display" instead of ' + defaultNSFWPolicy |
40 |
| - } |
41 |
| - |
42 |
| - // Redundancies |
43 |
| - const redundancyVideos = config.get<VideosRedundancy[]>('redundancy.videos.strategies') |
44 |
| - if (isArray(redundancyVideos)) { |
45 |
| - for (const r of redundancyVideos) { |
46 |
| - if ([ 'most-views', 'trending', 'recently-added' ].indexOf(r.strategy) === -1) { |
47 |
| - return 'Redundancy video entries should have "most-views" strategy instead of ' + r.strategy |
48 |
| - } |
49 |
| - } |
50 |
| - |
51 |
| - const filtered = uniq(redundancyVideos.map(r => r.strategy)) |
52 |
| - if (filtered.length !== redundancyVideos.length) { |
53 |
| - return 'Redundancy video entries should have unique strategies' |
54 |
| - } |
55 |
| - |
56 |
| - const recentlyAddedStrategy = redundancyVideos.find(r => r.strategy === 'recently-added') as RecentlyAddedStrategy |
57 |
| - if (recentlyAddedStrategy && isNaN(recentlyAddedStrategy.minViews)) { |
58 |
| - return 'Min views in recently added strategy is not a number' |
59 |
| - } |
60 |
| - } |
61 |
| - |
62 |
| - if (isProdInstance()) { |
63 |
| - const configStorage = config.get('storage') |
64 |
| - for (const key of Object.keys(configStorage)) { |
65 |
| - if (configStorage[key].startsWith('storage/')) { |
66 |
| - logger.warn( |
67 |
| - 'Directory of %s should not be in the production directory of PeerTube. Please check your production configuration file.', |
68 |
| - key |
69 |
| - ) |
70 |
| - } |
71 |
| - } |
72 |
| - } |
73 |
| - |
74 |
| - return null |
75 |
| -} |
| 5 | +// ONLY USE CORE MODULES IN THIS FILE! |
76 | 6 |
|
77 | 7 | // Check the config files
|
78 | 8 | function checkMissedConfig () {
|
@@ -109,6 +39,14 @@ function checkMissedConfig () {
|
109 | 39 | }
|
110 | 40 | }
|
111 | 41 |
|
| 42 | + const redundancyVideos = config.get<any>('redundancy.videos.strategies') |
| 43 | + if (isArray(redundancyVideos)) { |
| 44 | + for (const r of redundancyVideos) { |
| 45 | + if (!r.size) miss.push('redundancy.videos.strategies.size') |
| 46 | + if (!r.min_lifetime) miss.push('redundancy.videos.strategies.min_lifetime') |
| 47 | + } |
| 48 | + } |
| 49 | + |
112 | 50 | const missingAlternatives = requiredAlternatives.filter(
|
113 | 51 | set => !set.find(alternative => !alternative.find(key => !config.has(key)))
|
114 | 52 | )
|
@@ -163,36 +101,10 @@ async function checkFFmpegEncoders (): Promise<Map<string, boolean>> {
|
163 | 101 | }
|
164 | 102 | }
|
165 | 103 |
|
166 |
| -// We get db by param to not import it in this file (import orders) |
167 |
| -async function clientsExist () { |
168 |
| - const totalClients = await OAuthClientModel.countTotal() |
169 |
| - |
170 |
| - return totalClients !== 0 |
171 |
| -} |
172 |
| - |
173 |
| -// We get db by param to not import it in this file (import orders) |
174 |
| -async function usersExist () { |
175 |
| - const totalUsers = await UserModel.countTotal() |
176 |
| - |
177 |
| - return totalUsers !== 0 |
178 |
| -} |
179 |
| - |
180 |
| -// We get db by param to not import it in this file (import orders) |
181 |
| -async function applicationExist () { |
182 |
| - const totalApplication = await ApplicationModel.countTotal() |
183 |
| - |
184 |
| - return totalApplication !== 0 |
185 |
| -} |
186 |
| - |
187 | 104 | // ---------------------------------------------------------------------------
|
188 | 105 |
|
189 | 106 | export {
|
190 |
| - checkConfig, |
191 | 107 | checkFFmpeg,
|
192 | 108 | checkFFmpegEncoders,
|
193 |
| - checkMissedConfig, |
194 |
| - clientsExist, |
195 |
| - usersExist, |
196 |
| - applicationExist, |
197 |
| - checkActivityPubUrls |
| 109 | + checkMissedConfig |
198 | 110 | }
|
0 commit comments