aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-11 11:33:44 +0200
committerChocobozzz <me@florianbigard.com>2019-04-11 13:45:39 +0200
commit6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0 (patch)
treeb47de7efb8c6c611c63a15a971c6125a278f547a /server
parent2c3abc4fa796555eb7d25f416c4f41ab3e3ad8ca (diff)
downloadPeerTube-6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0.tar.gz
PeerTube-6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0.tar.zst
PeerTube-6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0.zip
Move config in its own file
Diffstat (limited to 'server')
-rw-r--r--server/controllers/activitypub/client.ts19
-rw-r--r--server/controllers/api/config.ts3
-rw-r--r--server/controllers/api/oauth-clients.ts2
-rw-r--r--server/controllers/api/server/logs.ts3
-rw-r--r--server/controllers/api/server/stats.ts3
-rw-r--r--server/controllers/api/users/index.ts7
-rw-r--r--server/controllers/api/users/me.ts3
-rw-r--r--server/controllers/api/users/my-subscriptions.ts4
-rw-r--r--server/controllers/api/video-channel.ts3
-rw-r--r--server/controllers/api/video-playlist.ts3
-rw-r--r--server/controllers/api/videos/captions.ts3
-rw-r--r--server/controllers/api/videos/import.ts5
-rw-r--r--server/controllers/api/videos/index.ts2
-rw-r--r--server/controllers/bots.ts16
-rw-r--r--server/controllers/feeds.ts11
-rw-r--r--server/controllers/services.ts6
-rw-r--r--server/controllers/static.ts7
-rw-r--r--server/controllers/tracker.ts3
-rw-r--r--server/helpers/audit-logger.ts2
-rw-r--r--server/helpers/captions-utils.ts2
-rw-r--r--server/helpers/custom-validators/video-channels.ts2
-rw-r--r--server/helpers/custom-validators/webfinger.ts4
-rw-r--r--server/helpers/express-utils.ts5
-rw-r--r--server/helpers/ffmpeg-utils.ts5
-rw-r--r--server/helpers/logger.ts2
-rw-r--r--server/helpers/requests.ts3
-rw-r--r--server/helpers/signup.ts3
-rw-r--r--server/helpers/utils.ts2
-rw-r--r--server/helpers/webfinger.ts4
-rw-r--r--server/helpers/webtorrent.ts2
-rw-r--r--server/initializers/checker-after-init.ts5
-rw-r--r--server/initializers/config.ts255
-rw-r--r--server/initializers/constants.ts321
-rw-r--r--server/initializers/database.ts2
-rw-r--r--server/initializers/installer.ts5
-rw-r--r--server/initializers/migrations/0075-video-resolutions.ts2
-rw-r--r--server/initializers/migrations/0140-actor-url.ts6
-rw-r--r--server/initializers/migrations/0235-delete-some-video-indexes.ts4
-rw-r--r--server/initializers/migrations/0240-drop-old-indexes.ts4
-rw-r--r--server/initializers/migrations/0345-video-playlists.ts4
-rw-r--r--server/lib/activitypub/actor.ts5
-rw-r--r--server/lib/activitypub/playlist.ts3
-rw-r--r--server/lib/activitypub/process/process-follow.ts3
-rw-r--r--server/lib/activitypub/url.ts20
-rw-r--r--server/lib/activitypub/videos.ts2
-rw-r--r--server/lib/avatar.ts3
-rw-r--r--server/lib/client-html.ts13
-rw-r--r--server/lib/emailer.ts43
-rw-r--r--server/lib/files-cache/videos-caption-cache.ts3
-rw-r--r--server/lib/files-cache/videos-preview-cache.ts3
-rw-r--r--server/lib/hls.ts3
-rw-r--r--server/lib/job-queue/handlers/activitypub-follow.ts4
-rw-r--r--server/lib/job-queue/handlers/video-import.ts5
-rw-r--r--server/lib/job-queue/handlers/video-transcoding.ts3
-rw-r--r--server/lib/job-queue/job-queue.ts4
-rw-r--r--server/lib/notifier.ts2
-rw-r--r--server/lib/oauth-model.ts3
-rw-r--r--server/lib/redis.ts7
-rw-r--r--server/lib/schedulers/videos-redundancy-scheduler.ts7
-rw-r--r--server/lib/video-blacklist.ts2
-rw-r--r--server/lib/video-transcoding.ts7
-rw-r--r--server/middlewares/csp.ts2
-rw-r--r--server/middlewares/validators/blocklist.ts5
-rw-r--r--server/middlewares/validators/follows.ts4
-rw-r--r--server/middlewares/validators/oembed.ts4
-rw-r--r--server/middlewares/validators/server.ts2
-rw-r--r--server/middlewares/validators/user-subscriptions.ts4
-rw-r--r--server/middlewares/validators/videos/video-imports.ts2
-rw-r--r--server/middlewares/validators/videos/videos.ts3
-rw-r--r--server/models/account/account.ts4
-rw-r--r--server/models/activitypub/actor.ts6
-rw-r--r--server/models/avatar/avatar.ts3
-rw-r--r--server/models/redundancy/video-redundancy.ts3
-rw-r--r--server/models/video/video-caption.ts3
-rw-r--r--server/models/video/video-channel.ts7
-rw-r--r--server/models/video/video-comment.ts4
-rw-r--r--server/models/video/video-format-utils.ts4
-rw-r--r--server/models/video/video-playlist.ts7
-rw-r--r--server/models/video/video.ts22
79 files changed, 523 insertions, 458 deletions
diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts
index e06aa35f4..f47fae766 100644
--- a/server/controllers/activitypub/client.ts
+++ b/server/controllers/activitypub/client.ts
@@ -2,7 +2,7 @@
2import * as express from 'express' 2import * as express from 'express'
3import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos' 3import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos'
4import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub' 4import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
5import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers' 5import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../../initializers'
6import { buildAnnounceWithVideoAudience, buildLikeActivity } from '../../lib/activitypub/send' 6import { buildAnnounceWithVideoAudience, buildLikeActivity } from '../../lib/activitypub/send'
7import { audiencify, getAudience } from '../../lib/activitypub/audience' 7import { audiencify, getAudience } from '../../lib/activitypub/audience'
8import { buildCreateActivity } from '../../lib/activitypub/send/send-create' 8import { buildCreateActivity } from '../../lib/activitypub/send/send-create'
@@ -19,7 +19,6 @@ import { AccountModel } from '../../models/account/account'
19import { ActorModel } from '../../models/activitypub/actor' 19import { ActorModel } from '../../models/activitypub/actor'
20import { ActorFollowModel } from '../../models/activitypub/actor-follow' 20import { ActorFollowModel } from '../../models/activitypub/actor-follow'
21import { VideoModel } from '../../models/video/video' 21import { VideoModel } from '../../models/video/video'
22import { VideoChannelModel } from '../../models/video/video-channel'
23import { VideoCommentModel } from '../../models/video/video-comment' 22import { VideoCommentModel } from '../../models/video/video-comment'
24import { VideoShareModel } from '../../models/video/video-share' 23import { VideoShareModel } from '../../models/video/video-share'
25import { cacheRoute } from '../../middlewares/cache' 24import { cacheRoute } from '../../middlewares/cache'
@@ -35,11 +34,9 @@ import {
35import { VideoCaptionModel } from '../../models/video/video-caption' 34import { VideoCaptionModel } from '../../models/video/video-caption'
36import { videoFileRedundancyGetValidator, videoPlaylistRedundancyGetValidator } from '../../middlewares/validators/redundancy' 35import { videoFileRedundancyGetValidator, videoPlaylistRedundancyGetValidator } from '../../middlewares/validators/redundancy'
37import { getServerActor } from '../../helpers/utils' 36import { getServerActor } from '../../helpers/utils'
38import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
39import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike' 37import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike'
40import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists' 38import { videoPlaylistElementAPGetValidator, videoPlaylistsGetValidator } from '../../middlewares/validators/videos/video-playlists'
41import { VideoPlaylistModel } from '../../models/video/video-playlist' 39import { VideoPlaylistModel } from '../../models/video/video-playlist'
42import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element'
43import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' 40import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
44 41
45const activityPubClientRouter = express.Router() 42const activityPubClientRouter = express.Router()
@@ -213,7 +210,7 @@ async function videoController (req: express.Request, res: express.Response) {
213 // We need more attributes 210 // We need more attributes
214 const video = await VideoModel.loadForGetAPI(res.locals.video.id) 211 const video = await VideoModel.loadForGetAPI(res.locals.video.id)
215 212
216 if (video.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(video.url) 213 if (video.url.startsWith(WEBSERVER.URL) === false) return res.redirect(video.url)
217 214
218 // We need captions to render AP object 215 // We need captions to render AP object
219 video.VideoCaptions = await VideoCaptionModel.listVideoCaptions(video.id) 216 video.VideoCaptions = await VideoCaptionModel.listVideoCaptions(video.id)
@@ -232,7 +229,7 @@ async function videoController (req: express.Request, res: express.Response) {
232async function videoAnnounceController (req: express.Request, res: express.Response) { 229async function videoAnnounceController (req: express.Request, res: express.Response) {
233 const share = res.locals.videoShare 230 const share = res.locals.videoShare
234 231
235 if (share.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(share.url) 232 if (share.url.startsWith(WEBSERVER.URL) === false) return res.redirect(share.url)
236 233
237 const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.video, undefined) 234 const { activity } = await buildAnnounceWithVideoAudience(share.Actor, share, res.locals.video, undefined)
238 235
@@ -306,7 +303,7 @@ async function videoChannelFollowingController (req: express.Request, res: expre
306async function videoCommentController (req: express.Request, res: express.Response) { 303async function videoCommentController (req: express.Request, res: express.Response) {
307 const videoComment = res.locals.videoComment 304 const videoComment = res.locals.videoComment
308 305
309 if (videoComment.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoComment.url) 306 if (videoComment.url.startsWith(WEBSERVER.URL) === false) return res.redirect(videoComment.url)
310 307
311 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined) 308 const threadParentComments = await VideoCommentModel.listThreadParentComments(videoComment, undefined)
312 const isPublic = true // Comments are always public 309 const isPublic = true // Comments are always public
@@ -324,7 +321,7 @@ async function videoCommentController (req: express.Request, res: express.Respon
324 321
325async function videoRedundancyController (req: express.Request, res: express.Response) { 322async function videoRedundancyController (req: express.Request, res: express.Response) {
326 const videoRedundancy = res.locals.videoRedundancy 323 const videoRedundancy = res.locals.videoRedundancy
327 if (videoRedundancy.url.startsWith(CONFIG.WEBSERVER.URL) === false) return res.redirect(videoRedundancy.url) 324 if (videoRedundancy.url.startsWith(WEBSERVER.URL) === false) return res.redirect(videoRedundancy.url)
328 325
329 const serverActor = await getServerActor() 326 const serverActor = await getServerActor()
330 327
@@ -366,7 +363,7 @@ async function actorFollowing (req: express.Request, actor: ActorModel) {
366 return ActorFollowModel.listAcceptedFollowingUrlsForApi([ actor.id ], undefined, start, count) 363 return ActorFollowModel.listAcceptedFollowingUrlsForApi([ actor.id ], undefined, start, count)
367 } 364 }
368 365
369 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page) 366 return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page)
370} 367}
371 368
372async function actorFollowers (req: express.Request, actor: ActorModel) { 369async function actorFollowers (req: express.Request, actor: ActorModel) {
@@ -374,7 +371,7 @@ async function actorFollowers (req: express.Request, actor: ActorModel) {
374 return ActorFollowModel.listAcceptedFollowerUrlsForAP([ actor.id ], undefined, start, count) 371 return ActorFollowModel.listAcceptedFollowerUrlsForAP([ actor.id ], undefined, start, count)
375 } 372 }
376 373
377 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page) 374 return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page)
378} 375}
379 376
380async function actorPlaylists (req: express.Request, account: AccountModel) { 377async function actorPlaylists (req: express.Request, account: AccountModel) {
@@ -382,7 +379,7 @@ async function actorPlaylists (req: express.Request, account: AccountModel) {
382 return VideoPlaylistModel.listPublicUrlsOfForAP(account.id, start, count) 379 return VideoPlaylistModel.listPublicUrlsOfForAP(account.id, start, count)
383 } 380 }
384 381
385 return activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.path, handler, req.query.page) 382 return activityPubCollectionPagination(WEBSERVER.URL + req.path, handler, req.query.page)
386} 383}
387 384
388function videoRates (req: express.Request, rateType: VideoRateType, video: VideoModel, url: string) { 385function videoRates (req: express.Request, rateType: VideoRateType, video: VideoModel, url: string) {
diff --git a/server/controllers/api/config.ts b/server/controllers/api/config.ts
index 0d7fc8625..cdbccaa7d 100644
--- a/server/controllers/api/config.ts
+++ b/server/controllers/api/config.ts
@@ -4,7 +4,7 @@ import { ServerConfig, UserRight } from '../../../shared'
4import { About } from '../../../shared/models/server/about.model' 4import { About } from '../../../shared/models/server/about.model'
5import { CustomConfig } from '../../../shared/models/server/custom-config.model' 5import { CustomConfig } from '../../../shared/models/server/custom-config.model'
6import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup' 6import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup'
7import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers' 7import { CONSTRAINTS_FIELDS } from '../../initializers'
8import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares' 8import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
9import { customConfigUpdateValidator } from '../../middlewares/validators/config' 9import { customConfigUpdateValidator } from '../../middlewares/validators/config'
10import { ClientHtml } from '../../lib/client-html' 10import { ClientHtml } from '../../lib/client-html'
@@ -14,6 +14,7 @@ import { getServerCommit } from '../../helpers/utils'
14import { Emailer } from '../../lib/emailer' 14import { Emailer } from '../../lib/emailer'
15import { isNumeric } from 'validator' 15import { isNumeric } from 'validator'
16import { objectConverter } from '../../helpers/core-utils' 16import { objectConverter } from '../../helpers/core-utils'
17import { CONFIG, reloadConfig } from '../../initializers/config'
17 18
18const packageJSON = require('../../../../package.json') 19const packageJSON = require('../../../../package.json')
19const configRouter = express.Router() 20const configRouter = express.Router()
diff --git a/server/controllers/api/oauth-clients.ts b/server/controllers/api/oauth-clients.ts
index 3dcc023e6..b2de8bcf5 100644
--- a/server/controllers/api/oauth-clients.ts
+++ b/server/controllers/api/oauth-clients.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import { OAuthClientLocal } from '../../../shared' 2import { OAuthClientLocal } from '../../../shared'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { CONFIG } from '../../initializers' 4import { CONFIG } from '../../initializers/config'
5import { asyncMiddleware } from '../../middlewares' 5import { asyncMiddleware } from '../../middlewares'
6import { OAuthClientModel } from '../../models/oauth/oauth-client' 6import { OAuthClientModel } from '../../models/oauth/oauth-client'
7 7
diff --git a/server/controllers/api/server/logs.ts b/server/controllers/api/server/logs.ts
index 5fa3c8787..bbbfa1d80 100644
--- a/server/controllers/api/server/logs.ts
+++ b/server/controllers/api/server/logs.ts
@@ -3,10 +3,11 @@ import { UserRight } from '../../../../shared/models/users'
3import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares' 3import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../../middlewares'
4import { mtimeSortFilesDesc } from '../../../../shared/utils/logs/logs' 4import { mtimeSortFilesDesc } from '../../../../shared/utils/logs/logs'
5import { readdir, readFile } from 'fs-extra' 5import { readdir, readFile } from 'fs-extra'
6import { CONFIG, MAX_LOGS_OUTPUT_CHARACTERS } from '../../../initializers' 6import { MAX_LOGS_OUTPUT_CHARACTERS } from '../../../initializers'
7import { join } from 'path' 7import { join } from 'path'
8import { getLogsValidator } from '../../../middlewares/validators/logs' 8import { getLogsValidator } from '../../../middlewares/validators/logs'
9import { LogLevel } from '../../../../shared/models/server/log-level.type' 9import { LogLevel } from '../../../../shared/models/server/log-level.type'
10import { CONFIG } from '../../../initializers/config'
10 11
11const logsRouter = express.Router() 12const logsRouter = express.Router()
12 13
diff --git a/server/controllers/api/server/stats.ts b/server/controllers/api/server/stats.ts
index 89ffd1717..951b98209 100644
--- a/server/controllers/api/server/stats.ts
+++ b/server/controllers/api/server/stats.ts
@@ -6,9 +6,10 @@ import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
6import { VideoModel } from '../../../models/video/video' 6import { VideoModel } from '../../../models/video/video'
7import { VideoCommentModel } from '../../../models/video/video-comment' 7import { VideoCommentModel } from '../../../models/video/video-comment'
8import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' 8import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
9import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../../initializers/constants' 9import { ROUTE_CACHE_LIFETIME } from '../../../initializers/constants'
10import { cacheRoute } from '../../../middlewares/cache' 10import { cacheRoute } from '../../../middlewares/cache'
11import { VideoFileModel } from '../../../models/video/video-file' 11import { VideoFileModel } from '../../../models/video/video-file'
12import { CONFIG } from '../../../initializers/config'
12 13
13const statsRouter = express.Router() 14const statsRouter = express.Router()
14 15
diff --git a/server/controllers/api/users/index.ts b/server/controllers/api/users/index.ts
index 2117bdfeb..a049e23e4 100644
--- a/server/controllers/api/users/index.ts
+++ b/server/controllers/api/users/index.ts
@@ -3,7 +3,7 @@ import * as RateLimit from 'express-rate-limit'
3import { UserCreate, UserRight, UserRole, UserUpdate } from '../../../../shared' 3import { UserCreate, UserRight, UserRole, UserUpdate } from '../../../../shared'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { getFormattedObjects } from '../../../helpers/utils' 5import { getFormattedObjects } from '../../../helpers/utils'
6import { CONFIG, RATES_LIMIT, sequelizeTypescript } from '../../../initializers' 6import { RATES_LIMIT, sequelizeTypescript, WEBSERVER } from '../../../initializers'
7import { Emailer } from '../../../lib/emailer' 7import { Emailer } from '../../../lib/emailer'
8import { Redis } from '../../../lib/redis' 8import { Redis } from '../../../lib/redis'
9import { createUserAccountAndChannelAndPlaylist } from '../../../lib/user' 9import { createUserAccountAndChannelAndPlaylist } from '../../../lib/user'
@@ -43,6 +43,7 @@ import { myVideosHistoryRouter } from './my-history'
43import { myNotificationsRouter } from './my-notifications' 43import { myNotificationsRouter } from './my-notifications'
44import { Notifier } from '../../../lib/notifier' 44import { Notifier } from '../../../lib/notifier'
45import { mySubscriptionsRouter } from './my-subscriptions' 45import { mySubscriptionsRouter } from './my-subscriptions'
46import { CONFIG } from '../../../initializers/config'
46 47
47const auditLogger = auditLoggerFactory('users') 48const auditLogger = auditLoggerFactory('users')
48 49
@@ -293,7 +294,7 @@ async function askResetUserPassword (req: express.Request, res: express.Response
293 const user = res.locals.user 294 const user = res.locals.user
294 295
295 const verificationString = await Redis.Instance.setResetPasswordVerificationString(user.id) 296 const verificationString = await Redis.Instance.setResetPasswordVerificationString(user.id)
296 const url = CONFIG.WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString 297 const url = WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString
297 await Emailer.Instance.addPasswordResetEmailJob(user.email, url) 298 await Emailer.Instance.addPasswordResetEmailJob(user.email, url)
298 299
299 return res.status(204).end() 300 return res.status(204).end()
@@ -310,7 +311,7 @@ async function resetUserPassword (req: express.Request, res: express.Response) {
310 311
311async function sendVerifyUserEmail (user: UserModel) { 312async function sendVerifyUserEmail (user: UserModel) {
312 const verificationString = await Redis.Instance.setVerifyEmailVerificationString(user.id) 313 const verificationString = await Redis.Instance.setVerifyEmailVerificationString(user.id)
313 const url = CONFIG.WEBSERVER.URL + '/verify-account/email?userId=' + user.id + '&verificationString=' + verificationString 314 const url = WEBSERVER.URL + '/verify-account/email?userId=' + user.id + '&verificationString=' + verificationString
314 await Emailer.Instance.addVerifyEmailJob(user.email, url) 315 await Emailer.Instance.addVerifyEmailJob(user.email, url)
315 return 316 return
316} 317}
diff --git a/server/controllers/api/users/me.ts b/server/controllers/api/users/me.ts
index 3533499be..1d1588eca 100644
--- a/server/controllers/api/users/me.ts
+++ b/server/controllers/api/users/me.ts
@@ -2,7 +2,7 @@ import * as express from 'express'
2import 'multer' 2import 'multer'
3import { UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../../shared' 3import { UserUpdateMe, UserVideoRate as FormattedUserVideoRate } from '../../../../shared'
4import { getFormattedObjects } from '../../../helpers/utils' 4import { getFormattedObjects } from '../../../helpers/utils'
5import { CONFIG, MIMETYPES, sequelizeTypescript } from '../../../initializers' 5import { MIMETYPES, sequelizeTypescript } from '../../../initializers'
6import { sendUpdateActor } from '../../../lib/activitypub/send' 6import { sendUpdateActor } from '../../../lib/activitypub/send'
7import { 7import {
8 asyncMiddleware, 8 asyncMiddleware,
@@ -26,6 +26,7 @@ import { updateActorAvatarFile } from '../../../lib/avatar'
26import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger' 26import { auditLoggerFactory, getAuditIdFromRes, UserAuditView } from '../../../helpers/audit-logger'
27import { VideoImportModel } from '../../../models/video/video-import' 27import { VideoImportModel } from '../../../models/video/video-import'
28import { AccountModel } from '../../../models/account/account' 28import { AccountModel } from '../../../models/account/account'
29import { CONFIG } from '../../../initializers/config'
29 30
30const auditLogger = auditLoggerFactory('users-me') 31const auditLogger = auditLoggerFactory('users-me')
31 32
diff --git a/server/controllers/api/users/my-subscriptions.ts b/server/controllers/api/users/my-subscriptions.ts
index a173adfd0..59b906a8b 100644
--- a/server/controllers/api/users/my-subscriptions.ts
+++ b/server/controllers/api/users/my-subscriptions.ts
@@ -1,7 +1,7 @@
1import * as express from 'express' 1import * as express from 'express'
2import 'multer' 2import 'multer'
3import { getFormattedObjects } from '../../../helpers/utils' 3import { getFormattedObjects } from '../../../helpers/utils'
4import { CONFIG, sequelizeTypescript } from '../../../initializers' 4import { sequelizeTypescript, WEBSERVER } from '../../../initializers'
5import { 5import {
6 asyncMiddleware, 6 asyncMiddleware,
7 asyncRetryTransactionMiddleware, 7 asyncRetryTransactionMiddleware,
@@ -80,7 +80,7 @@ async function areSubscriptionsExist (req: express.Request, res: express.Respons
80 80
81 const handles = uris.map(u => { 81 const handles = uris.map(u => {
82 let [ name, host ] = u.split('@') 82 let [ name, host ] = u.split('@')
83 if (host === CONFIG.WEBSERVER.HOST) host = null 83 if (host === WEBSERVER.HOST) host = null
84 84
85 return { name, host, uri: u } 85 return { name, host, uri: u }
86 }) 86 })
diff --git a/server/controllers/api/video-channel.ts b/server/controllers/api/video-channel.ts
index 5881cab41..b79ce9cec 100644
--- a/server/controllers/api/video-channel.ts
+++ b/server/controllers/api/video-channel.ts
@@ -23,7 +23,7 @@ import { createVideoChannel } from '../../lib/video-channel'
23import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' 23import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
24import { setAsyncActorKeys } from '../../lib/activitypub' 24import { setAsyncActorKeys } from '../../lib/activitypub'
25import { AccountModel } from '../../models/account/account' 25import { AccountModel } from '../../models/account/account'
26import { CONFIG, MIMETYPES, sequelizeTypescript } from '../../initializers' 26import { MIMETYPES, sequelizeTypescript } from '../../initializers'
27import { logger } from '../../helpers/logger' 27import { logger } from '../../helpers/logger'
28import { VideoModel } from '../../models/video/video' 28import { VideoModel } from '../../models/video/video'
29import { updateAvatarValidator } from '../../middlewares/validators/avatar' 29import { updateAvatarValidator } from '../../middlewares/validators/avatar'
@@ -33,6 +33,7 @@ import { resetSequelizeInstance } from '../../helpers/database-utils'
33import { JobQueue } from '../../lib/job-queue' 33import { JobQueue } from '../../lib/job-queue'
34import { VideoPlaylistModel } from '../../models/video/video-playlist' 34import { VideoPlaylistModel } from '../../models/video/video-playlist'
35import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists' 35import { commonVideoPlaylistFiltersValidator } from '../../middlewares/validators/videos/video-playlists'
36import { CONFIG } from '../../initializers/config'
36 37
37const auditLogger = auditLoggerFactory('channels') 38const auditLogger = auditLoggerFactory('channels')
38const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR }) 39const reqAvatarFile = createReqFiles([ 'avatarfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.TMP_DIR })
diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts
index feba30564..5a3d6a29d 100644
--- a/server/controllers/api/video-playlist.ts
+++ b/server/controllers/api/video-playlist.ts
@@ -12,7 +12,7 @@ import {
12} from '../../middlewares' 12} from '../../middlewares'
13import { videoPlaylistsSortValidator } from '../../middlewares/validators' 13import { videoPlaylistsSortValidator } from '../../middlewares/validators'
14import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' 14import { buildNSFWFilter, createReqFiles, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils'
15import { CONFIG, MIMETYPES, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers' 15import { MIMETYPES, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_PLAYLIST_PRIVACIES } from '../../initializers'
16import { logger } from '../../helpers/logger' 16import { logger } from '../../helpers/logger'
17import { resetSequelizeInstance } from '../../helpers/database-utils' 17import { resetSequelizeInstance } from '../../helpers/database-utils'
18import { VideoPlaylistModel } from '../../models/video/video-playlist' 18import { VideoPlaylistModel } from '../../models/video/video-playlist'
@@ -41,6 +41,7 @@ import { copy, pathExists } from 'fs-extra'
41import { AccountModel } from '../../models/account/account' 41import { AccountModel } from '../../models/account/account'
42import { VideoPlaylistReorder } from '../../../shared/models/videos/playlist/video-playlist-reorder.model' 42import { VideoPlaylistReorder } from '../../../shared/models/videos/playlist/video-playlist-reorder.model'
43import { JobQueue } from '../../lib/job-queue' 43import { JobQueue } from '../../lib/job-queue'
44import { CONFIG } from '../../initializers/config'
44 45
45const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR }) 46const reqThumbnailFile = createReqFiles([ 'thumbnailfile' ], MIMETYPES.IMAGE.MIMETYPE_EXT, { thumbnailfile: CONFIG.STORAGE.TMP_DIR })
46 47
diff --git a/server/controllers/api/videos/captions.ts b/server/controllers/api/videos/captions.ts
index 2694577d8..7dd36e368 100644
--- a/server/controllers/api/videos/captions.ts
+++ b/server/controllers/api/videos/captions.ts
@@ -2,12 +2,13 @@ import * as express from 'express'
2import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares' 2import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate } from '../../../middlewares'
3import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators' 3import { addVideoCaptionValidator, deleteVideoCaptionValidator, listVideoCaptionsValidator } from '../../../middlewares/validators'
4import { createReqFiles } from '../../../helpers/express-utils' 4import { createReqFiles } from '../../../helpers/express-utils'
5import { CONFIG, MIMETYPES, sequelizeTypescript } from '../../../initializers' 5import { MIMETYPES, sequelizeTypescript } from '../../../initializers'
6import { getFormattedObjects } from '../../../helpers/utils' 6import { getFormattedObjects } from '../../../helpers/utils'
7import { VideoCaptionModel } from '../../../models/video/video-caption' 7import { VideoCaptionModel } from '../../../models/video/video-caption'
8import { logger } from '../../../helpers/logger' 8import { logger } from '../../../helpers/logger'
9import { federateVideoIfNeeded } from '../../../lib/activitypub' 9import { federateVideoIfNeeded } from '../../../lib/activitypub'
10import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' 10import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
11import { CONFIG } from '../../../initializers/config'
11 12
12const reqVideoCaptionAdd = createReqFiles( 13const reqVideoCaptionAdd = createReqFiles(
13 [ 'captionfile' ], 14 [ 'captionfile' ],
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts
index c234a1391..5a8cd703e 100644
--- a/server/controllers/api/videos/import.ts
+++ b/server/controllers/api/videos/import.ts
@@ -3,7 +3,7 @@ import * as magnetUtil from 'magnet-uri'
3import 'multer' 3import 'multer'
4import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' 4import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger'
5import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' 5import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares'
6import { CONFIG, MIMETYPES, PREVIEWS_SIZE, sequelizeTypescript, THUMBNAILS_SIZE } from '../../../initializers' 6import { MIMETYPES, PREVIEWS_SIZE, sequelizeTypescript, THUMBNAILS_SIZE } from '../../../initializers'
7import { getYoutubeDLInfo, YoutubeDLInfo } from '../../../helpers/youtube-dl' 7import { getYoutubeDLInfo, YoutubeDLInfo } from '../../../helpers/youtube-dl'
8import { createReqFiles } from '../../../helpers/express-utils' 8import { createReqFiles } from '../../../helpers/express-utils'
9import { logger } from '../../../helpers/logger' 9import { logger } from '../../../helpers/logger'
@@ -22,8 +22,9 @@ import { UserModel } from '../../../models/account/user'
22import * as Bluebird from 'bluebird' 22import * as Bluebird from 'bluebird'
23import * as parseTorrent from 'parse-torrent' 23import * as parseTorrent from 'parse-torrent'
24import { getSecureTorrentName } from '../../../helpers/utils' 24import { getSecureTorrentName } from '../../../helpers/utils'
25import { readFile, move } from 'fs-extra' 25import { move, readFile } from 'fs-extra'
26import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' 26import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
27import { CONFIG } from '../../../initializers/config'
27 28
28const auditLogger = auditLoggerFactory('video-imports') 29const auditLogger = auditLoggerFactory('video-imports')
29const videoImportsRouter = express.Router() 30const videoImportsRouter = express.Router()
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index 393324819..9470afabf 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -8,7 +8,6 @@ import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../
8import { getFormattedObjects, getServerActor } from '../../../helpers/utils' 8import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
9import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' 9import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
10import { 10import {
11 CONFIG,
12 MIMETYPES, 11 MIMETYPES,
13 PREVIEWS_SIZE, 12 PREVIEWS_SIZE,
14 sequelizeTypescript, 13 sequelizeTypescript,
@@ -61,6 +60,7 @@ import { move } from 'fs-extra'
61import { watchingRouter } from './watching' 60import { watchingRouter } from './watching'
62import { Notifier } from '../../../lib/notifier' 61import { Notifier } from '../../../lib/notifier'
63import { sendView } from '../../../lib/activitypub/send/send-view' 62import { sendView } from '../../../lib/activitypub/send/send-view'
63import { CONFIG } from '../../../initializers/config'
64 64
65const auditLogger = auditLoggerFactory('videos') 65const auditLogger = auditLoggerFactory('videos')
66const videosRouter = express.Router() 66const videosRouter = express.Router()
diff --git a/server/controllers/bots.ts b/server/controllers/bots.ts
index 2db86a2d8..58ead4799 100644
--- a/server/controllers/bots.ts
+++ b/server/controllers/bots.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { asyncMiddleware } from '../middlewares' 2import { asyncMiddleware } from '../middlewares'
3import { CONFIG, ROUTE_CACHE_LIFETIME } from '../initializers' 3import { ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers'
4import * as sitemapModule from 'sitemap' 4import * as sitemapModule from 'sitemap'
5import { logger } from '../helpers/logger' 5import { logger } from '../helpers/logger'
6import { VideoModel } from '../models/video/video' 6import { VideoModel } from '../models/video/video'
@@ -35,7 +35,7 @@ async function getSitemap (req: express.Request, res: express.Response) {
35 urls = urls.concat(await getSitemapAccountUrls()) 35 urls = urls.concat(await getSitemapAccountUrls())
36 36
37 const sitemap = sitemapModule.createSitemap({ 37 const sitemap = sitemapModule.createSitemap({
38 hostname: CONFIG.WEBSERVER.URL, 38 hostname: WEBSERVER.URL,
39 urls: urls 39 urls: urls
40 }) 40 })
41 41
@@ -54,7 +54,7 @@ async function getSitemapVideoChannelUrls () {
54 const rows = await VideoChannelModel.listLocalsForSitemap('createdAt') 54 const rows = await VideoChannelModel.listLocalsForSitemap('createdAt')
55 55
56 return rows.map(channel => ({ 56 return rows.map(channel => ({
57 url: CONFIG.WEBSERVER.URL + '/video-channels/' + channel.Actor.preferredUsername 57 url: WEBSERVER.URL + '/video-channels/' + channel.Actor.preferredUsername
58 })) 58 }))
59} 59}
60 60
@@ -62,7 +62,7 @@ async function getSitemapAccountUrls () {
62 const rows = await AccountModel.listLocalsForSitemap('createdAt') 62 const rows = await AccountModel.listLocalsForSitemap('createdAt')
63 63
64 return rows.map(channel => ({ 64 return rows.map(channel => ({
65 url: CONFIG.WEBSERVER.URL + '/accounts/' + channel.Actor.preferredUsername 65 url: WEBSERVER.URL + '/accounts/' + channel.Actor.preferredUsername
66 })) 66 }))
67} 67}
68 68
@@ -78,14 +78,14 @@ async function getSitemapLocalVideoUrls () {
78 }) 78 })
79 79
80 return resultList.data.map(v => ({ 80 return resultList.data.map(v => ({
81 url: CONFIG.WEBSERVER.URL + '/videos/watch/' + v.uuid, 81 url: WEBSERVER.URL + '/videos/watch/' + v.uuid,
82 video: [ 82 video: [
83 { 83 {
84 title: v.name, 84 title: v.name,
85 // Sitemap description should be < 2000 characters 85 // Sitemap description should be < 2000 characters
86 description: truncate(v.description || v.name, { length: 2000, omission: '...' }), 86 description: truncate(v.description || v.name, { length: 2000, omission: '...' }),
87 player_loc: CONFIG.WEBSERVER.URL + '/videos/embed/' + v.uuid, 87 player_loc: WEBSERVER.URL + '/videos/embed/' + v.uuid,
88 thumbnail_loc: CONFIG.WEBSERVER.URL + v.getThumbnailStaticPath() 88 thumbnail_loc: WEBSERVER.URL + v.getThumbnailStaticPath()
89 } 89 }
90 ] 90 ]
91 })) 91 }))
@@ -97,5 +97,5 @@ function getSitemapBasicUrls () {
97 '/videos/local' 97 '/videos/local'
98 ] 98 ]
99 99
100 return paths.map(p => ({ url: CONFIG.WEBSERVER.URL + p })) 100 return paths.map(p => ({ url: WEBSERVER.URL + p }))
101} 101}
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts
index cd46b6e0f..24c41d946 100644
--- a/server/controllers/feeds.ts
+++ b/server/controllers/feeds.ts
@@ -1,5 +1,5 @@
1import * as express from 'express' 1import * as express from 'express'
2import { CONFIG, FEEDS, ROUTE_CACHE_LIFETIME } from '../initializers/constants' 2import { FEEDS, ROUTE_CACHE_LIFETIME, WEBSERVER } from '../initializers/constants'
3import { THUMBNAILS_SIZE } from '../initializers' 3import { THUMBNAILS_SIZE } from '../initializers'
4import { 4import {
5 asyncMiddleware, 5 asyncMiddleware,
@@ -14,6 +14,7 @@ import * as Feed from 'pfeed'
14import { cacheRoute } from '../middlewares/cache' 14import { cacheRoute } from '../middlewares/cache'
15import { VideoCommentModel } from '../models/video/video-comment' 15import { VideoCommentModel } from '../models/video/video-comment'
16import { buildNSFWFilter } from '../helpers/express-utils' 16import { buildNSFWFilter } from '../helpers/express-utils'
17import { CONFIG } from '../initializers/config'
17 18
18const feedsRouter = express.Router() 19const feedsRouter = express.Router()
19 20
@@ -54,7 +55,7 @@ async function generateVideoCommentsFeed (req: express.Request, res: express.Res
54 55
55 // Adding video items to the feed, one at a time 56 // Adding video items to the feed, one at a time
56 comments.forEach(comment => { 57 comments.forEach(comment => {
57 const link = CONFIG.WEBSERVER.URL + comment.getCommentStaticPath() 58 const link = WEBSERVER.URL + comment.getCommentStaticPath()
58 59
59 feed.addItem({ 60 feed.addItem({
60 title: `${comment.Video.name} - ${comment.Account.getDisplayName()}`, 61 title: `${comment.Video.name} - ${comment.Account.getDisplayName()}`,
@@ -122,7 +123,7 @@ async function generateVideoFeed (req: express.Request, res: express.Response) {
122 feed.addItem({ 123 feed.addItem({
123 title: video.name, 124 title: video.name,
124 id: video.url, 125 id: video.url,
125 link: CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid, 126 link: WEBSERVER.URL + '/videos/watch/' + video.uuid,
126 description: video.getTruncatedDescription(), 127 description: video.getTruncatedDescription(),
127 content: video.description, 128 content: video.description,
128 author: [ 129 author: [
@@ -137,7 +138,7 @@ async function generateVideoFeed (req: express.Request, res: express.Response) {
137 torrent: torrents, 138 torrent: torrents,
138 thumbnail: [ 139 thumbnail: [
139 { 140 {
140 url: CONFIG.WEBSERVER.URL + video.getThumbnailStaticPath(), 141 url: WEBSERVER.URL + video.getThumbnailStaticPath(),
141 height: THUMBNAILS_SIZE.height, 142 height: THUMBNAILS_SIZE.height,
142 width: THUMBNAILS_SIZE.width 143 width: THUMBNAILS_SIZE.width
143 } 144 }
@@ -150,7 +151,7 @@ async function generateVideoFeed (req: express.Request, res: express.Response) {
150} 151}
151 152
152function initFeed (name: string, description: string) { 153function initFeed (name: string, description: string) {
153 const webserverUrl = CONFIG.WEBSERVER.URL 154 const webserverUrl = WEBSERVER.URL
154 155
155 return new Feed({ 156 return new Feed({
156 title: name, 157 title: name,
diff --git a/server/controllers/services.ts b/server/controllers/services.ts
index cf7a513af..83b01b475 100644
--- a/server/controllers/services.ts
+++ b/server/controllers/services.ts
@@ -1,8 +1,8 @@
1import * as express from 'express' 1import * as express from 'express'
2import { CONFIG, EMBED_SIZE, PREVIEWS_SIZE } from '../initializers' 2import { EMBED_SIZE, PREVIEWS_SIZE, WEBSERVER } from '../initializers'
3import { asyncMiddleware, oembedValidator } from '../middlewares' 3import { asyncMiddleware, oembedValidator } from '../middlewares'
4import { accountNameWithHostGetValidator } from '../middlewares/validators' 4import { accountNameWithHostGetValidator } from '../middlewares/validators'
5import { VideoModel } from '../models/video/video' 5import { CONFIG } from '../initializers/config'
6 6
7const servicesRouter = express.Router() 7const servicesRouter = express.Router()
8 8
@@ -25,7 +25,7 @@ export {
25 25
26function generateOEmbed (req: express.Request, res: express.Response) { 26function generateOEmbed (req: express.Request, res: express.Response) {
27 const video = res.locals.video 27 const video = res.locals.video
28 const webserverUrl = CONFIG.WEBSERVER.URL 28 const webserverUrl = WEBSERVER.URL
29 const maxHeight = parseInt(req.query.maxheight, 10) 29 const maxHeight = parseInt(req.query.maxheight, 10)
30 const maxWidth = parseInt(req.query.maxwidth, 10) 30 const maxWidth = parseInt(req.query.maxwidth, 10)
31 31
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index e65c7afd3..be5fcc8ed 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -1,12 +1,12 @@
1import * as cors from 'cors' 1import * as cors from 'cors'
2import * as express from 'express' 2import * as express from 'express'
3import { 3import {
4 CONFIG,
5 HLS_STREAMING_PLAYLIST_DIRECTORY, 4 HLS_STREAMING_PLAYLIST_DIRECTORY,
6 ROUTE_CACHE_LIFETIME, 5 ROUTE_CACHE_LIFETIME,
7 STATIC_DOWNLOAD_PATHS, 6 STATIC_DOWNLOAD_PATHS,
8 STATIC_MAX_AGE, 7 STATIC_MAX_AGE,
9 STATIC_PATHS 8 STATIC_PATHS,
9 WEBSERVER
10} from '../initializers' 10} from '../initializers'
11import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' 11import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache'
12import { cacheRoute } from '../middlewares/cache' 12import { cacheRoute } from '../middlewares/cache'
@@ -17,6 +17,7 @@ import { VideoCommentModel } from '../models/video/video-comment'
17import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo' 17import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/nodeinfo'
18import { join } from 'path' 18import { join } from 'path'
19import { root } from '../helpers/core-utils' 19import { root } from '../helpers/core-utils'
20import { CONFIG } from '../initializers/config'
20 21
21const packageJSON = require('../../../package.json') 22const packageJSON = require('../../../package.json')
22const staticRouter = express.Router() 23const staticRouter = express.Router()
@@ -121,7 +122,7 @@ staticRouter.use('/.well-known/nodeinfo',
121 links: [ 122 links: [
122 { 123 {
123 rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0', 124 rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0',
124 href: CONFIG.WEBSERVER.URL + '/nodeinfo/2.0.json' 125 href: WEBSERVER.URL + '/nodeinfo/2.0.json'
125 } 126 }
126 ] 127 ]
127 }) 128 })
diff --git a/server/controllers/tracker.ts b/server/controllers/tracker.ts
index 56a3424a3..912f82b86 100644
--- a/server/controllers/tracker.ts
+++ b/server/controllers/tracker.ts
@@ -4,10 +4,11 @@ import * as http from 'http'
4import * as bitTorrentTracker from 'bittorrent-tracker' 4import * as bitTorrentTracker from 'bittorrent-tracker'
5import * as proxyAddr from 'proxy-addr' 5import * as proxyAddr from 'proxy-addr'
6import { Server as WebSocketServer } from 'ws' 6import { Server as WebSocketServer } from 'ws'
7import { CONFIG, TRACKER_RATE_LIMITS } from '../initializers/constants' 7import { TRACKER_RATE_LIMITS } from '../initializers/constants'
8import { VideoFileModel } from '../models/video/video-file' 8import { VideoFileModel } from '../models/video/video-file'
9import { parse } from 'url' 9import { parse } from 'url'
10import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist' 10import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist'
11import { CONFIG } from '../initializers/config'
11 12
12const TrackerServer = bitTorrentTracker.Server 13const TrackerServer = bitTorrentTracker.Server
13 14
diff --git a/server/helpers/audit-logger.ts b/server/helpers/audit-logger.ts
index af37bce16..f536da439 100644
--- a/server/helpers/audit-logger.ts
+++ b/server/helpers/audit-logger.ts
@@ -4,11 +4,11 @@ import { diff } from 'deep-object-diff'
4import { chain } from 'lodash' 4import { chain } from 'lodash'
5import * as flatten from 'flat' 5import * as flatten from 'flat'
6import * as winston from 'winston' 6import * as winston from 'winston'
7import { CONFIG } from '../initializers'
8import { jsonLoggerFormat, labelFormatter } from './logger' 7import { jsonLoggerFormat, labelFormatter } from './logger'
9import { User, VideoAbuse, VideoChannel, VideoDetails, VideoImport } from '../../shared' 8import { User, VideoAbuse, VideoChannel, VideoDetails, VideoImport } from '../../shared'
10import { VideoComment } from '../../shared/models/videos/video-comment.model' 9import { VideoComment } from '../../shared/models/videos/video-comment.model'
11import { CustomConfig } from '../../shared/models/server/custom-config.model' 10import { CustomConfig } from '../../shared/models/server/custom-config.model'
11import { CONFIG } from '../initializers/config'
12 12
13function getAuditIdFromRes (res: express.Response) { 13function getAuditIdFromRes (res: express.Response) {
14 return res.locals.oauth.token.User.username 14 return res.locals.oauth.token.User.username
diff --git a/server/helpers/captions-utils.ts b/server/helpers/captions-utils.ts
index 0fb11a125..7174d4654 100644
--- a/server/helpers/captions-utils.ts
+++ b/server/helpers/captions-utils.ts
@@ -1,5 +1,5 @@
1import { join } from 'path' 1import { join } from 'path'
2import { CONFIG } from '../initializers' 2import { CONFIG } from '../initializers/config'
3import { VideoCaptionModel } from '../models/video/video-caption' 3import { VideoCaptionModel } from '../models/video/video-caption'
4import * as srt2vtt from 'srt-to-vtt' 4import * as srt2vtt from 'srt-to-vtt'
5import { createReadStream, createWriteStream, remove, move } from 'fs-extra' 5import { createReadStream, createWriteStream, remove, move } from 'fs-extra'
diff --git a/server/helpers/custom-validators/video-channels.ts b/server/helpers/custom-validators/video-channels.ts
index fad7a9bcf..ca8d207cf 100644
--- a/server/helpers/custom-validators/video-channels.ts
+++ b/server/helpers/custom-validators/video-channels.ts
@@ -2,7 +2,7 @@ import * as express from 'express'
2import 'express-validator' 2import 'express-validator'
3import 'multer' 3import 'multer'
4import * as validator from 'validator' 4import * as validator from 'validator'
5import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' 5import { CONSTRAINTS_FIELDS } from '../../initializers'
6import { VideoChannelModel } from '../../models/video/video-channel' 6import { VideoChannelModel } from '../../models/video/video-channel'
7import { exists } from './misc' 7import { exists } from './misc'
8 8
diff --git a/server/helpers/custom-validators/webfinger.ts b/server/helpers/custom-validators/webfinger.ts
index 80a7e4a9d..b18e43fad 100644
--- a/server/helpers/custom-validators/webfinger.ts
+++ b/server/helpers/custom-validators/webfinger.ts
@@ -1,4 +1,4 @@
1import { CONFIG, REMOTE_SCHEME } from '../../initializers' 1import { REMOTE_SCHEME, WEBSERVER } from '../../initializers'
2import { sanitizeHost } from '../core-utils' 2import { sanitizeHost } from '../core-utils'
3import { exists } from './misc' 3import { exists } from './misc'
4 4
@@ -11,7 +11,7 @@ function isWebfingerLocalResourceValid (value: string) {
11 if (actorParts.length !== 2) return false 11 if (actorParts.length !== 2) return false
12 12
13 const host = actorParts[1] 13 const host = actorParts[1]
14 return sanitizeHost(host, REMOTE_SCHEME.HTTP) === CONFIG.WEBSERVER.HOST 14 return sanitizeHost(host, REMOTE_SCHEME.HTTP) === WEBSERVER.HOST
15} 15}
16 16
17// --------------------------------------------------------------------------- 17// ---------------------------------------------------------------------------
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts
index fef2da313..2b574ab8e 100644
--- a/server/helpers/express-utils.ts
+++ b/server/helpers/express-utils.ts
@@ -1,10 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as multer from 'multer' 2import * as multer from 'multer'
3import { CONFIG, REMOTE_SCHEME } from '../initializers' 3import { REMOTE_SCHEME } from '../initializers'
4import { logger } from './logger' 4import { logger } from './logger'
5import { deleteFileAsync, generateRandomString } from './utils' 5import { deleteFileAsync, generateRandomString } from './utils'
6import { extname } from 'path' 6import { extname } from 'path'
7import { isArray } from './custom-validators/misc' 7import { isArray } from './custom-validators/misc'
8import { CONFIG } from '../initializers/config'
8 9
9function buildNSFWFilter (res?: express.Response, paramNSFW?: string) { 10function buildNSFWFilter (res?: express.Response, paramNSFW?: string) {
10 if (paramNSFW === 'true') return true 11 if (paramNSFW === 'true') return true
@@ -58,7 +59,7 @@ function getHostWithPort (host: string) {
58 return host 59 return host
59} 60}
60 61
61function badRequest (req: express.Request, res: express.Response, next: express.NextFunction) { 62function badRequest (req: express.Request, res: express.Response) {
62 return res.type('json').status(400).end() 63 return res.type('json').status(400).end()
63} 64}
64 65
diff --git a/server/helpers/ffmpeg-utils.ts b/server/helpers/ffmpeg-utils.ts
index c477e2e89..d818c459c 100644
--- a/server/helpers/ffmpeg-utils.ts
+++ b/server/helpers/ffmpeg-utils.ts
@@ -1,11 +1,12 @@
1import * as ffmpeg from 'fluent-ffmpeg' 1import * as ffmpeg from 'fluent-ffmpeg'
2import { dirname, join } from 'path' 2import { dirname, join } from 'path'
3import { getTargetBitrate, VideoResolution } from '../../shared/models/videos' 3import { getTargetBitrate, VideoResolution } from '../../shared/models/videos'
4import { CONFIG, FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers/constants' 4import { FFMPEG_NICE, VIDEO_TRANSCODING_FPS } from '../initializers/constants'
5import { processImage } from './image-utils' 5import { processImage } from './image-utils'
6import { logger } from './logger' 6import { logger } from './logger'
7import { checkFFmpegEncoders } from '../initializers/checker-before-init' 7import { checkFFmpegEncoders } from '../initializers/checker-before-init'
8import { remove, readFile, writeFile } from 'fs-extra' 8import { readFile, remove, writeFile } from 'fs-extra'
9import { CONFIG } from '../initializers/config'
9 10
10function computeResolutionsToTranscode (videoFileHeight: number) { 11function computeResolutionsToTranscode (videoFileHeight: number) {
11 const resolutionsEnabled: number[] = [] 12 const resolutionsEnabled: number[] = []
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts
index f8a142718..734523b01 100644
--- a/server/helpers/logger.ts
+++ b/server/helpers/logger.ts
@@ -2,7 +2,7 @@
2import { mkdirpSync } from 'fs-extra' 2import { mkdirpSync } from 'fs-extra'
3import * as path from 'path' 3import * as path from 'path'
4import * as winston from 'winston' 4import * as winston from 'winston'
5import { CONFIG } from '../initializers' 5import { CONFIG } from '../initializers/config'
6import { omit } from 'lodash' 6import { omit } from 'lodash'
7 7
8const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT 8const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts
index 3762e4d3c..02854b164 100644
--- a/server/helpers/requests.ts
+++ b/server/helpers/requests.ts
@@ -1,10 +1,11 @@
1import * as Bluebird from 'bluebird' 1import * as Bluebird from 'bluebird'
2import { createWriteStream, remove } from 'fs-extra' 2import { createWriteStream, remove } from 'fs-extra'
3import * as request from 'request' 3import * as request from 'request'
4import { ACTIVITY_PUB, CONFIG } from '../initializers' 4import { ACTIVITY_PUB } from '../initializers'
5import { processImage } from './image-utils' 5import { processImage } from './image-utils'
6import { join } from 'path' 6import { join } from 'path'
7import { logger } from './logger' 7import { logger } from './logger'
8import { CONFIG } from '../initializers/config'
8 9
9function doRequest <T> ( 10function doRequest <T> (
10 requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean }, 11 requestOptions: request.CoreOptions & request.UriOptions & { activityPub?: boolean },
diff --git a/server/helpers/signup.ts b/server/helpers/signup.ts
index cdce7989d..5eb56b3cf 100644
--- a/server/helpers/signup.ts
+++ b/server/helpers/signup.ts
@@ -1,6 +1,7 @@
1import { CONFIG } from '../initializers'
2import { UserModel } from '../models/account/user' 1import { UserModel } from '../models/account/user'
3import * as ipaddr from 'ipaddr.js' 2import * as ipaddr from 'ipaddr.js'
3import { CONFIG } from '../initializers/config'
4
4const isCidr = require('is-cidr') 5const isCidr = require('is-cidr')
5 6
6async function isSignupAllowed () { 7async function isSignupAllowed () {
diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts
index cb0e823c5..94ceb15e0 100644
--- a/server/helpers/utils.ts
+++ b/server/helpers/utils.ts
@@ -1,5 +1,4 @@
1import { ResultList } from '../../shared' 1import { ResultList } from '../../shared'
2import { CONFIG } from '../initializers'
3import { ApplicationModel } from '../models/application/application' 2import { ApplicationModel } from '../models/application/application'
4import { execPromise, execPromise2, pseudoRandomBytesPromise, sha256 } from './core-utils' 3import { execPromise, execPromise2, pseudoRandomBytesPromise, sha256 } from './core-utils'
5import { logger } from './logger' 4import { logger } from './logger'
@@ -7,6 +6,7 @@ import { join } from 'path'
7import { Instance as ParseTorrent } from 'parse-torrent' 6import { Instance as ParseTorrent } from 'parse-torrent'
8import { remove } from 'fs-extra' 7import { remove } from 'fs-extra'
9import * as memoizee from 'memoizee' 8import * as memoizee from 'memoizee'
9import { CONFIG } from '../initializers/config'
10 10
11function deleteFileAsync (path: string) { 11function deleteFileAsync (path: string) {
12 remove(path) 12 remove(path)
diff --git a/server/helpers/webfinger.ts b/server/helpers/webfinger.ts
index 156376943..049808846 100644
--- a/server/helpers/webfinger.ts
+++ b/server/helpers/webfinger.ts
@@ -3,7 +3,7 @@ import { WebFingerData } from '../../shared'
3import { ActorModel } from '../models/activitypub/actor' 3import { ActorModel } from '../models/activitypub/actor'
4import { isTestInstance } from './core-utils' 4import { isTestInstance } from './core-utils'
5import { isActivityPubUrlValid } from './custom-validators/activitypub/misc' 5import { isActivityPubUrlValid } from './custom-validators/activitypub/misc'
6import { CONFIG } from '../initializers' 6import { WEBSERVER } from '../initializers/constants'
7 7
8const webfinger = new WebFinger({ 8const webfinger = new WebFinger({
9 webfist_fallback: false, 9 webfist_fallback: false,
@@ -19,7 +19,7 @@ async function loadActorUrlOrGetFromWebfinger (uriArg: string) {
19 const [ name, host ] = uri.split('@') 19 const [ name, host ] = uri.split('@')
20 let actor: ActorModel 20 let actor: ActorModel
21 21
22 if (host === CONFIG.WEBSERVER.HOST) { 22 if (host === WEBSERVER.HOST) {
23 actor = await ActorModel.loadLocalByName(name) 23 actor = await ActorModel.loadLocalByName(name)
24 } else { 24 } else {
25 actor = await ActorModel.loadByNameAndHost(name, host) 25 actor = await ActorModel.loadByNameAndHost(name, host)
diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts
index 3c9a0b96a..14dfe0d28 100644
--- a/server/helpers/webtorrent.ts
+++ b/server/helpers/webtorrent.ts
@@ -2,7 +2,7 @@ import { logger } from './logger'
2import { generateVideoImportTmpPath } from './utils' 2import { generateVideoImportTmpPath } from './utils'
3import * as WebTorrent from 'webtorrent' 3import * as WebTorrent from 'webtorrent'
4import { createWriteStream, ensureDir, remove } from 'fs-extra' 4import { createWriteStream, ensureDir, remove } from 'fs-extra'
5import { CONFIG } from '../initializers' 5import { CONFIG } from '../initializers/config'
6import { dirname, join } from 'path' 6import { dirname, join } from 'path'
7 7
8async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: string }, timeout: number) { 8async function downloadWebTorrentVideo (target: { magnetUri: string, torrentName?: string }, timeout: number) {
diff --git a/server/initializers/checker-after-init.ts b/server/initializers/checker-after-init.ts
index 85f752284..db3115085 100644
--- a/server/initializers/checker-after-init.ts
+++ b/server/initializers/checker-after-init.ts
@@ -4,19 +4,20 @@ import { UserModel } from '../models/account/user'
4import { ApplicationModel } from '../models/application/application' 4import { ApplicationModel } from '../models/application/application'
5import { OAuthClientModel } from '../models/oauth/oauth-client' 5import { OAuthClientModel } from '../models/oauth/oauth-client'
6import { parse } from 'url' 6import { parse } from 'url'
7import { CONFIG } from './constants' 7import { CONFIG } from './config'
8import { logger } from '../helpers/logger' 8import { logger } from '../helpers/logger'
9import { getServerActor } from '../helpers/utils' 9import { getServerActor } from '../helpers/utils'
10import { RecentlyAddedStrategy } from '../../shared/models/redundancy' 10import { RecentlyAddedStrategy } from '../../shared/models/redundancy'
11import { isArray } from '../helpers/custom-validators/misc' 11import { isArray } from '../helpers/custom-validators/misc'
12import { uniq } from 'lodash' 12import { uniq } from 'lodash'
13import { Emailer } from '../lib/emailer' 13import { Emailer } from '../lib/emailer'
14import { WEBSERVER } from './constants'
14 15
15async function checkActivityPubUrls () { 16async function checkActivityPubUrls () {
16 const actor = await getServerActor() 17 const actor = await getServerActor()
17 18
18 const parsed = parse(actor.url) 19 const parsed = parse(actor.url)
19 if (CONFIG.WEBSERVER.HOST !== parsed.host) { 20 if (WEBSERVER.HOST !== parsed.host) {
20 const NODE_ENV = config.util.getEnv('NODE_ENV') 21 const NODE_ENV = config.util.getEnv('NODE_ENV')
21 const NODE_CONFIG_DIR = config.util.getEnv('NODE_CONFIG_DIR') 22 const NODE_CONFIG_DIR = config.util.getEnv('NODE_CONFIG_DIR')
22 23
diff --git a/server/initializers/config.ts b/server/initializers/config.ts
new file mode 100644
index 000000000..8dd62cba8
--- /dev/null
+++ b/server/initializers/config.ts
@@ -0,0 +1,255 @@
1import { IConfig } from 'config'
2import { dirname, join } from 'path'
3import { VideosRedundancy } from '../../shared/models'
4// Do not use barrels, remain constants as independent as possible
5import { buildPath, parseBytes, parseDuration, root } from '../helpers/core-utils'
6import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
7import * as bytes from 'bytes'
8
9// Use a variable to reload the configuration if we need
10let config: IConfig = require('config')
11
12const configChangedHandlers: Function[] = []
13
14const CONFIG = {
15 CUSTOM_FILE: getLocalConfigFilePath(),
16 LISTEN: {
17 PORT: config.get<number>('listen.port'),
18 HOSTNAME: config.get<string>('listen.hostname')
19 },
20 DATABASE: {
21 DBNAME: 'peertube' + config.get<string>('database.suffix'),
22 HOSTNAME: config.get<string>('database.hostname'),
23 PORT: config.get<number>('database.port'),
24 USERNAME: config.get<string>('database.username'),
25 PASSWORD: config.get<string>('database.password'),
26 POOL: {
27 MAX: config.get<number>('database.pool.max')
28 }
29 },
30 REDIS: {
31 HOSTNAME: config.has('redis.hostname') ? config.get<string>('redis.hostname') : null,
32 PORT: config.has('redis.port') ? config.get<number>('redis.port') : null,
33 SOCKET: config.has('redis.socket') ? config.get<string>('redis.socket') : null,
34 AUTH: config.has('redis.auth') ? config.get<string>('redis.auth') : null,
35 DB: config.has('redis.db') ? config.get<number>('redis.db') : null
36 },
37 SMTP: {
38 HOSTNAME: config.get<string>('smtp.hostname'),
39 PORT: config.get<number>('smtp.port'),
40 USERNAME: config.get<string>('smtp.username'),
41 PASSWORD: config.get<string>('smtp.password'),
42 TLS: config.get<boolean>('smtp.tls'),
43 DISABLE_STARTTLS: config.get<boolean>('smtp.disable_starttls'),
44 CA_FILE: config.get<string>('smtp.ca_file'),
45 FROM_ADDRESS: config.get<string>('smtp.from_address')
46 },
47 STORAGE: {
48 TMP_DIR: buildPath(config.get<string>('storage.tmp')),
49 AVATARS_DIR: buildPath(config.get<string>('storage.avatars')),
50 LOG_DIR: buildPath(config.get<string>('storage.logs')),
51 VIDEOS_DIR: buildPath(config.get<string>('storage.videos')),
52 STREAMING_PLAYLISTS_DIR: buildPath(config.get<string>('storage.streaming_playlists')),
53 REDUNDANCY_DIR: buildPath(config.get<string>('storage.redundancy')),
54 THUMBNAILS_DIR: buildPath(config.get<string>('storage.thumbnails')),
55 PREVIEWS_DIR: buildPath(config.get<string>('storage.previews')),
56 CAPTIONS_DIR: buildPath(config.get<string>('storage.captions')),
57 TORRENTS_DIR: buildPath(config.get<string>('storage.torrents')),
58 CACHE_DIR: buildPath(config.get<string>('storage.cache'))
59 },
60 WEBSERVER: {
61 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
62 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
63 HOSTNAME: config.get<string>('webserver.hostname'),
64 PORT: config.get<number>('webserver.port')
65 },
66 TRUST_PROXY: config.get<string[]>('trust_proxy'),
67 LOG: {
68 LEVEL: config.get<string>('log.level')
69 },
70 SEARCH: {
71 REMOTE_URI: {
72 USERS: config.get<boolean>('search.remote_uri.users'),
73 ANONYMOUS: config.get<boolean>('search.remote_uri.anonymous')
74 }
75 },
76 TRENDING: {
77 VIDEOS: {
78 INTERVAL_DAYS: config.get<number>('trending.videos.interval_days')
79 }
80 },
81 REDUNDANCY: {
82 VIDEOS: {
83 CHECK_INTERVAL: parseDuration(config.get<string>('redundancy.videos.check_interval')),
84 STRATEGIES: buildVideosRedundancy(config.get<any[]>('redundancy.videos.strategies'))
85 }
86 },
87 CSP: {
88 ENABLED: config.get<boolean>('csp.enabled'),
89 REPORT_ONLY: config.get<boolean>('csp.report_only'),
90 REPORT_URI: config.get<boolean>('csp.report_uri')
91 },
92 TRACKER: {
93 ENABLED: config.get<boolean>('tracker.enabled'),
94 PRIVATE: config.get<boolean>('tracker.private'),
95 REJECT_TOO_MANY_ANNOUNCES: config.get<boolean>('tracker.reject_too_many_announces')
96 },
97 ADMIN: {
98 get EMAIL () { return config.get<string>('admin.email') }
99 },
100 CONTACT_FORM: {
101 get ENABLED () { return config.get<boolean>('contact_form.enabled') }
102 },
103 SIGNUP: {
104 get ENABLED () { return config.get<boolean>('signup.enabled') },
105 get LIMIT () { return config.get<number>('signup.limit') },
106 get REQUIRES_EMAIL_VERIFICATION () { return config.get<boolean>('signup.requires_email_verification') },
107 FILTERS: {
108 CIDR: {
109 get WHITELIST () { return config.get<string[]>('signup.filters.cidr.whitelist') },
110 get BLACKLIST () { return config.get<string[]>('signup.filters.cidr.blacklist') }
111 }
112 }
113 },
114 USER: {
115 get VIDEO_QUOTA () { return parseBytes(config.get<number>('user.video_quota')) },
116 get VIDEO_QUOTA_DAILY () { return parseBytes(config.get<number>('user.video_quota_daily')) }
117 },
118 TRANSCODING: {
119 get ENABLED () { return config.get<boolean>('transcoding.enabled') },
120 get ALLOW_ADDITIONAL_EXTENSIONS () { return config.get<boolean>('transcoding.allow_additional_extensions') },
121 get THREADS () { return config.get<number>('transcoding.threads') },
122 RESOLUTIONS: {
123 get '240p' () { return config.get<boolean>('transcoding.resolutions.240p') },
124 get '360p' () { return config.get<boolean>('transcoding.resolutions.360p') },
125 get '480p' () { return config.get<boolean>('transcoding.resolutions.480p') },
126 get '720p' () { return config.get<boolean>('transcoding.resolutions.720p') },
127 get '1080p' () { return config.get<boolean>('transcoding.resolutions.1080p') }
128 },
129 HLS: {
130 get ENABLED () { return config.get<boolean>('transcoding.hls.enabled') }
131 }
132 },
133 IMPORT: {
134 VIDEOS: {
135 HTTP: {
136 get ENABLED () { return config.get<boolean>('import.videos.http.enabled') }
137 },
138 TORRENT: {
139 get ENABLED () { return config.get<boolean>('import.videos.torrent.enabled') }
140 }
141 }
142 },
143 AUTO_BLACKLIST: {
144 VIDEOS: {
145 OF_USERS: {
146 get ENABLED () { return config.get<boolean>('auto_blacklist.videos.of_users.enabled') }
147 }
148 }
149 },
150 CACHE: {
151 PREVIEWS: {
152 get SIZE () { return config.get<number>('cache.previews.size') }
153 },
154 VIDEO_CAPTIONS: {
155 get SIZE () { return config.get<number>('cache.captions.size') }
156 }
157 },
158 INSTANCE: {
159 get NAME () { return config.get<string>('instance.name') },
160 get SHORT_DESCRIPTION () { return config.get<string>('instance.short_description') },
161 get DESCRIPTION () { return config.get<string>('instance.description') },
162 get TERMS () { return config.get<string>('instance.terms') },
163 get IS_NSFW () { return config.get<boolean>('instance.is_nsfw') },
164 get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') },
165 get DEFAULT_NSFW_POLICY () { return config.get<NSFWPolicyType>('instance.default_nsfw_policy') },
166 CUSTOMIZATIONS: {
167 get JAVASCRIPT () { return config.get<string>('instance.customizations.javascript') },
168 get CSS () { return config.get<string>('instance.customizations.css') }
169 },
170 get ROBOTS () { return config.get<string>('instance.robots') },
171 get SECURITYTXT () { return config.get<string>('instance.securitytxt') },
172 get SECURITYTXT_CONTACT () { return config.get<string>('admin.email') }
173 },
174 SERVICES: {
175 TWITTER: {
176 get USERNAME () { return config.get<string>('services.twitter.username') },
177 get WHITELISTED () { return config.get<boolean>('services.twitter.whitelisted') }
178 }
179 },
180 FOLLOWERS: {
181 INSTANCE: {
182 get ENABLED () { return config.get<boolean>('followers.instance.enabled') },
183 get MANUAL_APPROVAL () { return config.get<boolean>('followers.instance.manual_approval') }
184 }
185 }
186}
187
188function registerConfigChangedHandler (fun: Function) {
189 configChangedHandlers.push(fun)
190}
191
192// ---------------------------------------------------------------------------
193
194export {
195 CONFIG,
196 registerConfigChangedHandler
197}
198
199// ---------------------------------------------------------------------------
200
201function getLocalConfigFilePath () {
202 const configSources = config.util.getConfigSources()
203 if (configSources.length === 0) throw new Error('Invalid config source.')
204
205 let filename = 'local'
206 if (process.env.NODE_ENV) filename += `-${process.env.NODE_ENV}`
207 if (process.env.NODE_APP_INSTANCE) filename += `-${process.env.NODE_APP_INSTANCE}`
208
209 return join(dirname(configSources[ 0 ].name), filename + '.json')
210}
211
212function buildVideosRedundancy (objs: any[]): VideosRedundancy[] {
213 if (!objs) return []
214
215 if (!Array.isArray(objs)) return objs
216
217 return objs.map(obj => {
218 return Object.assign({}, obj, {
219 minLifetime: parseDuration(obj.min_lifetime),
220 size: bytes.parse(obj.size),
221 minViews: obj.min_views
222 })
223 })
224}
225
226export function reloadConfig () {
227
228 function directory () {
229 if (process.env.NODE_CONFIG_DIR) {
230 return process.env.NODE_CONFIG_DIR
231 }
232
233 return join(root(), 'config')
234 }
235
236 function purge () {
237 for (const fileName in require.cache) {
238 if (-1 === fileName.indexOf(directory())) {
239 continue
240 }
241
242 delete require.cache[fileName]
243 }
244
245 delete require.cache[require.resolve('config')]
246 }
247
248 purge()
249
250 config = require('config')
251
252 for (const configChangedHandler of configChangedHandlers) {
253 configChangedHandler()
254 }
255}
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts
index 739ea5502..3922d8515 100644
--- a/server/initializers/constants.ts
+++ b/server/initializers/constants.ts
@@ -1,20 +1,16 @@
1import { IConfig } from 'config' 1import { join } from 'path'
2import { dirname, join } from 'path' 2import { JobType, VideoRateType, VideoState } from '../../shared/models'
3import { JobType, VideoRateType, VideoState, VideosRedundancy } from '../../shared/models'
4import { ActivityPubActorType } from '../../shared/models/activitypub' 3import { ActivityPubActorType } from '../../shared/models/activitypub'
5import { FollowState } from '../../shared/models/actors' 4import { FollowState } from '../../shared/models/actors'
6import { VideoAbuseState, VideoImportState, VideoPrivacy, VideoTranscodingFPS } from '../../shared/models/videos' 5import { VideoAbuseState, VideoImportState, VideoPrivacy, VideoTranscodingFPS } from '../../shared/models/videos'
7// Do not use barrels, remain constants as independent as possible 6// Do not use barrels, remain constants as independent as possible
8import { buildPath, isTestInstance, parseDuration, parseBytes, root, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' 7import { isTestInstance, sanitizeHost, sanitizeUrl } from '../helpers/core-utils'
9import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' 8import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type'
10import { invert } from 'lodash' 9import { invert } from 'lodash'
11import { CronRepeatOptions, EveryRepeatOptions } from 'bull' 10import { CronRepeatOptions, EveryRepeatOptions } from 'bull'
12import * as bytes from 'bytes'
13import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model' 11import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model'
14import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model' 12import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model'
15 13import { CONFIG, registerConfigChangedHandler } from './config'
16// Use a variable to reload the configuration if we need
17let config: IConfig = require('config')
18 14
19// --------------------------------------------------------------------------- 15// ---------------------------------------------------------------------------
20 16
@@ -32,6 +28,15 @@ const PAGINATION = {
32 } 28 }
33} 29}
34 30
31const WEBSERVER = {
32 URL: '',
33 HOST: '',
34 SCHEME: '',
35 WS: '',
36 HOSTNAME: '',
37 PORT: 0
38}
39
35// Sortable columns per schema 40// Sortable columns per schema
36const SORTABLE_COLUMNS = { 41const SORTABLE_COLUMNS = {
37 USERS: [ 'id', 'username', 'createdAt' ], 42 USERS: [ 'id', 'username', 'createdAt' ],
@@ -102,7 +107,7 @@ const REMOTE_SCHEME = {
102} 107}
103 108
104// TODO: remove 'video-file' 109// TODO: remove 'video-file'
105const JOB_ATTEMPTS: { [ id in (JobType | 'video-file') ]: number } = { 110const JOB_ATTEMPTS: { [id in (JobType | 'video-file')]: number } = {
106 'activitypub-http-broadcast': 5, 111 'activitypub-http-broadcast': 5,
107 'activitypub-http-unicast': 5, 112 'activitypub-http-unicast': 5,
108 'activitypub-http-fetcher': 5, 113 'activitypub-http-fetcher': 5,
@@ -115,7 +120,7 @@ const JOB_ATTEMPTS: { [ id in (JobType | 'video-file') ]: number } = {
115 'videos-views': 1, 120 'videos-views': 1,
116 'activitypub-refresher': 1 121 'activitypub-refresher': 1
117} 122}
118const JOB_CONCURRENCY: { [ id in (JobType | 'video-file') ]: number } = { 123const JOB_CONCURRENCY: { [id in (JobType | 'video-file')]: number } = {
119 'activitypub-http-broadcast': 1, 124 'activitypub-http-broadcast': 1,
120 'activitypub-http-unicast': 5, 125 'activitypub-http-unicast': 5,
121 'activitypub-http-fetcher': 1, 126 'activitypub-http-fetcher': 1,
@@ -128,7 +133,7 @@ const JOB_CONCURRENCY: { [ id in (JobType | 'video-file') ]: number } = {
128 'videos-views': 1, 133 'videos-views': 1,
129 'activitypub-refresher': 1 134 'activitypub-refresher': 1
130} 135}
131const JOB_TTL: { [ id in (JobType | 'video-file') ]: number } = { 136const JOB_TTL: { [id in (JobType | 'video-file')]: number } = {
132 'activitypub-http-broadcast': 60000 * 10, // 10 minutes 137 'activitypub-http-broadcast': 60000 * 10, // 10 minutes
133 'activitypub-http-unicast': 60000 * 10, // 10 minutes 138 'activitypub-http-unicast': 60000 * 10, // 10 minutes
134 'activitypub-http-fetcher': 60000 * 10, // 10 minutes 139 'activitypub-http-fetcher': 60000 * 10, // 10 minutes
@@ -163,184 +168,6 @@ let SCHEDULER_INTERVALS_MS = {
163 168
164// --------------------------------------------------------------------------- 169// ---------------------------------------------------------------------------
165 170
166const CONFIG = {
167 CUSTOM_FILE: getLocalConfigFilePath(),
168 LISTEN: {
169 PORT: config.get<number>('listen.port'),
170 HOSTNAME: config.get<string>('listen.hostname')
171 },
172 DATABASE: {
173 DBNAME: 'peertube' + config.get<string>('database.suffix'),
174 HOSTNAME: config.get<string>('database.hostname'),
175 PORT: config.get<number>('database.port'),
176 USERNAME: config.get<string>('database.username'),
177 PASSWORD: config.get<string>('database.password'),
178 POOL: {
179 MAX: config.get<number>('database.pool.max')
180 }
181 },
182 REDIS: {
183 HOSTNAME: config.has('redis.hostname') ? config.get<string>('redis.hostname') : null,
184 PORT: config.has('redis.port') ? config.get<number>('redis.port') : null,
185 SOCKET: config.has('redis.socket') ? config.get<string>('redis.socket') : null,
186 AUTH: config.has('redis.auth') ? config.get<string>('redis.auth') : null,
187 DB: config.has('redis.db') ? config.get<number>('redis.db') : null
188 },
189 SMTP: {
190 HOSTNAME: config.get<string>('smtp.hostname'),
191 PORT: config.get<number>('smtp.port'),
192 USERNAME: config.get<string>('smtp.username'),
193 PASSWORD: config.get<string>('smtp.password'),
194 TLS: config.get<boolean>('smtp.tls'),
195 DISABLE_STARTTLS: config.get<boolean>('smtp.disable_starttls'),
196 CA_FILE: config.get<string>('smtp.ca_file'),
197 FROM_ADDRESS: config.get<string>('smtp.from_address')
198 },
199 STORAGE: {
200 TMP_DIR: buildPath(config.get<string>('storage.tmp')),
201 AVATARS_DIR: buildPath(config.get<string>('storage.avatars')),
202 LOG_DIR: buildPath(config.get<string>('storage.logs')),
203 VIDEOS_DIR: buildPath(config.get<string>('storage.videos')),
204 STREAMING_PLAYLISTS_DIR: buildPath(config.get<string>('storage.streaming_playlists')),
205 REDUNDANCY_DIR: buildPath(config.get<string>('storage.redundancy')),
206 THUMBNAILS_DIR: buildPath(config.get<string>('storage.thumbnails')),
207 PREVIEWS_DIR: buildPath(config.get<string>('storage.previews')),
208 CAPTIONS_DIR: buildPath(config.get<string>('storage.captions')),
209 TORRENTS_DIR: buildPath(config.get<string>('storage.torrents')),
210 CACHE_DIR: buildPath(config.get<string>('storage.cache'))
211 },
212 WEBSERVER: {
213 SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
214 WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',
215 HOSTNAME: config.get<string>('webserver.hostname'),
216 PORT: config.get<number>('webserver.port'),
217 URL: '',
218 HOST: ''
219 },
220 TRUST_PROXY: config.get<string[]>('trust_proxy'),
221 LOG: {
222 LEVEL: config.get<string>('log.level')
223 },
224 SEARCH: {
225 REMOTE_URI: {
226 USERS: config.get<boolean>('search.remote_uri.users'),
227 ANONYMOUS: config.get<boolean>('search.remote_uri.anonymous')
228 }
229 },
230 TRENDING: {
231 VIDEOS: {
232 INTERVAL_DAYS: config.get<number>('trending.videos.interval_days')
233 }
234 },
235 REDUNDANCY: {
236 VIDEOS: {
237 CHECK_INTERVAL: parseDuration(config.get<string>('redundancy.videos.check_interval')),
238 STRATEGIES: buildVideosRedundancy(config.get<any[]>('redundancy.videos.strategies'))
239 }
240 },
241 CSP: {
242 ENABLED: config.get<boolean>('csp.enabled'),
243 REPORT_ONLY: config.get<boolean>('csp.report_only'),
244 REPORT_URI: config.get<boolean>('csp.report_uri')
245 },
246 TRACKER: {
247 ENABLED: config.get<boolean>('tracker.enabled'),
248 PRIVATE: config.get<boolean>('tracker.private'),
249 REJECT_TOO_MANY_ANNOUNCES: config.get<boolean>('tracker.reject_too_many_announces')
250 },
251 ADMIN: {
252 get EMAIL () { return config.get<string>('admin.email') }
253 },
254 CONTACT_FORM: {
255 get ENABLED () { return config.get<boolean>('contact_form.enabled') }
256 },
257 SIGNUP: {
258 get ENABLED () { return config.get<boolean>('signup.enabled') },
259 get LIMIT () { return config.get<number>('signup.limit') },
260 get REQUIRES_EMAIL_VERIFICATION () { return config.get<boolean>('signup.requires_email_verification') },
261 FILTERS: {
262 CIDR: {
263 get WHITELIST () { return config.get<string[]>('signup.filters.cidr.whitelist') },
264 get BLACKLIST () { return config.get<string[]>('signup.filters.cidr.blacklist') }
265 }
266 }
267 },
268 USER: {
269 get VIDEO_QUOTA () { return parseBytes(config.get<number>('user.video_quota')) },
270 get VIDEO_QUOTA_DAILY () { return parseBytes(config.get<number>('user.video_quota_daily')) }
271 },
272 TRANSCODING: {
273 get ENABLED () { return config.get<boolean>('transcoding.enabled') },
274 get ALLOW_ADDITIONAL_EXTENSIONS () { return config.get<boolean>('transcoding.allow_additional_extensions') },
275 get THREADS () { return config.get<number>('transcoding.threads') },
276 RESOLUTIONS: {
277 get '240p' () { return config.get<boolean>('transcoding.resolutions.240p') },
278 get '360p' () { return config.get<boolean>('transcoding.resolutions.360p') },
279 get '480p' () { return config.get<boolean>('transcoding.resolutions.480p') },
280 get '720p' () { return config.get<boolean>('transcoding.resolutions.720p') },
281 get '1080p' () { return config.get<boolean>('transcoding.resolutions.1080p') }
282 },
283 HLS: {
284 get ENABLED () { return config.get<boolean>('transcoding.hls.enabled') }
285 }
286 },
287 IMPORT: {
288 VIDEOS: {
289 HTTP: {
290 get ENABLED () { return config.get<boolean>('import.videos.http.enabled') }
291 },
292 TORRENT: {
293 get ENABLED () { return config.get<boolean>('import.videos.torrent.enabled') }
294 }
295 }
296 },
297 AUTO_BLACKLIST: {
298 VIDEOS: {
299 OF_USERS: {
300 get ENABLED () { return config.get<boolean>('auto_blacklist.videos.of_users.enabled') }
301 }
302 }
303 },
304 CACHE: {
305 PREVIEWS: {
306 get SIZE () { return config.get<number>('cache.previews.size') }
307 },
308 VIDEO_CAPTIONS: {
309 get SIZE () { return config.get<number>('cache.captions.size') }
310 }
311 },
312 INSTANCE: {
313 get NAME () { return config.get<string>('instance.name') },
314 get SHORT_DESCRIPTION () { return config.get<string>('instance.short_description') },
315 get DESCRIPTION () { return config.get<string>('instance.description') },
316 get TERMS () { return config.get<string>('instance.terms') },
317 get IS_NSFW () { return config.get<boolean>('instance.is_nsfw') },
318 get DEFAULT_CLIENT_ROUTE () { return config.get<string>('instance.default_client_route') },
319 get DEFAULT_NSFW_POLICY () { return config.get<NSFWPolicyType>('instance.default_nsfw_policy') },
320 CUSTOMIZATIONS: {
321 get JAVASCRIPT () { return config.get<string>('instance.customizations.javascript') },
322 get CSS () { return config.get<string>('instance.customizations.css') }
323 },
324 get ROBOTS () { return config.get<string>('instance.robots') },
325 get SECURITYTXT () { return config.get<string>('instance.securitytxt') },
326 get SECURITYTXT_CONTACT () { return config.get<string>('admin.email') }
327 },
328 SERVICES: {
329 TWITTER: {
330 get USERNAME () { return config.get<string>('services.twitter.username') },
331 get WHITELISTED () { return config.get<boolean>('services.twitter.whitelisted') }
332 }
333 },
334 FOLLOWERS: {
335 INSTANCE: {
336 get ENABLED () { return config.get<boolean>('followers.instance.enabled') },
337 get MANUAL_APPROVAL () { return config.get<boolean>('followers.instance.manual_approval') }
338 }
339 }
340}
341
342// ---------------------------------------------------------------------------
343
344let CONSTRAINTS_FIELDS = { 171let CONSTRAINTS_FIELDS = {
345 USERS: { 172 USERS: {
346 NAME: { min: 1, max: 120 }, // Length 173 NAME: { min: 1, max: 120 }, // Length
@@ -517,38 +344,38 @@ const VIDEO_LICENCES = {
517const VIDEO_LANGUAGES = buildLanguages() 344const VIDEO_LANGUAGES = buildLanguages()
518 345
519const VIDEO_PRIVACIES = { 346const VIDEO_PRIVACIES = {
520 [VideoPrivacy.PUBLIC]: 'Public', 347 [ VideoPrivacy.PUBLIC ]: 'Public',
521 [VideoPrivacy.UNLISTED]: 'Unlisted', 348 [ VideoPrivacy.UNLISTED ]: 'Unlisted',
522 [VideoPrivacy.PRIVATE]: 'Private' 349 [ VideoPrivacy.PRIVATE ]: 'Private'
523} 350}
524 351
525const VIDEO_STATES = { 352const VIDEO_STATES = {
526 [VideoState.PUBLISHED]: 'Published', 353 [ VideoState.PUBLISHED ]: 'Published',
527 [VideoState.TO_TRANSCODE]: 'To transcode', 354 [ VideoState.TO_TRANSCODE ]: 'To transcode',
528 [VideoState.TO_IMPORT]: 'To import' 355 [ VideoState.TO_IMPORT ]: 'To import'
529} 356}
530 357
531const VIDEO_IMPORT_STATES = { 358const VIDEO_IMPORT_STATES = {
532 [VideoImportState.FAILED]: 'Failed', 359 [ VideoImportState.FAILED ]: 'Failed',
533 [VideoImportState.PENDING]: 'Pending', 360 [ VideoImportState.PENDING ]: 'Pending',
534 [VideoImportState.SUCCESS]: 'Success' 361 [ VideoImportState.SUCCESS ]: 'Success'
535} 362}
536 363
537const VIDEO_ABUSE_STATES = { 364const VIDEO_ABUSE_STATES = {
538 [VideoAbuseState.PENDING]: 'Pending', 365 [ VideoAbuseState.PENDING ]: 'Pending',
539 [VideoAbuseState.REJECTED]: 'Rejected', 366 [ VideoAbuseState.REJECTED ]: 'Rejected',
540 [VideoAbuseState.ACCEPTED]: 'Accepted' 367 [ VideoAbuseState.ACCEPTED ]: 'Accepted'
541} 368}
542 369
543const VIDEO_PLAYLIST_PRIVACIES = { 370const VIDEO_PLAYLIST_PRIVACIES = {
544 [VideoPlaylistPrivacy.PUBLIC]: 'Public', 371 [ VideoPlaylistPrivacy.PUBLIC ]: 'Public',
545 [VideoPlaylistPrivacy.UNLISTED]: 'Unlisted', 372 [ VideoPlaylistPrivacy.UNLISTED ]: 'Unlisted',
546 [VideoPlaylistPrivacy.PRIVATE]: 'Private' 373 [ VideoPlaylistPrivacy.PRIVATE ]: 'Private'
547} 374}
548 375
549const VIDEO_PLAYLIST_TYPES = { 376const VIDEO_PLAYLIST_TYPES = {
550 [VideoPlaylistType.REGULAR]: 'Regular', 377 [ VideoPlaylistType.REGULAR ]: 'Regular',
551 [VideoPlaylistType.WATCH_LATER]: 'Watch later' 378 [ VideoPlaylistType.WATCH_LATER ]: 'Watch later'
552} 379}
553 380
554const MIMETYPES = { 381const MIMETYPES = {
@@ -634,7 +461,7 @@ const USER_PASSWORD_RESET_LIFETIME = 60000 * 5 // 5 minutes
634 461
635const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes 462const USER_EMAIL_VERIFY_LIFETIME = 60000 * 60 // 60 minutes
636 463
637const NSFW_POLICY_TYPES: { [ id: string]: NSFWPolicyType } = { 464const NSFW_POLICY_TYPES: { [ id: string ]: NSFWPolicyType } = {
638 DO_NOT_LIST: 'do_not_list', 465 DO_NOT_LIST: 'do_not_list',
639 BLUR: 'blur', 466 BLUR: 'blur',
640 DISPLAY: 'display' 467 DISPLAY: 'display'
@@ -765,14 +592,14 @@ if (isTestInstance() === true) {
765 SCHEDULER_INTERVALS_MS.actorFollowScores = 1000 592 SCHEDULER_INTERVALS_MS.actorFollowScores = 1000
766 SCHEDULER_INTERVALS_MS.removeOldJobs = 10000 593 SCHEDULER_INTERVALS_MS.removeOldJobs = 10000
767 SCHEDULER_INTERVALS_MS.updateVideos = 5000 594 SCHEDULER_INTERVALS_MS.updateVideos = 5000
768 REPEAT_JOBS['videos-views'] = { every: 5000 } 595 REPEAT_JOBS[ 'videos-views' ] = { every: 5000 }
769 596
770 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1 597 REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1
771 598
772 VIDEO_VIEW_LIFETIME = 1000 // 1 second 599 VIDEO_VIEW_LIFETIME = 1000 // 1 second
773 CONTACT_FORM_LIFETIME = 1000 // 1 second 600 CONTACT_FORM_LIFETIME = 1000 // 1 second
774 601
775 JOB_ATTEMPTS['email'] = 1 602 JOB_ATTEMPTS[ 'email' ] = 1
776 603
777 FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000 604 FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000
778 MEMOIZE_TTL.OVERVIEWS_SAMPLE = 1 605 MEMOIZE_TTL.OVERVIEWS_SAMPLE = 1
@@ -783,9 +610,15 @@ if (isTestInstance() === true) {
783 610
784updateWebserverUrls() 611updateWebserverUrls()
785 612
613registerConfigChangedHandler(() => {
614 updateWebserverUrls()
615 updateWebserverConfig()
616})
617
786// --------------------------------------------------------------------------- 618// ---------------------------------------------------------------------------
787 619
788export { 620export {
621 WEBSERVER,
789 API_VERSION, 622 API_VERSION,
790 HLS_REDUNDANCY_DIRECTORY, 623 HLS_REDUNDANCY_DIRECTORY,
791 P2P_MEDIA_LOADER_PEER_VERSION, 624 P2P_MEDIA_LOADER_PEER_VERSION,
@@ -794,7 +627,6 @@ export {
794 BCRYPT_SALT_SIZE, 627 BCRYPT_SALT_SIZE,
795 TRACKER_RATE_LIMITS, 628 TRACKER_RATE_LIMITS,
796 FILES_CACHE, 629 FILES_CACHE,
797 CONFIG,
798 CONSTRAINTS_FIELDS, 630 CONSTRAINTS_FIELDS,
799 EMBED_SIZE, 631 EMBED_SIZE,
800 REDUNDANCY, 632 REDUNDANCY,
@@ -857,17 +689,6 @@ export {
857 689
858// --------------------------------------------------------------------------- 690// ---------------------------------------------------------------------------
859 691
860function getLocalConfigFilePath () {
861 const configSources = config.util.getConfigSources()
862 if (configSources.length === 0) throw new Error('Invalid config source.')
863
864 let filename = 'local'
865 if (process.env.NODE_ENV) filename += `-${process.env.NODE_ENV}`
866 if (process.env.NODE_APP_INSTANCE) filename += `-${process.env.NODE_APP_INSTANCE}`
867
868 return join(dirname(configSources[ 0 ].name), filename + '.json')
869}
870
871function buildVideoMimetypeExt () { 692function buildVideoMimetypeExt () {
872 const data = { 693 const data = {
873 'video/webm': '.webm', 694 'video/webm': '.webm',
@@ -890,8 +711,12 @@ function buildVideoMimetypeExt () {
890} 711}
891 712
892function updateWebserverUrls () { 713function updateWebserverUrls () {
893 CONFIG.WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT) 714 WEBSERVER.URL = sanitizeUrl(CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT)
894 CONFIG.WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP) 715 WEBSERVER.HOST = sanitizeHost(CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT, REMOTE_SCHEME.HTTP)
716 WEBSERVER.SCHEME = CONFIG.WEBSERVER.SCHEME
717 WEBSERVER.WS = CONFIG.WEBSERVER.WS
718 WEBSERVER.HOSTNAME = CONFIG.WEBSERVER.HOSTNAME
719 WEBSERVER.PORT = CONFIG.WEBSERVER.PORT
895} 720}
896 721
897function updateWebserverConfig () { 722function updateWebserverConfig () {
@@ -907,20 +732,6 @@ function buildVideosExtname () {
907 : [ '.mp4', '.ogv', '.webm' ] 732 : [ '.mp4', '.ogv', '.webm' ]
908} 733}
909 734
910function buildVideosRedundancy (objs: any[]): VideosRedundancy[] {
911 if (!objs) return []
912
913 if (!Array.isArray(objs)) return objs
914
915 return objs.map(obj => {
916 return Object.assign({}, obj, {
917 minLifetime: parseDuration(obj.min_lifetime),
918 size: bytes.parse(obj.size),
919 minViews: obj.min_views
920 })
921 })
922}
923
924function buildLanguages () { 735function buildLanguages () {
925 const iso639 = require('iso-639-3') 736 const iso639 = require('iso-639-3')
926 737
@@ -953,42 +764,12 @@ function buildLanguages () {
953 iso639 764 iso639
954 .filter(l => { 765 .filter(l => {
955 return (l.iso6391 !== null && l.type === 'living') || 766 return (l.iso6391 !== null && l.type === 'living') ||
956 additionalLanguages[l.iso6393] === true 767 additionalLanguages[ l.iso6393 ] === true
957 }) 768 })
958 .forEach(l => languages[l.iso6391 || l.iso6393] = l.name) 769 .forEach(l => languages[ l.iso6391 || l.iso6393 ] = l.name)
959 770
960 // Override Occitan label 771 // Override Occitan label
961 languages['oc'] = 'Occitan' 772 languages[ 'oc' ] = 'Occitan'
962 773
963 return languages 774 return languages
964} 775}
965
966export function reloadConfig () {
967
968 function directory () {
969 if (process.env.NODE_CONFIG_DIR) {
970 return process.env.NODE_CONFIG_DIR
971 }
972
973 return join(root(), 'config')
974 }
975
976 function purge () {
977 for (const fileName in require.cache) {
978 if (-1 === fileName.indexOf(directory())) {
979 continue
980 }
981
982 delete require.cache[fileName]
983 }
984
985 delete require.cache[require.resolve('config')]
986 }
987
988 purge()
989
990 config = require('config')
991
992 updateWebserverConfig()
993 updateWebserverUrls()
994}
diff --git a/server/initializers/database.ts b/server/initializers/database.ts
index 541ebbecf..872a56220 100644
--- a/server/initializers/database.ts
+++ b/server/initializers/database.ts
@@ -21,7 +21,7 @@ import { VideoCommentModel } from '../models/video/video-comment'
21import { VideoFileModel } from '../models/video/video-file' 21import { VideoFileModel } from '../models/video/video-file'
22import { VideoShareModel } from '../models/video/video-share' 22import { VideoShareModel } from '../models/video/video-share'
23import { VideoTagModel } from '../models/video/video-tag' 23import { VideoTagModel } from '../models/video/video-tag'
24import { CONFIG } from './constants' 24import { CONFIG } from './config'
25import { ScheduleVideoUpdateModel } from '../models/video/schedule-video-update' 25import { ScheduleVideoUpdateModel } from '../models/video/schedule-video-update'
26import { VideoCaptionModel } from '../models/video/video-caption' 26import { VideoCaptionModel } from '../models/video/video-caption'
27import { VideoImportModel } from '../models/video/video-import' 27import { VideoImportModel } from '../models/video/video-import'
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts
index 07af96b68..127449577 100644
--- a/server/initializers/installer.ts
+++ b/server/initializers/installer.ts
@@ -6,9 +6,10 @@ import { UserModel } from '../models/account/user'
6import { ApplicationModel } from '../models/application/application' 6import { ApplicationModel } from '../models/application/application'
7import { OAuthClientModel } from '../models/oauth/oauth-client' 7import { OAuthClientModel } from '../models/oauth/oauth-client'
8import { applicationExist, clientsExist, usersExist } from './checker-after-init' 8import { applicationExist, clientsExist, usersExist } from './checker-after-init'
9import { FILES_CACHE, CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY, LAST_MIGRATION_VERSION } from './constants' 9import { FILES_CACHE, HLS_STREAMING_PLAYLIST_DIRECTORY, LAST_MIGRATION_VERSION } from './constants'
10import { sequelizeTypescript } from './database' 10import { sequelizeTypescript } from './database'
11import { remove, ensureDir } from 'fs-extra' 11import { ensureDir, remove } from 'fs-extra'
12import { CONFIG } from './config'
12 13
13async function installApplication () { 14async function installApplication () {
14 try { 15 try {
diff --git a/server/initializers/migrations/0075-video-resolutions.ts b/server/initializers/migrations/0075-video-resolutions.ts
index 26a188e5e..e4f26cb77 100644
--- a/server/initializers/migrations/0075-video-resolutions.ts
+++ b/server/initializers/migrations/0075-video-resolutions.ts
@@ -1,6 +1,6 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { join } from 'path' 2import { join } from 'path'
3import { CONFIG } from '../../initializers/constants' 3import { CONFIG } from '../../initializers/config'
4import { getVideoFileResolution } from '../../helpers/ffmpeg-utils' 4import { getVideoFileResolution } from '../../helpers/ffmpeg-utils'
5import { readdir, rename } from 'fs-extra' 5import { readdir, rename } from 'fs-extra'
6 6
diff --git a/server/initializers/migrations/0140-actor-url.ts b/server/initializers/migrations/0140-actor-url.ts
index e64ee3487..020499391 100644
--- a/server/initializers/migrations/0140-actor-url.ts
+++ b/server/initializers/migrations/0140-actor-url.ts
@@ -1,13 +1,13 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { CONFIG } from '../constants' 2import { WEBSERVER } from '../constants'
3 3
4async function up (utils: { 4async function up (utils: {
5 transaction: Sequelize.Transaction, 5 transaction: Sequelize.Transaction,
6 queryInterface: Sequelize.QueryInterface, 6 queryInterface: Sequelize.QueryInterface,
7 sequelize: Sequelize.Sequelize 7 sequelize: Sequelize.Sequelize
8}): Promise<void> { 8}): Promise<void> {
9 const toReplace = CONFIG.WEBSERVER.HOSTNAME + ':443' 9 const toReplace = WEBSERVER.HOSTNAME + ':443'
10 const by = CONFIG.WEBSERVER.HOST 10 const by = WEBSERVER.HOST
11 const replacer = column => `replace("${column}", '${toReplace}', '${by}')` 11 const replacer = column => `replace("${column}", '${toReplace}', '${by}')`
12 12
13 { 13 {
diff --git a/server/initializers/migrations/0235-delete-some-video-indexes.ts b/server/initializers/migrations/0235-delete-some-video-indexes.ts
index e362f240c..5964b0dc5 100644
--- a/server/initializers/migrations/0235-delete-some-video-indexes.ts
+++ b/server/initializers/migrations/0235-delete-some-video-indexes.ts
@@ -1,8 +1,4 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { createClient } from 'redis'
3import { CONFIG } from '../constants'
4import { JobQueue } from '../../lib/job-queue'
5import { initDatabaseModels } from '../database'
6 2
7async function up (utils: { 3async function up (utils: {
8 transaction: Sequelize.Transaction 4 transaction: Sequelize.Transaction
diff --git a/server/initializers/migrations/0240-drop-old-indexes.ts b/server/initializers/migrations/0240-drop-old-indexes.ts
index ba961e3f9..39868fa2d 100644
--- a/server/initializers/migrations/0240-drop-old-indexes.ts
+++ b/server/initializers/migrations/0240-drop-old-indexes.ts
@@ -1,8 +1,4 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { createClient } from 'redis'
3import { CONFIG } from '../constants'
4import { JobQueue } from '../../lib/job-queue'
5import { initDatabaseModels } from '../database'
6 2
7async function up (utils: { 3async function up (utils: {
8 transaction: Sequelize.Transaction 4 transaction: Sequelize.Transaction
diff --git a/server/initializers/migrations/0345-video-playlists.ts b/server/initializers/migrations/0345-video-playlists.ts
index 11670b11d..6953f5553 100644
--- a/server/initializers/migrations/0345-video-playlists.ts
+++ b/server/initializers/migrations/0345-video-playlists.ts
@@ -1,7 +1,7 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { CONFIG } from '../constants'
3import { VideoPlaylistPrivacy, VideoPlaylistType } from '../../../shared/models/videos' 2import { VideoPlaylistPrivacy, VideoPlaylistType } from '../../../shared/models/videos'
4import * as uuidv4 from 'uuid/v4' 3import * as uuidv4 from 'uuid/v4'
4import { WEBSERVER } from '../constants'
5 5
6async function up (utils: { 6async function up (utils: {
7 transaction: Sequelize.Transaction, 7 transaction: Sequelize.Transaction,
@@ -57,7 +57,7 @@ CREATE TABLE IF NOT EXISTS "videoPlaylistElement"
57 for (const username of usernames) { 57 for (const username of usernames) {
58 const uuid = uuidv4() 58 const uuid = uuidv4()
59 59
60 const baseUrl = CONFIG.WEBSERVER.URL + '/video-playlists/' + uuid 60 const baseUrl = WEBSERVER.URL + '/video-playlists/' + uuid
61 const query = ` 61 const query = `
62 INSERT INTO "videoPlaylist" ("url", "uuid", "name", "privacy", "type", "ownerAccountId", "createdAt", "updatedAt") 62 INSERT INTO "videoPlaylist" ("url", "uuid", "name", "privacy", "type", "ownerAccountId", "createdAt", "updatedAt")
63 SELECT '${baseUrl}' AS "url", 63 SELECT '${baseUrl}' AS "url",
diff --git a/server/lib/activitypub/actor.ts b/server/lib/activitypub/actor.ts
index c0ad07a52..cfefc26ce 100644
--- a/server/lib/activitypub/actor.ts
+++ b/server/lib/activitypub/actor.ts
@@ -12,7 +12,7 @@ import { logger } from '../../helpers/logger'
12import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto' 12import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto'
13import { doRequest, downloadImage } from '../../helpers/requests' 13import { doRequest, downloadImage } from '../../helpers/requests'
14import { getUrlFromWebfinger } from '../../helpers/webfinger' 14import { getUrlFromWebfinger } from '../../helpers/webfinger'
15import { AVATARS_SIZE, CONFIG, MIMETYPES, sequelizeTypescript } from '../../initializers' 15import { AVATARS_SIZE, MIMETYPES, sequelizeTypescript, WEBSERVER } from '../../initializers'
16import { AccountModel } from '../../models/account/account' 16import { AccountModel } from '../../models/account/account'
17import { ActorModel } from '../../models/activitypub/actor' 17import { ActorModel } from '../../models/activitypub/actor'
18import { AvatarModel } from '../../models/avatar/avatar' 18import { AvatarModel } from '../../models/avatar/avatar'
@@ -21,6 +21,7 @@ import { VideoChannelModel } from '../../models/video/video-channel'
21import { JobQueue } from '../job-queue' 21import { JobQueue } from '../job-queue'
22import { getServerActor } from '../../helpers/utils' 22import { getServerActor } from '../../helpers/utils'
23import { ActorFetchByUrlType, fetchActorByUrl } from '../../helpers/actor' 23import { ActorFetchByUrlType, fetchActorByUrl } from '../../helpers/actor'
24import { CONFIG } from '../../initializers/config'
24 25
25// Set account keys, this could be long so process after the account creation and do not block the client 26// Set account keys, this could be long so process after the account creation and do not block the client
26function setAsyncActorKeys (actor: ActorModel) { 27function setAsyncActorKeys (actor: ActorModel) {
@@ -116,7 +117,7 @@ function buildActorInstance (type: ActivityPubActorType, url: string, preferredU
116 followingCount: 0, 117 followingCount: 0,
117 inboxUrl: url + '/inbox', 118 inboxUrl: url + '/inbox',
118 outboxUrl: url + '/outbox', 119 outboxUrl: url + '/outbox',
119 sharedInboxUrl: CONFIG.WEBSERVER.URL + '/inbox', 120 sharedInboxUrl: WEBSERVER.URL + '/inbox',
120 followersUrl: url + '/followers', 121 followersUrl: url + '/followers',
121 followingUrl: url + '/following' 122 followingUrl: url + '/following'
122 }) 123 })
diff --git a/server/lib/activitypub/playlist.ts b/server/lib/activitypub/playlist.ts
index c4a8f12ec..a0d0e736e 100644
--- a/server/lib/activitypub/playlist.ts
+++ b/server/lib/activitypub/playlist.ts
@@ -1,6 +1,6 @@
1import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' 1import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object'
2import { crawlCollectionPage } from './crawl' 2import { crawlCollectionPage } from './crawl'
3import { ACTIVITY_PUB, CONFIG, CRAWL_REQUEST_CONCURRENCY, sequelizeTypescript, THUMBNAILS_SIZE } from '../../initializers' 3import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY, sequelizeTypescript, THUMBNAILS_SIZE } from '../../initializers'
4import { AccountModel } from '../../models/account/account' 4import { AccountModel } from '../../models/account/account'
5import { isArray } from '../../helpers/custom-validators/misc' 5import { isArray } from '../../helpers/custom-validators/misc'
6import { getOrCreateActorAndServerAndModel } from './actor' 6import { getOrCreateActorAndServerAndModel } from './actor'
@@ -17,6 +17,7 @@ import { VideoModel } from '../../models/video/video'
17import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model' 17import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model'
18import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' 18import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
19import { ActivityIconObject } from '../../../shared/models/activitypub/objects' 19import { ActivityIconObject } from '../../../shared/models/activitypub/objects'
20import { CONFIG } from '../../initializers/config'
20 21
21function playlistObjectToDBAttributes (playlistObject: PlaylistObject, byAccount: AccountModel, to: string[]) { 22function playlistObjectToDBAttributes (playlistObject: PlaylistObject, byAccount: AccountModel, to: string[]) {
22 const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPlaylistPrivacy.PUBLIC : VideoPlaylistPrivacy.UNLISTED 23 const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPlaylistPrivacy.PUBLIC : VideoPlaylistPrivacy.UNLISTED
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts
index 276a57e60..ac3dd6ac4 100644
--- a/server/lib/activitypub/process/process-follow.ts
+++ b/server/lib/activitypub/process/process-follow.ts
@@ -1,13 +1,14 @@
1import { ActivityFollow } from '../../../../shared/models/activitypub' 1import { ActivityFollow } from '../../../../shared/models/activitypub'
2import { retryTransactionWrapper } from '../../../helpers/database-utils' 2import { retryTransactionWrapper } from '../../../helpers/database-utils'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { sequelizeTypescript, CONFIG } from '../../../initializers' 4import { sequelizeTypescript } from '../../../initializers'
5import { ActorModel } from '../../../models/activitypub/actor' 5import { ActorModel } from '../../../models/activitypub/actor'
6import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 6import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
7import { sendAccept, sendReject } from '../send' 7import { sendAccept, sendReject } from '../send'
8import { Notifier } from '../../notifier' 8import { Notifier } from '../../notifier'
9import { getAPId } from '../../../helpers/activitypub' 9import { getAPId } from '../../../helpers/activitypub'
10import { getServerActor } from '../../../helpers/utils' 10import { getServerActor } from '../../../helpers/utils'
11import { CONFIG } from '../../../initializers/config'
11 12
12async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) { 13async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) {
13 const activityObject = getAPId(activity.object) 14 const activityObject = getAPId(activity.object)
diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts
index 401b83fc2..01950a13b 100644
--- a/server/lib/activitypub/url.ts
+++ b/server/lib/activitypub/url.ts
@@ -1,4 +1,4 @@
1import { CONFIG } from '../../initializers' 1import { WEBSERVER } from '../../initializers'
2import { ActorModel } from '../../models/activitypub/actor' 2import { ActorModel } from '../../models/activitypub/actor'
3import { ActorFollowModel } from '../../models/activitypub/actor-follow' 3import { ActorFollowModel } from '../../models/activitypub/actor-follow'
4import { VideoModel } from '../../models/video/video' 4import { VideoModel } from '../../models/video/video'
@@ -9,41 +9,41 @@ import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-
9import { VideoPlaylistModel } from '../../models/video/video-playlist' 9import { VideoPlaylistModel } from '../../models/video/video-playlist'
10 10
11function getVideoActivityPubUrl (video: VideoModel) { 11function getVideoActivityPubUrl (video: VideoModel) {
12 return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid 12 return WEBSERVER.URL + '/videos/watch/' + video.uuid
13} 13}
14 14
15function getVideoPlaylistActivityPubUrl (videoPlaylist: VideoPlaylistModel) { 15function getVideoPlaylistActivityPubUrl (videoPlaylist: VideoPlaylistModel) {
16 return CONFIG.WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid 16 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid
17} 17}
18 18
19function getVideoPlaylistElementActivityPubUrl (videoPlaylist: VideoPlaylistModel, video: VideoModel) { 19function getVideoPlaylistElementActivityPubUrl (videoPlaylist: VideoPlaylistModel, video: VideoModel) {
20 return CONFIG.WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/' + video.uuid 20 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/' + video.uuid
21} 21}
22 22
23function getVideoCacheFileActivityPubUrl (videoFile: VideoFileModel) { 23function getVideoCacheFileActivityPubUrl (videoFile: VideoFileModel) {
24 const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : '' 24 const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : ''
25 25
26 return `${CONFIG.WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}` 26 return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}`
27} 27}
28 28
29function getVideoCacheStreamingPlaylistActivityPubUrl (video: VideoModel, playlist: VideoStreamingPlaylistModel) { 29function getVideoCacheStreamingPlaylistActivityPubUrl (video: VideoModel, playlist: VideoStreamingPlaylistModel) {
30 return `${CONFIG.WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}` 30 return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}`
31} 31}
32 32
33function getVideoCommentActivityPubUrl (video: VideoModel, videoComment: VideoCommentModel) { 33function getVideoCommentActivityPubUrl (video: VideoModel, videoComment: VideoCommentModel) {
34 return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id 34 return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
35} 35}
36 36
37function getVideoChannelActivityPubUrl (videoChannelName: string) { 37function getVideoChannelActivityPubUrl (videoChannelName: string) {
38 return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannelName 38 return WEBSERVER.URL + '/video-channels/' + videoChannelName
39} 39}
40 40
41function getAccountActivityPubUrl (accountName: string) { 41function getAccountActivityPubUrl (accountName: string) {
42 return CONFIG.WEBSERVER.URL + '/accounts/' + accountName 42 return WEBSERVER.URL + '/accounts/' + accountName
43} 43}
44 44
45function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseModel) { 45function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseModel) {
46 return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id 46 return WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id
47} 47}
48 48
49function getVideoViewActivityPubUrl (byActor: ActorModel, video: VideoModel) { 49function getVideoViewActivityPubUrl (byActor: ActorModel, video: VideoModel) {
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts
index caff0621e..191f4817b 100644
--- a/server/lib/activitypub/videos.ts
+++ b/server/lib/activitypub/videos.ts
@@ -19,7 +19,6 @@ import { logger } from '../../helpers/logger'
19import { doRequest, downloadImage } from '../../helpers/requests' 19import { doRequest, downloadImage } from '../../helpers/requests'
20import { 20import {
21 ACTIVITY_PUB, 21 ACTIVITY_PUB,
22 CONFIG,
23 MIMETYPES, 22 MIMETYPES,
24 P2P_MEDIA_LOADER_PEER_VERSION, 23 P2P_MEDIA_LOADER_PEER_VERSION,
25 REMOTE_SCHEME, 24 REMOTE_SCHEME,
@@ -51,6 +50,7 @@ import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model'
51import { AccountVideoRateModel } from '../../models/account/account-video-rate' 50import { AccountVideoRateModel } from '../../models/account/account-video-rate'
52import { VideoShareModel } from '../../models/video/video-share' 51import { VideoShareModel } from '../../models/video/video-share'
53import { VideoCommentModel } from '../../models/video/video-comment' 52import { VideoCommentModel } from '../../models/video/video-comment'
53import { CONFIG } from '../../initializers/config'
54 54
55async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) { 55async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) {
56 // If the video is not private and is published, we federate it 56 // If the video is not private and is published, we federate it
diff --git a/server/lib/avatar.ts b/server/lib/avatar.ts
index 021426a1a..a5316df4b 100644
--- a/server/lib/avatar.ts
+++ b/server/lib/avatar.ts
@@ -1,6 +1,6 @@
1import 'multer' 1import 'multer'
2import { sendUpdateActor } from './activitypub/send' 2import { sendUpdateActor } from './activitypub/send'
3import { AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../initializers' 3import { AVATARS_SIZE, sequelizeTypescript } from '../initializers'
4import { updateActorAvatarInstance } from './activitypub' 4import { updateActorAvatarInstance } from './activitypub'
5import { processImage } from '../helpers/image-utils' 5import { processImage } from '../helpers/image-utils'
6import { AccountModel } from '../models/account/account' 6import { AccountModel } from '../models/account/account'
@@ -8,6 +8,7 @@ import { VideoChannelModel } from '../models/video/video-channel'
8import { extname, join } from 'path' 8import { extname, join } from 'path'
9import { retryTransactionWrapper } from '../helpers/database-utils' 9import { retryTransactionWrapper } from '../helpers/database-utils'
10import * as uuidv4 from 'uuid/v4' 10import * as uuidv4 from 'uuid/v4'
11import { CONFIG } from '../initializers/config'
11 12
12async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) { 13async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) {
13 const extension = extname(avatarPhysicalFile.filename) 14 const extension = extname(avatarPhysicalFile.filename)
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts
index 217f6a437..f8e1e456f 100644
--- a/server/lib/client-html.ts
+++ b/server/lib/client-html.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/models/i18n/i18n' 2import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/models/i18n/i18n'
3import { CONFIG, CUSTOM_HTML_TAG_COMMENTS, EMBED_SIZE } from '../initializers' 3import { CUSTOM_HTML_TAG_COMMENTS, EMBED_SIZE, WEBSERVER } from '../initializers'
4import { join } from 'path' 4import { join } from 'path'
5import { escapeHTML } from '../helpers/core-utils' 5import { escapeHTML } from '../helpers/core-utils'
6import { VideoModel } from '../models/video/video' 6import { VideoModel } from '../models/video/video'
@@ -11,6 +11,7 @@ import { getActivityStreamDuration } from '../models/video/video-format-utils'
11import { AccountModel } from '../models/account/account' 11import { AccountModel } from '../models/account/account'
12import { VideoChannelModel } from '../models/video/video-channel' 12import { VideoChannelModel } from '../models/video/video-channel'
13import * as Bluebird from 'bluebird' 13import * as Bluebird from 'bluebird'
14import { CONFIG } from '../initializers/config'
14 15
15export class ClientHtml { 16export class ClientHtml {
16 17
@@ -106,7 +107,7 @@ export class ClientHtml {
106 107
107 // Save locale in cookies 108 // Save locale in cookies
108 res.cookie('clientLanguage', lang, { 109 res.cookie('clientLanguage', lang, {
109 secure: CONFIG.WEBSERVER.SCHEME === 'https', 110 secure: WEBSERVER.SCHEME === 'https',
110 sameSite: true, 111 sameSite: true,
111 maxAge: 1000 * 3600 * 24 * 90 // 3 months 112 maxAge: 1000 * 3600 * 24 * 90 // 3 months
112 }) 113 })
@@ -143,12 +144,12 @@ export class ClientHtml {
143 } 144 }
144 145
145 private static addVideoOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoModel) { 146 private static addVideoOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoModel) {
146 const previewUrl = CONFIG.WEBSERVER.URL + video.getPreviewStaticPath() 147 const previewUrl = WEBSERVER.URL + video.getPreviewStaticPath()
147 const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() 148 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
148 149
149 const videoNameEscaped = escapeHTML(video.name) 150 const videoNameEscaped = escapeHTML(video.name)
150 const videoDescriptionEscaped = escapeHTML(video.description) 151 const videoDescriptionEscaped = escapeHTML(video.description)
151 const embedUrl = CONFIG.WEBSERVER.URL + video.getEmbedStaticPath() 152 const embedUrl = WEBSERVER.URL + video.getEmbedStaticPath()
152 153
153 const openGraphMetaTags = { 154 const openGraphMetaTags = {
154 'og:type': 'video', 155 'og:type': 'video',
@@ -180,7 +181,7 @@ export class ClientHtml {
180 const oembedLinkTags = [ 181 const oembedLinkTags = [
181 { 182 {
182 type: 'application/json+oembed', 183 type: 'application/json+oembed',
183 href: CONFIG.WEBSERVER.URL + '/services/oembed?url=' + encodeURIComponent(videoUrl), 184 href: WEBSERVER.URL + '/services/oembed?url=' + encodeURIComponent(videoUrl),
184 title: videoNameEscaped 185 title: videoNameEscaped
185 } 186 }
186 ] 187 ]
diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts
index aa9083362..8c06e9751 100644
--- a/server/lib/emailer.ts
+++ b/server/lib/emailer.ts
@@ -1,7 +1,7 @@
1import { createTransport, Transporter } from 'nodemailer' 1import { createTransport, Transporter } from 'nodemailer'
2import { isTestInstance } from '../helpers/core-utils' 2import { isTestInstance } from '../helpers/core-utils'
3import { bunyanLogger, logger } from '../helpers/logger' 3import { bunyanLogger, logger } from '../helpers/logger'
4import { CONFIG } from '../initializers' 4import { CONFIG } from '../initializers/config'
5import { UserModel } from '../models/account/user' 5import { UserModel } from '../models/account/user'
6import { VideoModel } from '../models/video/video' 6import { VideoModel } from '../models/video/video'
7import { JobQueue } from './job-queue' 7import { JobQueue } from './job-queue'
@@ -12,6 +12,7 @@ import { VideoAbuseModel } from '../models/video/video-abuse'
12import { VideoBlacklistModel } from '../models/video/video-blacklist' 12import { VideoBlacklistModel } from '../models/video/video-blacklist'
13import { VideoImportModel } from '../models/video/video-import' 13import { VideoImportModel } from '../models/video/video-import'
14import { ActorFollowModel } from '../models/activitypub/actor-follow' 14import { ActorFollowModel } from '../models/activitypub/actor-follow'
15import { WEBSERVER } from '../initializers/constants'
15 16
16type SendEmailOptions = { 17type SendEmailOptions = {
17 to: string[] 18 to: string[]
@@ -91,7 +92,7 @@ class Emailer {
91 92
92 addNewVideoFromSubscriberNotification (to: string[], video: VideoModel) { 93 addNewVideoFromSubscriberNotification (to: string[], video: VideoModel) {
93 const channelName = video.VideoChannel.getDisplayName() 94 const channelName = video.VideoChannel.getDisplayName()
94 const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() 95 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
95 96
96 const text = `Hi dear user,\n\n` + 97 const text = `Hi dear user,\n\n` +
97 `Your subscription ${channelName} just published a new video: ${video.name}` + 98 `Your subscription ${channelName} just published a new video: ${video.name}` +
@@ -148,7 +149,7 @@ class Emailer {
148 } 149 }
149 150
150 myVideoPublishedNotification (to: string[], video: VideoModel) { 151 myVideoPublishedNotification (to: string[], video: VideoModel) {
151 const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() 152 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
152 153
153 const text = `Hi dear user,\n\n` + 154 const text = `Hi dear user,\n\n` +
154 `Your video ${video.name} has been published.` + 155 `Your video ${video.name} has been published.` +
@@ -168,7 +169,7 @@ class Emailer {
168 } 169 }
169 170
170 myVideoImportSuccessNotification (to: string[], videoImport: VideoImportModel) { 171 myVideoImportSuccessNotification (to: string[], videoImport: VideoImportModel) {
171 const videoUrl = CONFIG.WEBSERVER.URL + videoImport.Video.getWatchStaticPath() 172 const videoUrl = WEBSERVER.URL + videoImport.Video.getWatchStaticPath()
172 173
173 const text = `Hi dear user,\n\n` + 174 const text = `Hi dear user,\n\n` +
174 `Your video import ${videoImport.getTargetIdentifier()} is finished.` + 175 `Your video import ${videoImport.getTargetIdentifier()} is finished.` +
@@ -188,7 +189,7 @@ class Emailer {
188 } 189 }
189 190
190 myVideoImportErrorNotification (to: string[], videoImport: VideoImportModel) { 191 myVideoImportErrorNotification (to: string[], videoImport: VideoImportModel) {
191 const importUrl = CONFIG.WEBSERVER.URL + '/my-account/video-imports' 192 const importUrl = WEBSERVER.URL + '/my-account/video-imports'
192 193
193 const text = `Hi dear user,\n\n` + 194 const text = `Hi dear user,\n\n` +
194 `Your video import ${videoImport.getTargetIdentifier()} encountered an error.` + 195 `Your video import ${videoImport.getTargetIdentifier()} encountered an error.` +
@@ -210,7 +211,7 @@ class Emailer {
210 addNewCommentOnMyVideoNotification (to: string[], comment: VideoCommentModel) { 211 addNewCommentOnMyVideoNotification (to: string[], comment: VideoCommentModel) {
211 const accountName = comment.Account.getDisplayName() 212 const accountName = comment.Account.getDisplayName()
212 const video = comment.Video 213 const video = comment.Video
213 const commentUrl = CONFIG.WEBSERVER.URL + comment.getCommentStaticPath() 214 const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath()
214 215
215 const text = `Hi dear user,\n\n` + 216 const text = `Hi dear user,\n\n` +
216 `A new comment has been posted by ${accountName} on your video ${video.name}` + 217 `A new comment has been posted by ${accountName} on your video ${video.name}` +
@@ -232,7 +233,7 @@ class Emailer {
232 addNewCommentMentionNotification (to: string[], comment: VideoCommentModel) { 233 addNewCommentMentionNotification (to: string[], comment: VideoCommentModel) {
233 const accountName = comment.Account.getDisplayName() 234 const accountName = comment.Account.getDisplayName()
234 const video = comment.Video 235 const video = comment.Video
235 const commentUrl = CONFIG.WEBSERVER.URL + comment.getCommentStaticPath() 236 const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath()
236 237
237 const text = `Hi dear user,\n\n` + 238 const text = `Hi dear user,\n\n` +
238 `${accountName} mentioned you on video ${video.name}` + 239 `${accountName} mentioned you on video ${video.name}` +
@@ -252,10 +253,10 @@ class Emailer {
252 } 253 }
253 254
254 addVideoAbuseModeratorsNotification (to: string[], videoAbuse: VideoAbuseModel) { 255 addVideoAbuseModeratorsNotification (to: string[], videoAbuse: VideoAbuseModel) {
255 const videoUrl = CONFIG.WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath() 256 const videoUrl = WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath()
256 257
257 const text = `Hi,\n\n` + 258 const text = `Hi,\n\n` +
258 `${CONFIG.WEBSERVER.HOST} received an abuse for the following video ${videoUrl}\n\n` + 259 `${WEBSERVER.HOST} received an abuse for the following video ${videoUrl}\n\n` +
259 `Cheers,\n` + 260 `Cheers,\n` +
260 `PeerTube.` 261 `PeerTube.`
261 262
@@ -269,8 +270,8 @@ class Emailer {
269 } 270 }
270 271
271 addVideoAutoBlacklistModeratorsNotification (to: string[], video: VideoModel) { 272 addVideoAutoBlacklistModeratorsNotification (to: string[], video: VideoModel) {
272 const VIDEO_AUTO_BLACKLIST_URL = CONFIG.WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' 273 const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list'
273 const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() 274 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
274 275
275 const text = `Hi,\n\n` + 276 const text = `Hi,\n\n` +
276 `A recently added video was auto-blacklisted and requires moderator review before publishing.` + 277 `A recently added video was auto-blacklisted and requires moderator review before publishing.` +
@@ -293,13 +294,13 @@ class Emailer {
293 294
294 addNewUserRegistrationNotification (to: string[], user: UserModel) { 295 addNewUserRegistrationNotification (to: string[], user: UserModel) {
295 const text = `Hi,\n\n` + 296 const text = `Hi,\n\n` +
296 `User ${user.username} just registered on ${CONFIG.WEBSERVER.HOST} PeerTube instance.\n\n` + 297 `User ${user.username} just registered on ${WEBSERVER.HOST} PeerTube instance.\n\n` +
297 `Cheers,\n` + 298 `Cheers,\n` +
298 `PeerTube.` 299 `PeerTube.`
299 300
300 const emailPayload: EmailPayload = { 301 const emailPayload: EmailPayload = {
301 to, 302 to,
302 subject: '[PeerTube] New user registration on ' + CONFIG.WEBSERVER.HOST, 303 subject: '[PeerTube] New user registration on ' + WEBSERVER.HOST,
303 text 304 text
304 } 305 }
305 306
@@ -308,10 +309,10 @@ class Emailer {
308 309
309 addVideoBlacklistNotification (to: string[], videoBlacklist: VideoBlacklistModel) { 310 addVideoBlacklistNotification (to: string[], videoBlacklist: VideoBlacklistModel) {
310 const videoName = videoBlacklist.Video.name 311 const videoName = videoBlacklist.Video.name
311 const videoUrl = CONFIG.WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() 312 const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath()
312 313
313 const reasonString = videoBlacklist.reason ? ` for the following reason: ${videoBlacklist.reason}` : '' 314 const reasonString = videoBlacklist.reason ? ` for the following reason: ${videoBlacklist.reason}` : ''
314 const blockedString = `Your video ${videoName} (${videoUrl} on ${CONFIG.WEBSERVER.HOST} has been blacklisted${reasonString}.` 315 const blockedString = `Your video ${videoName} (${videoUrl} on ${WEBSERVER.HOST} has been blacklisted${reasonString}.`
315 316
316 const text = 'Hi,\n\n' + 317 const text = 'Hi,\n\n' +
317 blockedString + 318 blockedString +
@@ -329,10 +330,10 @@ class Emailer {
329 } 330 }
330 331
331 addVideoUnblacklistNotification (to: string[], video: VideoModel) { 332 addVideoUnblacklistNotification (to: string[], video: VideoModel) {
332 const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() 333 const videoUrl = WEBSERVER.URL + video.getWatchStaticPath()
333 334
334 const text = 'Hi,\n\n' + 335 const text = 'Hi,\n\n' +
335 `Your video ${video.name} (${videoUrl}) on ${CONFIG.WEBSERVER.HOST} has been unblacklisted.` + 336 `Your video ${video.name} (${videoUrl}) on ${WEBSERVER.HOST} has been unblacklisted.` +
336 '\n\n' + 337 '\n\n' +
337 'Cheers,\n' + 338 'Cheers,\n' +
338 `PeerTube.` 339 `PeerTube.`
@@ -348,7 +349,7 @@ class Emailer {
348 349
349 addPasswordResetEmailJob (to: string, resetPasswordUrl: string) { 350 addPasswordResetEmailJob (to: string, resetPasswordUrl: string) {
350 const text = `Hi dear user,\n\n` + 351 const text = `Hi dear user,\n\n` +
351 `A reset password procedure for your account ${to} has been requested on ${CONFIG.WEBSERVER.HOST} ` + 352 `A reset password procedure for your account ${to} has been requested on ${WEBSERVER.HOST} ` +
352 `Please follow this link to reset it: ${resetPasswordUrl}\n\n` + 353 `Please follow this link to reset it: ${resetPasswordUrl}\n\n` +
353 `If you are not the person who initiated this request, please ignore this email.\n\n` + 354 `If you are not the person who initiated this request, please ignore this email.\n\n` +
354 `Cheers,\n` + 355 `Cheers,\n` +
@@ -365,7 +366,7 @@ class Emailer {
365 366
366 addVerifyEmailJob (to: string, verifyEmailUrl: string) { 367 addVerifyEmailJob (to: string, verifyEmailUrl: string) {
367 const text = `Welcome to PeerTube,\n\n` + 368 const text = `Welcome to PeerTube,\n\n` +
368 `To start using PeerTube on ${CONFIG.WEBSERVER.HOST} you must verify your email! ` + 369 `To start using PeerTube on ${WEBSERVER.HOST} you must verify your email! ` +
369 `Please follow this link to verify this email belongs to you: ${verifyEmailUrl}\n\n` + 370 `Please follow this link to verify this email belongs to you: ${verifyEmailUrl}\n\n` +
370 `If you are not the person who initiated this request, please ignore this email.\n\n` + 371 `If you are not the person who initiated this request, please ignore this email.\n\n` +
371 `Cheers,\n` + 372 `Cheers,\n` +
@@ -383,7 +384,7 @@ class Emailer {
383 addUserBlockJob (user: UserModel, blocked: boolean, reason?: string) { 384 addUserBlockJob (user: UserModel, blocked: boolean, reason?: string) {
384 const reasonString = reason ? ` for the following reason: ${reason}` : '' 385 const reasonString = reason ? ` for the following reason: ${reason}` : ''
385 const blockedWord = blocked ? 'blocked' : 'unblocked' 386 const blockedWord = blocked ? 'blocked' : 'unblocked'
386 const blockedString = `Your account ${user.username} on ${CONFIG.WEBSERVER.HOST} has been ${blockedWord}${reasonString}.` 387 const blockedString = `Your account ${user.username} on ${WEBSERVER.HOST} has been ${blockedWord}${reasonString}.`
387 388
388 const text = 'Hi,\n\n' + 389 const text = 'Hi,\n\n' +
389 blockedString + 390 blockedString +
@@ -428,7 +429,7 @@ class Emailer {
428 429
429 const fromDisplayName = options.fromDisplayName 430 const fromDisplayName = options.fromDisplayName
430 ? options.fromDisplayName 431 ? options.fromDisplayName
431 : CONFIG.WEBSERVER.HOST 432 : WEBSERVER.HOST
432 433
433 return this.transporter.sendMail({ 434 return this.transporter.sendMail({
434 from: `"${fromDisplayName}" <${CONFIG.SMTP.FROM_ADDRESS}>`, 435 from: `"${fromDisplayName}" <${CONFIG.SMTP.FROM_ADDRESS}>`,
diff --git a/server/lib/files-cache/videos-caption-cache.ts b/server/lib/files-cache/videos-caption-cache.ts
index fe5b441af..f5ccfe0a2 100644
--- a/server/lib/files-cache/videos-caption-cache.ts
+++ b/server/lib/files-cache/videos-caption-cache.ts
@@ -1,8 +1,9 @@
1import { join } from 'path' 1import { join } from 'path'
2import { FILES_CACHE, CONFIG } from '../../initializers' 2import { FILES_CACHE } from '../../initializers'
3import { VideoModel } from '../../models/video/video' 3import { VideoModel } from '../../models/video/video'
4import { VideoCaptionModel } from '../../models/video/video-caption' 4import { VideoCaptionModel } from '../../models/video/video-caption'
5import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' 5import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
6import { CONFIG } from '../../initializers/config'
6 7
7type GetPathParam = { videoId: string, language: string } 8type GetPathParam = { videoId: string, language: string }
8 9
diff --git a/server/lib/files-cache/videos-preview-cache.ts b/server/lib/files-cache/videos-preview-cache.ts
index 01cd3647e..192f99aec 100644
--- a/server/lib/files-cache/videos-preview-cache.ts
+++ b/server/lib/files-cache/videos-preview-cache.ts
@@ -1,7 +1,8 @@
1import { join } from 'path' 1import { join } from 'path'
2import { FILES_CACHE, CONFIG, STATIC_PATHS } from '../../initializers' 2import { FILES_CACHE, STATIC_PATHS } from '../../initializers'
3import { VideoModel } from '../../models/video/video' 3import { VideoModel } from '../../models/video/video'
4import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' 4import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache'
5import { CONFIG } from '../../initializers/config'
5 6
6class VideosPreviewCache extends AbstractVideoStaticFileCache <string> { 7class VideosPreviewCache extends AbstractVideoStaticFileCache <string> {
7 8
diff --git a/server/lib/hls.ts b/server/lib/hls.ts
index a9a96dd16..e804e7b3a 100644
--- a/server/lib/hls.ts
+++ b/server/lib/hls.ts
@@ -1,6 +1,6 @@
1import { VideoModel } from '../models/video/video' 1import { VideoModel } from '../models/video/video'
2import { basename, dirname, join } from 'path' 2import { basename, dirname, join } from 'path'
3import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, sequelizeTypescript } from '../initializers' 3import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, sequelizeTypescript } from '../initializers'
4import { close, ensureDir, move, open, outputJSON, pathExists, read, readFile, remove, writeFile } from 'fs-extra' 4import { close, ensureDir, move, open, outputJSON, pathExists, read, readFile, remove, writeFile } from 'fs-extra'
5import { getVideoFileSize } from '../helpers/ffmpeg-utils' 5import { getVideoFileSize } from '../helpers/ffmpeg-utils'
6import { sha256 } from '../helpers/core-utils' 6import { sha256 } from '../helpers/core-utils'
@@ -10,6 +10,7 @@ import { doRequest, doRequestAndSaveToFile } from '../helpers/requests'
10import { generateRandomString } from '../helpers/utils' 10import { generateRandomString } from '../helpers/utils'
11import { flatten, uniq } from 'lodash' 11import { flatten, uniq } from 'lodash'
12import { VideoFileModel } from '../models/video/video-file' 12import { VideoFileModel } from '../models/video/video-file'
13import { CONFIG } from '../initializers/config'
13 14
14async function updateStreamingPlaylistsInfohashesIfNeeded () { 15async function updateStreamingPlaylistsInfohashesIfNeeded () {
15 const playlistsToUpdate = await VideoStreamingPlaylistModel.listByIncorrectPeerVersion() 16 const playlistsToUpdate = await VideoStreamingPlaylistModel.listByIncorrectPeerVersion()
diff --git a/server/lib/job-queue/handlers/activitypub-follow.ts b/server/lib/job-queue/handlers/activitypub-follow.ts
index e7e5ff950..7c84aa937 100644
--- a/server/lib/job-queue/handlers/activitypub-follow.ts
+++ b/server/lib/job-queue/handlers/activitypub-follow.ts
@@ -1,6 +1,6 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import { logger } from '../../../helpers/logger' 2import { logger } from '../../../helpers/logger'
3import { CONFIG, REMOTE_SCHEME, sequelizeTypescript } from '../../../initializers' 3import { REMOTE_SCHEME, sequelizeTypescript, WEBSERVER } from '../../../initializers'
4import { sendFollow } from '../../activitypub/send' 4import { sendFollow } from '../../activitypub/send'
5import { sanitizeHost } from '../../../helpers/core-utils' 5import { sanitizeHost } from '../../../helpers/core-utils'
6import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger' 6import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger'
@@ -23,7 +23,7 @@ async function processActivityPubFollow (job: Bull.Job) {
23 logger.info('Processing ActivityPub follow in job %d.', job.id) 23 logger.info('Processing ActivityPub follow in job %d.', job.id)
24 24
25 let targetActor: ActorModel 25 let targetActor: ActorModel
26 if (!host || host === CONFIG.WEBSERVER.HOST) { 26 if (!host || host === WEBSERVER.HOST) {
27 targetActor = await ActorModel.loadLocalByName(payload.name) 27 targetActor = await ActorModel.loadLocalByName(payload.name)
28 } else { 28 } else {
29 const sanitizedHost = sanitizeHost(host, REMOTE_SCHEME.HTTP) 29 const sanitizedHost = sanitizeHost(host, REMOTE_SCHEME.HTTP)
diff --git a/server/lib/job-queue/handlers/video-import.ts b/server/lib/job-queue/handlers/video-import.ts
index c5fc1061c..732773efd 100644
--- a/server/lib/job-queue/handlers/video-import.ts
+++ b/server/lib/job-queue/handlers/video-import.ts
@@ -6,7 +6,7 @@ import { VideoImportState } from '../../../../shared/models/videos'
6import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' 6import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils'
7import { extname, join } from 'path' 7import { extname, join } from 'path'
8import { VideoFileModel } from '../../../models/video/video-file' 8import { VideoFileModel } from '../../../models/video/video-file'
9import { CONFIG, PREVIEWS_SIZE, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_IMPORT_TIMEOUT } from '../../../initializers' 9import { PREVIEWS_SIZE, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_IMPORT_TIMEOUT } from '../../../initializers'
10import { downloadImage } from '../../../helpers/requests' 10import { downloadImage } from '../../../helpers/requests'
11import { VideoState } from '../../../../shared' 11import { VideoState } from '../../../../shared'
12import { JobQueue } from '../index' 12import { JobQueue } from '../index'
@@ -14,8 +14,9 @@ import { federateVideoIfNeeded } from '../../activitypub'
14import { VideoModel } from '../../../models/video/video' 14import { VideoModel } from '../../../models/video/video'
15import { downloadWebTorrentVideo } from '../../../helpers/webtorrent' 15import { downloadWebTorrentVideo } from '../../../helpers/webtorrent'
16import { getSecureTorrentName } from '../../../helpers/utils' 16import { getSecureTorrentName } from '../../../helpers/utils'
17import { remove, move, stat } from 'fs-extra' 17import { move, remove, stat } from 'fs-extra'
18import { Notifier } from '../../notifier' 18import { Notifier } from '../../notifier'
19import { CONFIG } from '../../../initializers/config'
19 20
20type VideoImportYoutubeDLPayload = { 21type VideoImportYoutubeDLPayload = {
21 type: 'youtube-dl' 22 type: 'youtube-dl'
diff --git a/server/lib/job-queue/handlers/video-transcoding.ts b/server/lib/job-queue/handlers/video-transcoding.ts
index 581ec283e..48cac517e 100644
--- a/server/lib/job-queue/handlers/video-transcoding.ts
+++ b/server/lib/job-queue/handlers/video-transcoding.ts
@@ -5,11 +5,12 @@ import { VideoModel } from '../../../models/video/video'
5import { JobQueue } from '../job-queue' 5import { JobQueue } from '../job-queue'
6import { federateVideoIfNeeded } from '../../activitypub' 6import { federateVideoIfNeeded } from '../../activitypub'
7import { retryTransactionWrapper } from '../../../helpers/database-utils' 7import { retryTransactionWrapper } from '../../../helpers/database-utils'
8import { CONFIG, sequelizeTypescript } from '../../../initializers' 8import { sequelizeTypescript } from '../../../initializers'
9import * as Bluebird from 'bluebird' 9import * as Bluebird from 'bluebird'
10import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils' 10import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils'
11import { generateHlsPlaylist, optimizeVideofile, transcodeOriginalVideofile } from '../../video-transcoding' 11import { generateHlsPlaylist, optimizeVideofile, transcodeOriginalVideofile } from '../../video-transcoding'
12import { Notifier } from '../../notifier' 12import { Notifier } from '../../notifier'
13import { CONFIG } from '../../../initializers/config'
13 14
14export type VideoTranscodingPayload = { 15export type VideoTranscodingPayload = {
15 videoUUID: string 16 videoUUID: string
diff --git a/server/lib/job-queue/job-queue.ts b/server/lib/job-queue/job-queue.ts
index cee0941c7..1c2aa109d 100644
--- a/server/lib/job-queue/job-queue.ts
+++ b/server/lib/job-queue/job-queue.ts
@@ -2,7 +2,7 @@ import * as Bull from 'bull'
2import { JobState, JobType } from '../../../shared/models' 2import { JobState, JobType } from '../../../shared/models'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { Redis } from '../redis' 4import { Redis } from '../redis'
5import { CONFIG, JOB_ATTEMPTS, JOB_COMPLETED_LIFETIME, JOB_CONCURRENCY, JOB_TTL, REPEAT_JOBS } from '../../initializers' 5import { JOB_ATTEMPTS, JOB_COMPLETED_LIFETIME, JOB_CONCURRENCY, JOB_TTL, REPEAT_JOBS, WEBSERVER } from '../../initializers'
6import { ActivitypubHttpBroadcastPayload, processActivityPubHttpBroadcast } from './handlers/activitypub-http-broadcast' 6import { ActivitypubHttpBroadcastPayload, processActivityPubHttpBroadcast } from './handlers/activitypub-http-broadcast'
7import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher' 7import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher'
8import { ActivitypubHttpUnicastPayload, processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast' 8import { ActivitypubHttpUnicastPayload, processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast'
@@ -68,7 +68,7 @@ class JobQueue {
68 if (this.initialized === true) return 68 if (this.initialized === true) return
69 this.initialized = true 69 this.initialized = true
70 70
71 this.jobRedisPrefix = 'bull-' + CONFIG.WEBSERVER.HOST 71 this.jobRedisPrefix = 'bull-' + WEBSERVER.HOST
72 const queueOptions = { 72 const queueOptions = {
73 prefix: this.jobRedisPrefix, 73 prefix: this.jobRedisPrefix,
74 redis: Redis.getRedisClient(), 74 redis: Redis.getRedisClient(),
diff --git a/server/lib/notifier.ts b/server/lib/notifier.ts
index 91b71cc64..c1e63fa8f 100644
--- a/server/lib/notifier.ts
+++ b/server/lib/notifier.ts
@@ -6,7 +6,7 @@ import { UserNotificationModel } from '../models/account/user-notification'
6import { VideoCommentModel } from '../models/video/video-comment' 6import { VideoCommentModel } from '../models/video/video-comment'
7import { UserModel } from '../models/account/user' 7import { UserModel } from '../models/account/user'
8import { PeerTubeSocket } from './peertube-socket' 8import { PeerTubeSocket } from './peertube-socket'
9import { CONFIG } from '../initializers/constants' 9import { CONFIG } from '../initializers/config'
10import { VideoPrivacy, VideoState } from '../../shared/models/videos' 10import { VideoPrivacy, VideoState } from '../../shared/models/videos'
11import { VideoAbuseModel } from '../models/video/video-abuse' 11import { VideoAbuseModel } from '../models/video/video-abuse'
12import { VideoBlacklistModel } from '../models/video/video-blacklist' 12import { VideoBlacklistModel } from '../models/video/video-blacklist'
diff --git a/server/lib/oauth-model.ts b/server/lib/oauth-model.ts
index 5b4a2bcf9..eb0e63bc8 100644
--- a/server/lib/oauth-model.ts
+++ b/server/lib/oauth-model.ts
@@ -4,8 +4,9 @@ import { logger } from '../helpers/logger'
4import { UserModel } from '../models/account/user' 4import { UserModel } from '../models/account/user'
5import { OAuthClientModel } from '../models/oauth/oauth-client' 5import { OAuthClientModel } from '../models/oauth/oauth-client'
6import { OAuthTokenModel } from '../models/oauth/oauth-token' 6import { OAuthTokenModel } from '../models/oauth/oauth-token'
7import { CONFIG, CACHE } from '../initializers/constants' 7import { CACHE } from '../initializers/constants'
8import { Transaction } from 'sequelize' 8import { Transaction } from 'sequelize'
9import { CONFIG } from '../initializers/config'
9 10
10type TokenInfo = { accessToken: string, refreshToken: string, accessTokenExpiresAt: Date, refreshTokenExpiresAt: Date } 11type TokenInfo = { accessToken: string, refreshToken: string, accessTokenExpiresAt: Date, refreshTokenExpiresAt: Date }
11let accessTokenCache: { [ accessToken: string ]: OAuthTokenModel } = {} 12let accessTokenCache: { [ accessToken: string ]: OAuthTokenModel } = {}
diff --git a/server/lib/redis.ts b/server/lib/redis.ts
index d85dbe2b5..a7ec8c9df 100644
--- a/server/lib/redis.ts
+++ b/server/lib/redis.ts
@@ -3,12 +3,13 @@ import { createClient, RedisClient } from 'redis'
3import { logger } from '../helpers/logger' 3import { logger } from '../helpers/logger'
4import { generateRandomString } from '../helpers/utils' 4import { generateRandomString } from '../helpers/utils'
5import { 5import {
6 CONFIG,
7 CONTACT_FORM_LIFETIME, 6 CONTACT_FORM_LIFETIME,
8 USER_EMAIL_VERIFY_LIFETIME, 7 USER_EMAIL_VERIFY_LIFETIME,
9 USER_PASSWORD_RESET_LIFETIME, 8 USER_PASSWORD_RESET_LIFETIME,
10 VIDEO_VIEW_LIFETIME 9 VIDEO_VIEW_LIFETIME,
10 WEBSERVER
11} from '../initializers' 11} from '../initializers'
12import { CONFIG } from '../initializers/config'
12 13
13type CachedRoute = { 14type CachedRoute = {
14 body: string, 15 body: string,
@@ -41,7 +42,7 @@ class Redis {
41 this.client.auth(CONFIG.REDIS.AUTH) 42 this.client.auth(CONFIG.REDIS.AUTH)
42 } 43 }
43 44
44 this.prefix = 'redis-' + CONFIG.WEBSERVER.HOST + '-' 45 this.prefix = 'redis-' + WEBSERVER.HOST + '-'
45 } 46 }
46 47
47 static getRedisClient () { 48 static getRedisClient () {
diff --git a/server/lib/schedulers/videos-redundancy-scheduler.ts b/server/lib/schedulers/videos-redundancy-scheduler.ts
index 1a48f2bd0..4a8a1d413 100644
--- a/server/lib/schedulers/videos-redundancy-scheduler.ts
+++ b/server/lib/schedulers/videos-redundancy-scheduler.ts
@@ -1,5 +1,5 @@
1import { AbstractScheduler } from './abstract-scheduler' 1import { AbstractScheduler } from './abstract-scheduler'
2import { CONFIG, HLS_REDUNDANCY_DIRECTORY, REDUNDANCY, VIDEO_IMPORT_TIMEOUT } from '../../initializers' 2import { HLS_REDUNDANCY_DIRECTORY, REDUNDANCY, VIDEO_IMPORT_TIMEOUT, WEBSERVER } from '../../initializers'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { VideosRedundancy } from '../../../shared/models/redundancy' 4import { VideosRedundancy } from '../../../shared/models/redundancy'
5import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' 5import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
@@ -15,6 +15,7 @@ import { getOrCreateVideoAndAccountAndChannel } from '../activitypub'
15import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist' 15import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist'
16import { VideoModel } from '../../models/video/video' 16import { VideoModel } from '../../models/video/video'
17import { downloadPlaylistSegments } from '../hls' 17import { downloadPlaylistSegments } from '../hls'
18import { CONFIG } from '../../initializers/config'
18 19
19type CandidateToDuplicate = { 20type CandidateToDuplicate = {
20 redundancy: VideosRedundancy, 21 redundancy: VideosRedundancy,
@@ -186,7 +187,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
186 const createdModel = await VideoRedundancyModel.create({ 187 const createdModel = await VideoRedundancyModel.create({
187 expiresOn: this.buildNewExpiration(redundancy.minLifetime), 188 expiresOn: this.buildNewExpiration(redundancy.minLifetime),
188 url: getVideoCacheFileActivityPubUrl(file), 189 url: getVideoCacheFileActivityPubUrl(file),
189 fileUrl: video.getVideoRedundancyUrl(file, CONFIG.WEBSERVER.URL), 190 fileUrl: video.getVideoRedundancyUrl(file, WEBSERVER.URL),
190 strategy: redundancy.strategy, 191 strategy: redundancy.strategy,
191 videoFileId: file.id, 192 videoFileId: file.id,
192 actorId: serverActor.id 193 actorId: serverActor.id
@@ -212,7 +213,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler {
212 const createdModel = await VideoRedundancyModel.create({ 213 const createdModel = await VideoRedundancyModel.create({
213 expiresOn: this.buildNewExpiration(redundancy.minLifetime), 214 expiresOn: this.buildNewExpiration(redundancy.minLifetime),
214 url: getVideoCacheStreamingPlaylistActivityPubUrl(video, playlist), 215 url: getVideoCacheStreamingPlaylistActivityPubUrl(video, playlist),
215 fileUrl: playlist.getVideoRedundancyUrl(CONFIG.WEBSERVER.URL), 216 fileUrl: playlist.getVideoRedundancyUrl(WEBSERVER.URL),
216 strategy: redundancy.strategy, 217 strategy: redundancy.strategy,
217 videoStreamingPlaylistId: playlist.id, 218 videoStreamingPlaylistId: playlist.id,
218 actorId: serverActor.id 219 actorId: serverActor.id
diff --git a/server/lib/video-blacklist.ts b/server/lib/video-blacklist.ts
index dc4e0aed9..a5c6fcbb2 100644
--- a/server/lib/video-blacklist.ts
+++ b/server/lib/video-blacklist.ts
@@ -1,5 +1,5 @@
1import * as sequelize from 'sequelize' 1import * as sequelize from 'sequelize'
2import { CONFIG } from '../initializers/constants' 2import { CONFIG } from '../initializers/config'
3import { VideoBlacklistType, UserRight } from '../../shared/models' 3import { VideoBlacklistType, UserRight } from '../../shared/models'
4import { VideoBlacklistModel } from '../models/video/video-blacklist' 4import { VideoBlacklistModel } from '../models/video/video-blacklist'
5import { UserModel } from '../models/account/user' 5import { UserModel } from '../models/account/user'
diff --git a/server/lib/video-transcoding.ts b/server/lib/video-transcoding.ts
index dbc22816c..11098dca3 100644
--- a/server/lib/video-transcoding.ts
+++ b/server/lib/video-transcoding.ts
@@ -1,4 +1,4 @@
1import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION } from '../initializers' 1import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSERVER } from '../initializers'
2import { join } from 'path' 2import { join } from 'path'
3import { getVideoFileFPS, transcode } from '../helpers/ffmpeg-utils' 3import { getVideoFileFPS, transcode } from '../helpers/ffmpeg-utils'
4import { ensureDir, move, remove, stat } from 'fs-extra' 4import { ensureDir, move, remove, stat } from 'fs-extra'
@@ -9,6 +9,7 @@ import { VideoModel } from '../models/video/video'
9import { updateMasterHLSPlaylist, updateSha256Segments } from './hls' 9import { updateMasterHLSPlaylist, updateSha256Segments } from './hls'
10import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist' 10import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist'
11import { VideoStreamingPlaylistType } from '../../shared/models/videos/video-streaming-playlist.type' 11import { VideoStreamingPlaylistType } from '../../shared/models/videos/video-streaming-playlist.type'
12import { CONFIG } from '../initializers/config'
12 13
13async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFileModel) { 14async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFileModel) {
14 const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR 15 const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR
@@ -111,12 +112,12 @@ async function generateHlsPlaylist (video: VideoModel, resolution: VideoResoluti
111 await updateMasterHLSPlaylist(video) 112 await updateMasterHLSPlaylist(video)
112 await updateSha256Segments(video) 113 await updateSha256Segments(video)
113 114
114 const playlistUrl = CONFIG.WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid) 115 const playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid)
115 116
116 await VideoStreamingPlaylistModel.upsert({ 117 await VideoStreamingPlaylistModel.upsert({
117 videoId: video.id, 118 videoId: video.id,
118 playlistUrl, 119 playlistUrl,
119 segmentsSha256Url: CONFIG.WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid), 120 segmentsSha256Url: WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid),
120 p2pMediaLoaderInfohashes: VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlistUrl, video.VideoFiles), 121 p2pMediaLoaderInfohashes: VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlistUrl, video.VideoFiles),
121 p2pMediaLoaderPeerVersion: P2P_MEDIA_LOADER_PEER_VERSION, 122 p2pMediaLoaderPeerVersion: P2P_MEDIA_LOADER_PEER_VERSION,
122 123
diff --git a/server/middlewares/csp.ts b/server/middlewares/csp.ts
index 404e33b43..d484b3021 100644
--- a/server/middlewares/csp.ts
+++ b/server/middlewares/csp.ts
@@ -1,5 +1,5 @@
1import * as helmet from 'helmet' 1import * as helmet from 'helmet'
2import { CONFIG } from '../initializers/constants' 2import { CONFIG } from '../initializers/config'
3 3
4const baseDirectives = Object.assign({}, 4const baseDirectives = Object.assign({},
5 { 5 {
diff --git a/server/middlewares/validators/blocklist.ts b/server/middlewares/validators/blocklist.ts
index f5b295f45..7c494de78 100644
--- a/server/middlewares/validators/blocklist.ts
+++ b/server/middlewares/validators/blocklist.ts
@@ -3,13 +3,12 @@ import * as express from 'express'
3import { logger } from '../../helpers/logger' 3import { logger } from '../../helpers/logger'
4import { areValidationErrors } from './utils' 4import { areValidationErrors } from './utils'
5import { doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts' 5import { doesAccountNameWithHostExist } from '../../helpers/custom-validators/accounts'
6import { UserModel } from '../../models/account/user'
7import { AccountBlocklistModel } from '../../models/account/account-blocklist' 6import { AccountBlocklistModel } from '../../models/account/account-blocklist'
8import { isHostValid } from '../../helpers/custom-validators/servers' 7import { isHostValid } from '../../helpers/custom-validators/servers'
9import { ServerBlocklistModel } from '../../models/server/server-blocklist' 8import { ServerBlocklistModel } from '../../models/server/server-blocklist'
10import { ServerModel } from '../../models/server/server' 9import { ServerModel } from '../../models/server/server'
11import { CONFIG } from '../../initializers'
12import { getServerActor } from '../../helpers/utils' 10import { getServerActor } from '../../helpers/utils'
11import { WEBSERVER } from '../../initializers/constants'
13 12
14const blockAccountValidator = [ 13const blockAccountValidator = [
15 body('accountName').exists().withMessage('Should have an account name with host'), 14 body('accountName').exists().withMessage('Should have an account name with host'),
@@ -79,7 +78,7 @@ const blockServerValidator = [
79 78
80 const host: string = req.body.host 79 const host: string = req.body.host
81 80
82 if (host === CONFIG.WEBSERVER.HOST) { 81 if (host === WEBSERVER.HOST) {
83 return res.status(409) 82 return res.status(409)
84 .send({ error: 'You cannot block your own server.' }) 83 .send({ error: 'You cannot block your own server.' })
85 .end() 84 .end()
diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts
index b360cf95e..5623b4ba6 100644
--- a/server/middlewares/validators/follows.ts
+++ b/server/middlewares/validators/follows.ts
@@ -4,7 +4,7 @@ import { isTestInstance } from '../../helpers/core-utils'
4import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' 4import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers'
5import { logger } from '../../helpers/logger' 5import { logger } from '../../helpers/logger'
6import { getServerActor } from '../../helpers/utils' 6import { getServerActor } from '../../helpers/utils'
7import { CONFIG, SERVER_ACTOR_NAME } from '../../initializers' 7import { SERVER_ACTOR_NAME, WEBSERVER } from '../../initializers'
8import { ActorFollowModel } from '../../models/activitypub/actor-follow' 8import { ActorFollowModel } from '../../models/activitypub/actor-follow'
9import { areValidationErrors } from './utils' 9import { areValidationErrors } from './utils'
10import { ActorModel } from '../../models/activitypub/actor' 10import { ActorModel } from '../../models/activitypub/actor'
@@ -16,7 +16,7 @@ const followValidator = [
16 16
17 (req: express.Request, res: express.Response, next: express.NextFunction) => { 17 (req: express.Request, res: express.Response, next: express.NextFunction) => {
18 // Force https if the administrator wants to make friends 18 // Force https if the administrator wants to make friends
19 if (isTestInstance() === false && CONFIG.WEBSERVER.SCHEME === 'http') { 19 if (isTestInstance() === false && WEBSERVER.SCHEME === 'http') {
20 return res.status(500) 20 return res.status(500)
21 .json({ 21 .json({
22 error: 'Cannot follow on a non HTTPS web server.' 22 error: 'Cannot follow on a non HTTPS web server.'
diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts
index c89bc26de..0bb908d0b 100644
--- a/server/middlewares/validators/oembed.ts
+++ b/server/middlewares/validators/oembed.ts
@@ -5,10 +5,10 @@ import { isTestInstance } from '../../helpers/core-utils'
5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc' 5import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
6import { doesVideoExist } from '../../helpers/custom-validators/videos' 6import { doesVideoExist } from '../../helpers/custom-validators/videos'
7import { logger } from '../../helpers/logger' 7import { logger } from '../../helpers/logger'
8import { CONFIG } from '../../initializers'
9import { areValidationErrors } from './utils' 8import { areValidationErrors } from './utils'
9import { WEBSERVER } from '../../initializers/constants'
10 10
11const urlShouldStartWith = CONFIG.WEBSERVER.SCHEME + '://' + join(CONFIG.WEBSERVER.HOST, 'videos', 'watch') + '/' 11const urlShouldStartWith = WEBSERVER.SCHEME + '://' + join(WEBSERVER.HOST, 'videos', 'watch') + '/'
12const videoWatchRegex = new RegExp('([^/]+)$') 12const videoWatchRegex = new RegExp('([^/]+)$')
13const isURLOptions = { 13const isURLOptions = {
14 require_host: true, 14 require_host: true,
diff --git a/server/middlewares/validators/server.ts b/server/middlewares/validators/server.ts
index e62a17163..6eff8e9ee 100644
--- a/server/middlewares/validators/server.ts
+++ b/server/middlewares/validators/server.ts
@@ -7,7 +7,7 @@ import { body } from 'express-validator/check'
7import { isUserDisplayNameValid } from '../../helpers/custom-validators/users' 7import { isUserDisplayNameValid } from '../../helpers/custom-validators/users'
8import { Emailer } from '../../lib/emailer' 8import { Emailer } from '../../lib/emailer'
9import { Redis } from '../../lib/redis' 9import { Redis } from '../../lib/redis'
10import { CONFIG } from '../../initializers/constants' 10import { CONFIG } from '../../initializers/config'
11 11
12const serverGetValidator = [ 12const serverGetValidator = [
13 body('host').custom(isHostValid).withMessage('Should have a valid host'), 13 body('host').custom(isHostValid).withMessage('Should have a valid host'),
diff --git a/server/middlewares/validators/user-subscriptions.ts b/server/middlewares/validators/user-subscriptions.ts
index fd82ed017..2356745d7 100644
--- a/server/middlewares/validators/user-subscriptions.ts
+++ b/server/middlewares/validators/user-subscriptions.ts
@@ -5,8 +5,8 @@ import { logger } from '../../helpers/logger'
5import { areValidationErrors } from './utils' 5import { areValidationErrors } from './utils'
6import { ActorFollowModel } from '../../models/activitypub/actor-follow' 6import { ActorFollowModel } from '../../models/activitypub/actor-follow'
7import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' 7import { areValidActorHandles, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor'
8import { CONFIG } from '../../initializers'
9import { toArray } from '../../helpers/custom-validators/misc' 8import { toArray } from '../../helpers/custom-validators/misc'
9import { WEBSERVER } from '../../initializers/constants'
10 10
11const userSubscriptionAddValidator = [ 11const userSubscriptionAddValidator = [
12 body('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to follow (username@domain)'), 12 body('uri').custom(isValidActorHandle).withMessage('Should have a valid URI to follow (username@domain)'),
@@ -43,7 +43,7 @@ const userSubscriptionGetValidator = [
43 if (areValidationErrors(req, res)) return 43 if (areValidationErrors(req, res)) return
44 44
45 let [ name, host ] = req.params.uri.split('@') 45 let [ name, host ] = req.params.uri.split('@')
46 if (host === CONFIG.WEBSERVER.HOST) host = null 46 if (host === WEBSERVER.HOST) host = null
47 47
48 const user = res.locals.oauth.token.User 48 const user = res.locals.oauth.token.User
49 const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(user.Account.Actor.id, name, host) 49 const subscription = await ActorFollowModel.loadByActorAndTargetNameAndHostForAPI(user.Account.Actor.id, name, host)
diff --git a/server/middlewares/validators/videos/video-imports.ts b/server/middlewares/validators/videos/video-imports.ts
index 3d662b20f..fb13f3ceb 100644
--- a/server/middlewares/validators/videos/video-imports.ts
+++ b/server/middlewares/validators/videos/video-imports.ts
@@ -7,7 +7,7 @@ import { getCommonVideoEditAttributes } from './videos'
7import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports' 7import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../../helpers/custom-validators/video-imports'
8import { cleanUpReqFiles } from '../../../helpers/express-utils' 8import { cleanUpReqFiles } from '../../../helpers/express-utils'
9import { doesVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos' 9import { doesVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../../helpers/custom-validators/videos'
10import { CONFIG } from '../../../initializers/constants' 10import { CONFIG } from '../../../initializers/config'
11import { CONSTRAINTS_FIELDS } from '../../../initializers' 11import { CONSTRAINTS_FIELDS } from '../../../initializers'
12 12
13const videoImportAddValidator = getCommonVideoEditAttributes().concat([ 13const videoImportAddValidator = getCommonVideoEditAttributes().concat([
diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts
index e247db708..7ce1a922f 100644
--- a/server/middlewares/validators/videos/videos.ts
+++ b/server/middlewares/validators/videos/videos.ts
@@ -32,7 +32,7 @@ import {
32} from '../../../helpers/custom-validators/videos' 32} from '../../../helpers/custom-validators/videos'
33import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils' 33import { getDurationFromVideoFile } from '../../../helpers/ffmpeg-utils'
34import { logger } from '../../../helpers/logger' 34import { logger } from '../../../helpers/logger'
35import { CONFIG, CONSTRAINTS_FIELDS } from '../../../initializers' 35import { CONSTRAINTS_FIELDS } from '../../../initializers'
36import { authenticatePromiseIfNeeded } from '../../oauth' 36import { authenticatePromiseIfNeeded } from '../../oauth'
37import { areValidationErrors } from '../utils' 37import { areValidationErrors } from '../utils'
38import { cleanUpReqFiles } from '../../../helpers/express-utils' 38import { cleanUpReqFiles } from '../../../helpers/express-utils'
@@ -43,6 +43,7 @@ import { AccountModel } from '../../../models/account/account'
43import { VideoFetchType } from '../../../helpers/video' 43import { VideoFetchType } from '../../../helpers/video'
44import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search' 44import { isNSFWQueryValid, isNumberArray, isStringArray } from '../../../helpers/custom-validators/search'
45import { getServerActor } from '../../../helpers/utils' 45import { getServerActor } from '../../../helpers/utils'
46import { CONFIG } from '../../../initializers/config'
46 47
47const videosAddValidator = getCommonVideoEditAttributes().concat([ 48const videosAddValidator = getCommonVideoEditAttributes().concat([
48 body('videofile') 49 body('videofile')
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 7cc40f631..6f425024e 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -25,9 +25,9 @@ import { getSort, throwIfNotValid } from '../utils'
25import { VideoChannelModel } from '../video/video-channel' 25import { VideoChannelModel } from '../video/video-channel'
26import { VideoCommentModel } from '../video/video-comment' 26import { VideoCommentModel } from '../video/video-comment'
27import { UserModel } from './user' 27import { UserModel } from './user'
28import { CONFIG } from '../../initializers'
29import { AvatarModel } from '../avatar/avatar' 28import { AvatarModel } from '../avatar/avatar'
30import { VideoPlaylistModel } from '../video/video-playlist' 29import { VideoPlaylistModel } from '../video/video-playlist'
30import { WEBSERVER } from '../../initializers/constants'
31 31
32export enum ScopeNames { 32export enum ScopeNames {
33 SUMMARY = 'SUMMARY' 33 SUMMARY = 'SUMMARY'
@@ -199,7 +199,7 @@ export class AccountModel extends Model<AccountModel> {
199 static loadByNameWithHost (nameWithHost: string) { 199 static loadByNameWithHost (nameWithHost: string) {
200 const [ accountName, host ] = nameWithHost.split('@') 200 const [ accountName, host ] = nameWithHost.split('@')
201 201
202 if (!host || host === CONFIG.WEBSERVER.HOST) return AccountModel.loadLocalByName(accountName) 202 if (!host || host === WEBSERVER.HOST) return AccountModel.loadLocalByName(accountName)
203 203
204 return AccountModel.loadByNameAndHost(accountName, host) 204 return AccountModel.loadByNameAndHost(accountName, host)
205 } 205 }
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts
index 7d91e8a4a..5472c8b92 100644
--- a/server/models/activitypub/actor.ts
+++ b/server/models/activitypub/actor.ts
@@ -30,7 +30,7 @@ import {
30 isActorPublicKeyValid 30 isActorPublicKeyValid
31} from '../../helpers/custom-validators/activitypub/actor' 31} from '../../helpers/custom-validators/activitypub/actor'
32import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 32import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
33import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' 33import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers'
34import { AccountModel } from '../account/account' 34import { AccountModel } from '../account/account'
35import { AvatarModel } from '../avatar/avatar' 35import { AvatarModel } from '../avatar/avatar'
36import { ServerModel } from '../server/server' 36import { ServerModel } from '../server/server'
@@ -516,7 +516,7 @@ export class ActorModel extends Model<ActorModel> {
516 } 516 }
517 517
518 getHost () { 518 getHost () {
519 return this.Server ? this.Server.host : CONFIG.WEBSERVER.HOST 519 return this.Server ? this.Server.host : WEBSERVER.HOST
520 } 520 }
521 521
522 getRedundancyAllowed () { 522 getRedundancyAllowed () {
@@ -526,7 +526,7 @@ export class ActorModel extends Model<ActorModel> {
526 getAvatarUrl () { 526 getAvatarUrl () {
527 if (!this.avatarId) return undefined 527 if (!this.avatarId) return undefined
528 528
529 return CONFIG.WEBSERVER.URL + this.Avatar.getWebserverPath() 529 return WEBSERVER.URL + this.Avatar.getWebserverPath()
530 } 530 }
531 531
532 isOutdated () { 532 isOutdated () {
diff --git a/server/models/avatar/avatar.ts b/server/models/avatar/avatar.ts
index 303aebcc2..455835524 100644
--- a/server/models/avatar/avatar.ts
+++ b/server/models/avatar/avatar.ts
@@ -1,9 +1,10 @@
1import { join } from 'path' 1import { join } from 'path'
2import { AfterDestroy, AllowNull, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript' 2import { AfterDestroy, AllowNull, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript'
3import { Avatar } from '../../../shared/models/avatars/avatar.model' 3import { Avatar } from '../../../shared/models/avatars/avatar.model'
4import { CONFIG, STATIC_PATHS } from '../../initializers' 4import { STATIC_PATHS } from '../../initializers'
5import { logger } from '../../helpers/logger' 5import { logger } from '../../helpers/logger'
6import { remove } from 'fs-extra' 6import { remove } from 'fs-extra'
7import { CONFIG } from '../../initializers/config'
7 8
8@Table({ 9@Table({
9 tableName: 'avatar' 10 tableName: 'avatar'
diff --git a/server/models/redundancy/video-redundancy.ts b/server/models/redundancy/video-redundancy.ts
index b722bed14..39c50be5c 100644
--- a/server/models/redundancy/video-redundancy.ts
+++ b/server/models/redundancy/video-redundancy.ts
@@ -15,7 +15,7 @@ import {
15import { ActorModel } from '../activitypub/actor' 15import { ActorModel } from '../activitypub/actor'
16import { getVideoSort, throwIfNotValid } from '../utils' 16import { getVideoSort, throwIfNotValid } from '../utils'
17import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc' 17import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc'
18import { CONFIG, CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers' 18import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers'
19import { VideoFileModel } from '../video/video-file' 19import { VideoFileModel } from '../video/video-file'
20import { getServerActor } from '../../helpers/utils' 20import { getServerActor } from '../../helpers/utils'
21import { VideoModel } from '../video/video' 21import { VideoModel } from '../video/video'
@@ -29,6 +29,7 @@ import { isTestInstance } from '../../helpers/core-utils'
29import * as Bluebird from 'bluebird' 29import * as Bluebird from 'bluebird'
30import * as Sequelize from 'sequelize' 30import * as Sequelize from 'sequelize'
31import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist' 31import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist'
32import { CONFIG } from '../../initializers/config'
32 33
33export enum ScopeNames { 34export enum ScopeNames {
34 WITH_VIDEO = 'WITH_VIDEO' 35 WITH_VIDEO = 'WITH_VIDEO'
diff --git a/server/models/video/video-caption.ts b/server/models/video/video-caption.ts
index b4f17b481..c670bce71 100644
--- a/server/models/video/video-caption.ts
+++ b/server/models/video/video-caption.ts
@@ -16,10 +16,11 @@ import { throwIfNotValid } from '../utils'
16import { VideoModel } from './video' 16import { VideoModel } from './video'
17import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions' 17import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions'
18import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model' 18import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model'
19import { CONFIG, STATIC_PATHS, VIDEO_LANGUAGES } from '../../initializers' 19import { STATIC_PATHS, VIDEO_LANGUAGES } from '../../initializers'
20import { join } from 'path' 20import { join } from 'path'
21import { logger } from '../../helpers/logger' 21import { logger } from '../../helpers/logger'
22import { remove } from 'fs-extra' 22import { remove } from 'fs-extra'
23import { CONFIG } from '../../initializers/config'
23 24
24export enum ScopeNames { 25export enum ScopeNames {
25 WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE' 26 WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE'
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index ca06048d1..1abc23eaa 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -8,7 +8,8 @@ import {
8 Default, 8 Default,
9 DefaultScope, 9 DefaultScope,
10 ForeignKey, 10 ForeignKey,
11 HasMany, IFindOptions, 11 HasMany,
12 IFindOptions,
12 Is, 13 Is,
13 Model, 14 Model,
14 Scopes, 15 Scopes,
@@ -28,7 +29,7 @@ import { AccountModel, ScopeNames as AccountModelScopeNames } from '../account/a
28import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor' 29import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor'
29import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' 30import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils'
30import { VideoModel } from './video' 31import { VideoModel } from './video'
31import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' 32import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers'
32import { ServerModel } from '../server/server' 33import { ServerModel } from '../server/server'
33import { DefineIndexesOptions } from 'sequelize' 34import { DefineIndexesOptions } from 'sequelize'
34import { AvatarModel } from '../avatar/avatar' 35import { AvatarModel } from '../avatar/avatar'
@@ -419,7 +420,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> {
419 static loadByNameWithHostAndPopulateAccount (nameWithHost: string) { 420 static loadByNameWithHostAndPopulateAccount (nameWithHost: string) {
420 const [ name, host ] = nameWithHost.split('@') 421 const [ name, host ] = nameWithHost.split('@')
421 422
422 if (!host || host === CONFIG.WEBSERVER.HOST) return VideoChannelModel.loadLocalByNameAndPopulateAccount(name) 423 if (!host || host === WEBSERVER.HOST) return VideoChannelModel.loadLocalByNameAndPopulateAccount(name)
423 424
424 return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host) 425 return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host)
425 } 426 }
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 93d84c6fc..47f1cbb99 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -18,7 +18,7 @@ import { ActivityTagObject } from '../../../shared/models/activitypub/objects/co
18import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' 18import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object'
19import { VideoComment } from '../../../shared/models/videos/video-comment.model' 19import { VideoComment } from '../../../shared/models/videos/video-comment.model'
20import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 20import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
21import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' 21import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers'
22import { sendDeleteVideoComment } from '../../lib/activitypub/send' 22import { sendDeleteVideoComment } from '../../lib/activitypub/send'
23import { AccountModel } from '../account/account' 23import { AccountModel } from '../account/account'
24import { ActorModel } from '../activitypub/actor' 24import { ActorModel } from '../activitypub/actor'
@@ -482,7 +482,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
482 let result: string[] = [] 482 let result: string[] = []
483 483
484 const localMention = `@(${actorNameAlphabet}+)` 484 const localMention = `@(${actorNameAlphabet}+)`
485 const remoteMention = `${localMention}@${CONFIG.WEBSERVER.HOST}` 485 const remoteMention = `${localMention}@${WEBSERVER.HOST}`
486 486
487 const mentionRegex = this.isOwned() 487 const mentionRegex = this.isOwned()
488 ? '(?:(?:' + remoteMention + ')|(?:' + localMention + '))' // Include local mentions? 488 ? '(?:(?:' + remoteMention + ')|(?:' + localMention + '))' // Include local mentions?
diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts
index dc10fb9a2..7915fc1f9 100644
--- a/server/models/video/video-format-utils.ts
+++ b/server/models/video/video-format-utils.ts
@@ -7,7 +7,7 @@ import {
7 ActivityUrlObject, 7 ActivityUrlObject,
8 VideoTorrentObject 8 VideoTorrentObject
9} from '../../../shared/models/activitypub/objects' 9} from '../../../shared/models/activitypub/objects'
10import { CONFIG, MIMETYPES, THUMBNAILS_SIZE } from '../../initializers' 10import { MIMETYPES, THUMBNAILS_SIZE, WEBSERVER } from '../../initializers'
11import { VideoCaptionModel } from './video-caption' 11import { VideoCaptionModel } from './video-caption'
12import { 12import {
13 getVideoCommentsActivityPubUrl, 13 getVideoCommentsActivityPubUrl,
@@ -290,7 +290,7 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject {
290 type: 'Link', 290 type: 'Link',
291 mimeType: 'text/html', 291 mimeType: 'text/html',
292 mediaType: 'text/html', 292 mediaType: 'text/html',
293 href: CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid 293 href: WEBSERVER.URL + '/videos/watch/' + video.uuid
294 }) 294 })
295 295
296 const subtitleLanguage = [] 296 const subtitleLanguage = []
diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts
index 08e4d32c8..93f36a9d0 100644
--- a/server/models/video/video-playlist.ts
+++ b/server/models/video/video-playlist.ts
@@ -26,12 +26,12 @@ import {
26import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 26import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
27import { 27import {
28 ACTIVITY_PUB, 28 ACTIVITY_PUB,
29 CONFIG,
30 CONSTRAINTS_FIELDS, 29 CONSTRAINTS_FIELDS,
31 STATIC_PATHS, 30 STATIC_PATHS,
32 THUMBNAILS_SIZE, 31 THUMBNAILS_SIZE,
33 VIDEO_PLAYLIST_PRIVACIES, 32 VIDEO_PLAYLIST_PRIVACIES,
34 VIDEO_PLAYLIST_TYPES 33 VIDEO_PLAYLIST_TYPES,
34 WEBSERVER
35} from '../../initializers' 35} from '../../initializers'
36import { VideoPlaylist } from '../../../shared/models/videos/playlist/video-playlist.model' 36import { VideoPlaylist } from '../../../shared/models/videos/playlist/video-playlist.model'
37import { AccountModel, ScopeNames as AccountScopeNames } from '../account/account' 37import { AccountModel, ScopeNames as AccountScopeNames } from '../account/account'
@@ -43,6 +43,7 @@ import { activityPubCollectionPagination } from '../../helpers/activitypub'
43import { remove } from 'fs-extra' 43import { remove } from 'fs-extra'
44import { logger } from '../../helpers/logger' 44import { logger } from '../../helpers/logger'
45import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video-playlist-type.model' 45import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video-playlist-type.model'
46import { CONFIG } from '../../initializers/config'
46 47
47enum ScopeNames { 48enum ScopeNames {
48 AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', 49 AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
@@ -417,7 +418,7 @@ export class VideoPlaylistModel extends Model<VideoPlaylistModel> {
417 } 418 }
418 419
419 getThumbnailUrl () { 420 getThumbnailUrl () {
420 return CONFIG.WEBSERVER.URL + STATIC_PATHS.THUMBNAILS + this.getThumbnailName() 421 return WEBSERVER.URL + STATIC_PATHS.THUMBNAILS + this.getThumbnailName()
421 } 422 }
422 423
423 getThumbnailStaticPath () { 424 getThumbnailStaticPath () {
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index b0d92b674..3b30e9e28 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -51,10 +51,9 @@ import { getServerActor } from '../../helpers/utils'
51import { 51import {
52 ACTIVITY_PUB, 52 ACTIVITY_PUB,
53 API_VERSION, 53 API_VERSION,
54 CONFIG,
55 CONSTRAINTS_FIELDS, 54 CONSTRAINTS_FIELDS,
56 HLS_STREAMING_PLAYLIST_DIRECTORY,
57 HLS_REDUNDANCY_DIRECTORY, 55 HLS_REDUNDANCY_DIRECTORY,
56 HLS_STREAMING_PLAYLIST_DIRECTORY,
58 PREVIEWS_SIZE, 57 PREVIEWS_SIZE,
59 REMOTE_SCHEME, 58 REMOTE_SCHEME,
60 STATIC_DOWNLOAD_PATHS, 59 STATIC_DOWNLOAD_PATHS,
@@ -64,7 +63,8 @@ import {
64 VIDEO_LANGUAGES, 63 VIDEO_LANGUAGES,
65 VIDEO_LICENCES, 64 VIDEO_LICENCES,
66 VIDEO_PRIVACIES, 65 VIDEO_PRIVACIES,
67 VIDEO_STATES 66 VIDEO_STATES,
67 WEBSERVER
68} from '../../initializers' 68} from '../../initializers'
69import { sendDeleteVideo } from '../../lib/activitypub/send' 69import { sendDeleteVideo } from '../../lib/activitypub/send'
70import { AccountModel } from '../account/account' 70import { AccountModel } from '../account/account'
@@ -77,12 +77,13 @@ import {
77 buildTrigramSearchIndex, 77 buildTrigramSearchIndex,
78 buildWhereIdOrUUID, 78 buildWhereIdOrUUID,
79 createSimilarityAttribute, 79 createSimilarityAttribute,
80 getVideoSort, isOutdated, 80 getVideoSort,
81 isOutdated,
81 throwIfNotValid 82 throwIfNotValid
82} from '../utils' 83} from '../utils'
83import { TagModel } from './tag' 84import { TagModel } from './tag'
84import { VideoAbuseModel } from './video-abuse' 85import { VideoAbuseModel } from './video-abuse'
85import { VideoChannelModel, ScopeNames as VideoChannelScopeNames } from './video-channel' 86import { ScopeNames as VideoChannelScopeNames, VideoChannelModel } from './video-channel'
86import { VideoCommentModel } from './video-comment' 87import { VideoCommentModel } from './video-comment'
87import { VideoFileModel } from './video-file' 88import { VideoFileModel } from './video-file'
88import { VideoShareModel } from './video-share' 89import { VideoShareModel } from './video-share'
@@ -105,6 +106,7 @@ import { UserModel } from '../account/user'
105import { VideoImportModel } from './video-import' 106import { VideoImportModel } from './video-import'
106import { VideoStreamingPlaylistModel } from './video-streaming-playlist' 107import { VideoStreamingPlaylistModel } from './video-streaming-playlist'
107import { VideoPlaylistElementModel } from './video-playlist-element' 108import { VideoPlaylistElementModel } from './video-playlist-element'
109import { CONFIG } from '../../initializers/config'
108 110
109// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation 111// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
110const indexes: Sequelize.DefineIndexesOptions[] = [ 112const indexes: Sequelize.DefineIndexesOptions[] = [
@@ -1664,10 +1666,10 @@ export class VideoModel extends Model<VideoModel> {
1664 name: `${this.name} ${videoFile.resolution}p${videoFile.extname}`, 1666 name: `${this.name} ${videoFile.resolution}p${videoFile.extname}`,
1665 createdBy: 'PeerTube', 1667 createdBy: 'PeerTube',
1666 announceList: [ 1668 announceList: [
1667 [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ], 1669 [ WEBSERVER.WS + '://' + WEBSERVER.HOSTNAME + ':' + WEBSERVER.PORT + '/tracker/socket' ],
1668 [ CONFIG.WEBSERVER.URL + '/tracker/announce' ] 1670 [ WEBSERVER.URL + '/tracker/announce' ]
1669 ], 1671 ],
1670 urlList: [ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) ] 1672 urlList: [ WEBSERVER.URL + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) ]
1671 } 1673 }
1672 1674
1673 const torrent = await createTorrentPromise(this.getVideoFilePath(videoFile), options) 1675 const torrent = await createTorrentPromise(this.getVideoFilePath(videoFile), options)
@@ -1781,8 +1783,8 @@ export class VideoModel extends Model<VideoModel> {
1781 let baseUrlWs 1783 let baseUrlWs
1782 1784
1783 if (this.isOwned()) { 1785 if (this.isOwned()) {
1784 baseUrlHttp = CONFIG.WEBSERVER.URL 1786 baseUrlHttp = WEBSERVER.URL
1785 baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT 1787 baseUrlWs = WEBSERVER.WS + '://' + WEBSERVER.HOSTNAME + ':' + WEBSERVER.PORT
1786 } else { 1788 } else {
1787 baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + this.VideoChannel.Account.Actor.Server.host 1789 baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + this.VideoChannel.Account.Actor.Server.host
1788 baseUrlWs = REMOTE_SCHEME.WS + '://' + this.VideoChannel.Account.Actor.Server.host 1790 baseUrlWs = REMOTE_SCHEME.WS + '://' + this.VideoChannel.Account.Actor.Server.host