aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/checker-after-init.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-24 13:07:33 +0200
committerChocobozzz <me@florianbigard.com>2018-09-24 13:38:39 +0200
commite5565833f62b97f62ea75eba5b479963ae78b873 (patch)
tree835793ce464f9666b0ceae79f3d278cc4e007b32 /server/initializers/checker-after-init.ts
parentd1a63fc7ac58a1db00d8ca4f43aadba02eb9b084 (diff)
downloadPeerTube-e5565833f62b97f62ea75eba5b479963ae78b873.tar.gz
PeerTube-e5565833f62b97f62ea75eba5b479963ae78b873.tar.zst
PeerTube-e5565833f62b97f62ea75eba5b479963ae78b873.zip
Improve redundancy: add 'min_lifetime' configuration
Diffstat (limited to 'server/initializers/checker-after-init.ts')
-rw-r--r--server/initializers/checker-after-init.ts115
1 files changed, 115 insertions, 0 deletions
diff --git a/server/initializers/checker-after-init.ts b/server/initializers/checker-after-init.ts
new file mode 100644
index 000000000..588526235
--- /dev/null
+++ b/server/initializers/checker-after-init.ts
@@ -0,0 +1,115 @@
1import * as config from 'config'
2import { promisify0, isProdInstance, parseDuration, isTestInstance } from '../helpers/core-utils'
3import { UserModel } from '../models/account/user'
4import { ApplicationModel } from '../models/application/application'
5import { OAuthClientModel } from '../models/oauth/oauth-client'
6import { parse } from 'url'
7import { CONFIG } from './constants'
8import { logger } from '../helpers/logger'
9import { getServerActor } from '../helpers/utils'
10import { RecentlyAddedStrategy, VideosRedundancy } from '../../shared/models/redundancy'
11import { isArray } from '../helpers/custom-validators/misc'
12import { uniq } from 'lodash'
13
14async 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
32// Some checks on configuration files
33// Return an error message, or null if everything is okay
34function checkConfig () {
35 const defaultNSFWPolicy = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY
36
37 // NSFW policy
38 {
39 const available = [ 'do_not_list', 'blur', 'display' ]
40 if (available.indexOf(defaultNSFWPolicy) === -1) {
41 return 'NSFW policy setting should be ' + available.join(' or ') + ' instead of ' + defaultNSFWPolicy
42 }
43 }
44
45 // Redundancies
46 const redundancyVideos = CONFIG.REDUNDANCY.VIDEOS.STRATEGIES
47 if (isArray(redundancyVideos)) {
48 const available = [ 'most-views', 'trending', 'recently-added' ]
49 for (const r of redundancyVideos) {
50 if (available.indexOf(r.strategy) === -1) {
51 return 'Videos redundancy should have ' + available.join(' or ') + ' strategy instead of ' + r.strategy
52 }
53
54 // Lifetime should not be < 10 hours
55 if (!isTestInstance() && r.minLifetime < 1000 * 3600 * 10) {
56 return 'Video redundancy minimum lifetime should be >= 10 hours for strategy ' + r.strategy
57 }
58 }
59
60 const filtered = uniq(redundancyVideos.map(r => r.strategy))
61 if (filtered.length !== redundancyVideos.length) {
62 return 'Redundancy video entries should have unique strategies'
63 }
64
65 const recentlyAddedStrategy = redundancyVideos.find(r => r.strategy === 'recently-added') as RecentlyAddedStrategy
66 if (recentlyAddedStrategy && isNaN(recentlyAddedStrategy.minViews)) {
67 return 'Min views in recently added strategy is not a number'
68 }
69 }
70
71 if (isProdInstance()) {
72 const configStorage = config.get('storage')
73 for (const key of Object.keys(configStorage)) {
74 if (configStorage[key].startsWith('storage/')) {
75 logger.warn(
76 'Directory of %s should not be in the production directory of PeerTube. Please check your production configuration file.',
77 key
78 )
79 }
80 }
81 }
82
83 return null
84}
85
86// We get db by param to not import it in this file (import orders)
87async function clientsExist () {
88 const totalClients = await OAuthClientModel.countTotal()
89
90 return totalClients !== 0
91}
92
93// We get db by param to not import it in this file (import orders)
94async function usersExist () {
95 const totalUsers = await UserModel.countTotal()
96
97 return totalUsers !== 0
98}
99
100// We get db by param to not import it in this file (import orders)
101async function applicationExist () {
102 const totalApplication = await ApplicationModel.countTotal()
103
104 return totalApplication !== 0
105}
106
107// ---------------------------------------------------------------------------
108
109export {
110 checkConfig,
111 clientsExist,
112 usersExist,
113 applicationExist,
114 checkActivityPubUrls
115}