From 6dd9de95dfa39bd5c1faed00d1dbd52cd112bae0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 11 Apr 2019 11:33:44 +0200 Subject: Move config in its own file --- server/lib/activitypub/actor.ts | 5 ++- server/lib/activitypub/playlist.ts | 3 +- server/lib/activitypub/process/process-follow.ts | 3 +- server/lib/activitypub/url.ts | 20 +++++----- server/lib/activitypub/videos.ts | 2 +- server/lib/avatar.ts | 3 +- server/lib/client-html.ts | 13 ++++--- server/lib/emailer.ts | 43 +++++++++++----------- server/lib/files-cache/videos-caption-cache.ts | 3 +- server/lib/files-cache/videos-preview-cache.ts | 3 +- server/lib/hls.ts | 3 +- .../lib/job-queue/handlers/activitypub-follow.ts | 4 +- server/lib/job-queue/handlers/video-import.ts | 5 ++- server/lib/job-queue/handlers/video-transcoding.ts | 3 +- server/lib/job-queue/job-queue.ts | 4 +- server/lib/notifier.ts | 2 +- server/lib/oauth-model.ts | 3 +- server/lib/redis.ts | 7 ++-- .../lib/schedulers/videos-redundancy-scheduler.ts | 7 ++-- server/lib/video-blacklist.ts | 2 +- server/lib/video-transcoding.ts | 7 ++-- 21 files changed, 80 insertions(+), 65 deletions(-) (limited to 'server/lib') 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' import { createPrivateAndPublicKeys } from '../../helpers/peertube-crypto' import { doRequest, downloadImage } from '../../helpers/requests' import { getUrlFromWebfinger } from '../../helpers/webfinger' -import { AVATARS_SIZE, CONFIG, MIMETYPES, sequelizeTypescript } from '../../initializers' +import { AVATARS_SIZE, MIMETYPES, sequelizeTypescript, WEBSERVER } from '../../initializers' import { AccountModel } from '../../models/account/account' import { ActorModel } from '../../models/activitypub/actor' import { AvatarModel } from '../../models/avatar/avatar' @@ -21,6 +21,7 @@ import { VideoChannelModel } from '../../models/video/video-channel' import { JobQueue } from '../job-queue' import { getServerActor } from '../../helpers/utils' import { ActorFetchByUrlType, fetchActorByUrl } from '../../helpers/actor' +import { CONFIG } from '../../initializers/config' // Set account keys, this could be long so process after the account creation and do not block the client function setAsyncActorKeys (actor: ActorModel) { @@ -116,7 +117,7 @@ function buildActorInstance (type: ActivityPubActorType, url: string, preferredU followingCount: 0, inboxUrl: url + '/inbox', outboxUrl: url + '/outbox', - sharedInboxUrl: CONFIG.WEBSERVER.URL + '/inbox', + sharedInboxUrl: WEBSERVER.URL + '/inbox', followersUrl: url + '/followers', followingUrl: url + '/following' }) 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 @@ import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' import { crawlCollectionPage } from './crawl' -import { ACTIVITY_PUB, CONFIG, CRAWL_REQUEST_CONCURRENCY, sequelizeTypescript, THUMBNAILS_SIZE } from '../../initializers' +import { ACTIVITY_PUB, CRAWL_REQUEST_CONCURRENCY, sequelizeTypescript, THUMBNAILS_SIZE } from '../../initializers' import { AccountModel } from '../../models/account/account' import { isArray } from '../../helpers/custom-validators/misc' import { getOrCreateActorAndServerAndModel } from './actor' @@ -17,6 +17,7 @@ import { VideoModel } from '../../models/video/video' import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model' import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' import { ActivityIconObject } from '../../../shared/models/activitypub/objects' +import { CONFIG } from '../../initializers/config' function playlistObjectToDBAttributes (playlistObject: PlaylistObject, byAccount: AccountModel, to: string[]) { 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 @@ import { ActivityFollow } from '../../../../shared/models/activitypub' import { retryTransactionWrapper } from '../../../helpers/database-utils' import { logger } from '../../../helpers/logger' -import { sequelizeTypescript, CONFIG } from '../../../initializers' +import { sequelizeTypescript } from '../../../initializers' import { ActorModel } from '../../../models/activitypub/actor' import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { sendAccept, sendReject } from '../send' import { Notifier } from '../../notifier' import { getAPId } from '../../../helpers/activitypub' import { getServerActor } from '../../../helpers/utils' +import { CONFIG } from '../../../initializers/config' async function processFollowActivity (activity: ActivityFollow, byActor: ActorModel) { 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 @@ -import { CONFIG } from '../../initializers' +import { WEBSERVER } from '../../initializers' import { ActorModel } from '../../models/activitypub/actor' import { ActorFollowModel } from '../../models/activitypub/actor-follow' import { VideoModel } from '../../models/video/video' @@ -9,41 +9,41 @@ import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming- import { VideoPlaylistModel } from '../../models/video/video-playlist' function getVideoActivityPubUrl (video: VideoModel) { - return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid + return WEBSERVER.URL + '/videos/watch/' + video.uuid } function getVideoPlaylistActivityPubUrl (videoPlaylist: VideoPlaylistModel) { - return CONFIG.WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid } function getVideoPlaylistElementActivityPubUrl (videoPlaylist: VideoPlaylistModel, video: VideoModel) { - return CONFIG.WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/' + video.uuid + return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/' + video.uuid } function getVideoCacheFileActivityPubUrl (videoFile: VideoFileModel) { const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : '' - return `${CONFIG.WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}` + return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}` } function getVideoCacheStreamingPlaylistActivityPubUrl (video: VideoModel, playlist: VideoStreamingPlaylistModel) { - return `${CONFIG.WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}` + return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}` } function getVideoCommentActivityPubUrl (video: VideoModel, videoComment: VideoCommentModel) { - return CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id + return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id } function getVideoChannelActivityPubUrl (videoChannelName: string) { - return CONFIG.WEBSERVER.URL + '/video-channels/' + videoChannelName + return WEBSERVER.URL + '/video-channels/' + videoChannelName } function getAccountActivityPubUrl (accountName: string) { - return CONFIG.WEBSERVER.URL + '/accounts/' + accountName + return WEBSERVER.URL + '/accounts/' + accountName } function getVideoAbuseActivityPubUrl (videoAbuse: VideoAbuseModel) { - return CONFIG.WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id + return WEBSERVER.URL + '/admin/video-abuses/' + videoAbuse.id } function 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' import { doRequest, downloadImage } from '../../helpers/requests' import { ACTIVITY_PUB, - CONFIG, MIMETYPES, P2P_MEDIA_LOADER_PEER_VERSION, REMOTE_SCHEME, @@ -51,6 +50,7 @@ import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model' import { AccountVideoRateModel } from '../../models/account/account-video-rate' import { VideoShareModel } from '../../models/video/video-share' import { VideoCommentModel } from '../../models/video/video-comment' +import { CONFIG } from '../../initializers/config' async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) { // 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 @@ import 'multer' import { sendUpdateActor } from './activitypub/send' -import { AVATARS_SIZE, CONFIG, sequelizeTypescript } from '../initializers' +import { AVATARS_SIZE, sequelizeTypescript } from '../initializers' import { updateActorAvatarInstance } from './activitypub' import { processImage } from '../helpers/image-utils' import { AccountModel } from '../models/account/account' @@ -8,6 +8,7 @@ import { VideoChannelModel } from '../models/video/video-channel' import { extname, join } from 'path' import { retryTransactionWrapper } from '../helpers/database-utils' import * as uuidv4 from 'uuid/v4' +import { CONFIG } from '../initializers/config' async function updateActorAvatarFile (avatarPhysicalFile: Express.Multer.File, accountOrChannel: AccountModel | VideoChannelModel) { 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 @@ import * as express from 'express' import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/models/i18n/i18n' -import { CONFIG, CUSTOM_HTML_TAG_COMMENTS, EMBED_SIZE } from '../initializers' +import { CUSTOM_HTML_TAG_COMMENTS, EMBED_SIZE, WEBSERVER } from '../initializers' import { join } from 'path' import { escapeHTML } from '../helpers/core-utils' import { VideoModel } from '../models/video/video' @@ -11,6 +11,7 @@ import { getActivityStreamDuration } from '../models/video/video-format-utils' import { AccountModel } from '../models/account/account' import { VideoChannelModel } from '../models/video/video-channel' import * as Bluebird from 'bluebird' +import { CONFIG } from '../initializers/config' export class ClientHtml { @@ -106,7 +107,7 @@ export class ClientHtml { // Save locale in cookies res.cookie('clientLanguage', lang, { - secure: CONFIG.WEBSERVER.SCHEME === 'https', + secure: WEBSERVER.SCHEME === 'https', sameSite: true, maxAge: 1000 * 3600 * 24 * 90 // 3 months }) @@ -143,12 +144,12 @@ export class ClientHtml { } private static addVideoOpenGraphAndOEmbedTags (htmlStringPage: string, video: VideoModel) { - const previewUrl = CONFIG.WEBSERVER.URL + video.getPreviewStaticPath() - const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() + const previewUrl = WEBSERVER.URL + video.getPreviewStaticPath() + const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() const videoNameEscaped = escapeHTML(video.name) const videoDescriptionEscaped = escapeHTML(video.description) - const embedUrl = CONFIG.WEBSERVER.URL + video.getEmbedStaticPath() + const embedUrl = WEBSERVER.URL + video.getEmbedStaticPath() const openGraphMetaTags = { 'og:type': 'video', @@ -180,7 +181,7 @@ export class ClientHtml { const oembedLinkTags = [ { type: 'application/json+oembed', - href: CONFIG.WEBSERVER.URL + '/services/oembed?url=' + encodeURIComponent(videoUrl), + href: WEBSERVER.URL + '/services/oembed?url=' + encodeURIComponent(videoUrl), title: videoNameEscaped } ] 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 @@ import { createTransport, Transporter } from 'nodemailer' import { isTestInstance } from '../helpers/core-utils' import { bunyanLogger, logger } from '../helpers/logger' -import { CONFIG } from '../initializers' +import { CONFIG } from '../initializers/config' import { UserModel } from '../models/account/user' import { VideoModel } from '../models/video/video' import { JobQueue } from './job-queue' @@ -12,6 +12,7 @@ import { VideoAbuseModel } from '../models/video/video-abuse' import { VideoBlacklistModel } from '../models/video/video-blacklist' import { VideoImportModel } from '../models/video/video-import' import { ActorFollowModel } from '../models/activitypub/actor-follow' +import { WEBSERVER } from '../initializers/constants' type SendEmailOptions = { to: string[] @@ -91,7 +92,7 @@ class Emailer { addNewVideoFromSubscriberNotification (to: string[], video: VideoModel) { const channelName = video.VideoChannel.getDisplayName() - const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() + const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() const text = `Hi dear user,\n\n` + `Your subscription ${channelName} just published a new video: ${video.name}` + @@ -148,7 +149,7 @@ class Emailer { } myVideoPublishedNotification (to: string[], video: VideoModel) { - const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() + const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() const text = `Hi dear user,\n\n` + `Your video ${video.name} has been published.` + @@ -168,7 +169,7 @@ class Emailer { } myVideoImportSuccessNotification (to: string[], videoImport: VideoImportModel) { - const videoUrl = CONFIG.WEBSERVER.URL + videoImport.Video.getWatchStaticPath() + const videoUrl = WEBSERVER.URL + videoImport.Video.getWatchStaticPath() const text = `Hi dear user,\n\n` + `Your video import ${videoImport.getTargetIdentifier()} is finished.` + @@ -188,7 +189,7 @@ class Emailer { } myVideoImportErrorNotification (to: string[], videoImport: VideoImportModel) { - const importUrl = CONFIG.WEBSERVER.URL + '/my-account/video-imports' + const importUrl = WEBSERVER.URL + '/my-account/video-imports' const text = `Hi dear user,\n\n` + `Your video import ${videoImport.getTargetIdentifier()} encountered an error.` + @@ -210,7 +211,7 @@ class Emailer { addNewCommentOnMyVideoNotification (to: string[], comment: VideoCommentModel) { const accountName = comment.Account.getDisplayName() const video = comment.Video - const commentUrl = CONFIG.WEBSERVER.URL + comment.getCommentStaticPath() + const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath() const text = `Hi dear user,\n\n` + `A new comment has been posted by ${accountName} on your video ${video.name}` + @@ -232,7 +233,7 @@ class Emailer { addNewCommentMentionNotification (to: string[], comment: VideoCommentModel) { const accountName = comment.Account.getDisplayName() const video = comment.Video - const commentUrl = CONFIG.WEBSERVER.URL + comment.getCommentStaticPath() + const commentUrl = WEBSERVER.URL + comment.getCommentStaticPath() const text = `Hi dear user,\n\n` + `${accountName} mentioned you on video ${video.name}` + @@ -252,10 +253,10 @@ class Emailer { } addVideoAbuseModeratorsNotification (to: string[], videoAbuse: VideoAbuseModel) { - const videoUrl = CONFIG.WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath() + const videoUrl = WEBSERVER.URL + videoAbuse.Video.getWatchStaticPath() const text = `Hi,\n\n` + - `${CONFIG.WEBSERVER.HOST} received an abuse for the following video ${videoUrl}\n\n` + + `${WEBSERVER.HOST} received an abuse for the following video ${videoUrl}\n\n` + `Cheers,\n` + `PeerTube.` @@ -269,8 +270,8 @@ class Emailer { } addVideoAutoBlacklistModeratorsNotification (to: string[], video: VideoModel) { - const VIDEO_AUTO_BLACKLIST_URL = CONFIG.WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' - const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() + const VIDEO_AUTO_BLACKLIST_URL = WEBSERVER.URL + '/admin/moderation/video-auto-blacklist/list' + const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() const text = `Hi,\n\n` + `A recently added video was auto-blacklisted and requires moderator review before publishing.` + @@ -293,13 +294,13 @@ class Emailer { addNewUserRegistrationNotification (to: string[], user: UserModel) { const text = `Hi,\n\n` + - `User ${user.username} just registered on ${CONFIG.WEBSERVER.HOST} PeerTube instance.\n\n` + + `User ${user.username} just registered on ${WEBSERVER.HOST} PeerTube instance.\n\n` + `Cheers,\n` + `PeerTube.` const emailPayload: EmailPayload = { to, - subject: '[PeerTube] New user registration on ' + CONFIG.WEBSERVER.HOST, + subject: '[PeerTube] New user registration on ' + WEBSERVER.HOST, text } @@ -308,10 +309,10 @@ class Emailer { addVideoBlacklistNotification (to: string[], videoBlacklist: VideoBlacklistModel) { const videoName = videoBlacklist.Video.name - const videoUrl = CONFIG.WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() + const videoUrl = WEBSERVER.URL + videoBlacklist.Video.getWatchStaticPath() const reasonString = videoBlacklist.reason ? ` for the following reason: ${videoBlacklist.reason}` : '' - const blockedString = `Your video ${videoName} (${videoUrl} on ${CONFIG.WEBSERVER.HOST} has been blacklisted${reasonString}.` + const blockedString = `Your video ${videoName} (${videoUrl} on ${WEBSERVER.HOST} has been blacklisted${reasonString}.` const text = 'Hi,\n\n' + blockedString + @@ -329,10 +330,10 @@ class Emailer { } addVideoUnblacklistNotification (to: string[], video: VideoModel) { - const videoUrl = CONFIG.WEBSERVER.URL + video.getWatchStaticPath() + const videoUrl = WEBSERVER.URL + video.getWatchStaticPath() const text = 'Hi,\n\n' + - `Your video ${video.name} (${videoUrl}) on ${CONFIG.WEBSERVER.HOST} has been unblacklisted.` + + `Your video ${video.name} (${videoUrl}) on ${WEBSERVER.HOST} has been unblacklisted.` + '\n\n' + 'Cheers,\n' + `PeerTube.` @@ -348,7 +349,7 @@ class Emailer { addPasswordResetEmailJob (to: string, resetPasswordUrl: string) { const text = `Hi dear user,\n\n` + - `A reset password procedure for your account ${to} has been requested on ${CONFIG.WEBSERVER.HOST} ` + + `A reset password procedure for your account ${to} has been requested on ${WEBSERVER.HOST} ` + `Please follow this link to reset it: ${resetPasswordUrl}\n\n` + `If you are not the person who initiated this request, please ignore this email.\n\n` + `Cheers,\n` + @@ -365,7 +366,7 @@ class Emailer { addVerifyEmailJob (to: string, verifyEmailUrl: string) { const text = `Welcome to PeerTube,\n\n` + - `To start using PeerTube on ${CONFIG.WEBSERVER.HOST} you must verify your email! ` + + `To start using PeerTube on ${WEBSERVER.HOST} you must verify your email! ` + `Please follow this link to verify this email belongs to you: ${verifyEmailUrl}\n\n` + `If you are not the person who initiated this request, please ignore this email.\n\n` + `Cheers,\n` + @@ -383,7 +384,7 @@ class Emailer { addUserBlockJob (user: UserModel, blocked: boolean, reason?: string) { const reasonString = reason ? ` for the following reason: ${reason}` : '' const blockedWord = blocked ? 'blocked' : 'unblocked' - const blockedString = `Your account ${user.username} on ${CONFIG.WEBSERVER.HOST} has been ${blockedWord}${reasonString}.` + const blockedString = `Your account ${user.username} on ${WEBSERVER.HOST} has been ${blockedWord}${reasonString}.` const text = 'Hi,\n\n' + blockedString + @@ -428,7 +429,7 @@ class Emailer { const fromDisplayName = options.fromDisplayName ? options.fromDisplayName - : CONFIG.WEBSERVER.HOST + : WEBSERVER.HOST return this.transporter.sendMail({ 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 @@ import { join } from 'path' -import { FILES_CACHE, CONFIG } from '../../initializers' +import { FILES_CACHE } from '../../initializers' import { VideoModel } from '../../models/video/video' import { VideoCaptionModel } from '../../models/video/video-caption' import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' +import { CONFIG } from '../../initializers/config' type GetPathParam = { videoId: string, language: string } 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 @@ import { join } from 'path' -import { FILES_CACHE, CONFIG, STATIC_PATHS } from '../../initializers' +import { FILES_CACHE, STATIC_PATHS } from '../../initializers' import { VideoModel } from '../../models/video/video' import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' +import { CONFIG } from '../../initializers/config' class VideosPreviewCache extends AbstractVideoStaticFileCache { 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 @@ import { VideoModel } from '../models/video/video' import { basename, dirname, join } from 'path' -import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, sequelizeTypescript } from '../initializers' +import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, sequelizeTypescript } from '../initializers' import { close, ensureDir, move, open, outputJSON, pathExists, read, readFile, remove, writeFile } from 'fs-extra' import { getVideoFileSize } from '../helpers/ffmpeg-utils' import { sha256 } from '../helpers/core-utils' @@ -10,6 +10,7 @@ import { doRequest, doRequestAndSaveToFile } from '../helpers/requests' import { generateRandomString } from '../helpers/utils' import { flatten, uniq } from 'lodash' import { VideoFileModel } from '../models/video/video-file' +import { CONFIG } from '../initializers/config' async function updateStreamingPlaylistsInfohashesIfNeeded () { 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 @@ import * as Bull from 'bull' import { logger } from '../../../helpers/logger' -import { CONFIG, REMOTE_SCHEME, sequelizeTypescript } from '../../../initializers' +import { REMOTE_SCHEME, sequelizeTypescript, WEBSERVER } from '../../../initializers' import { sendFollow } from '../../activitypub/send' import { sanitizeHost } from '../../../helpers/core-utils' import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger' @@ -23,7 +23,7 @@ async function processActivityPubFollow (job: Bull.Job) { logger.info('Processing ActivityPub follow in job %d.', job.id) let targetActor: ActorModel - if (!host || host === CONFIG.WEBSERVER.HOST) { + if (!host || host === WEBSERVER.HOST) { targetActor = await ActorModel.loadLocalByName(payload.name) } else { 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' import { getDurationFromVideoFile, getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg-utils' import { extname, join } from 'path' import { VideoFileModel } from '../../../models/video/video-file' -import { CONFIG, PREVIEWS_SIZE, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_IMPORT_TIMEOUT } from '../../../initializers' +import { PREVIEWS_SIZE, sequelizeTypescript, THUMBNAILS_SIZE, VIDEO_IMPORT_TIMEOUT } from '../../../initializers' import { downloadImage } from '../../../helpers/requests' import { VideoState } from '../../../../shared' import { JobQueue } from '../index' @@ -14,8 +14,9 @@ import { federateVideoIfNeeded } from '../../activitypub' import { VideoModel } from '../../../models/video/video' import { downloadWebTorrentVideo } from '../../../helpers/webtorrent' import { getSecureTorrentName } from '../../../helpers/utils' -import { remove, move, stat } from 'fs-extra' +import { move, remove, stat } from 'fs-extra' import { Notifier } from '../../notifier' +import { CONFIG } from '../../../initializers/config' type VideoImportYoutubeDLPayload = { 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' import { JobQueue } from '../job-queue' import { federateVideoIfNeeded } from '../../activitypub' import { retryTransactionWrapper } from '../../../helpers/database-utils' -import { CONFIG, sequelizeTypescript } from '../../../initializers' +import { sequelizeTypescript } from '../../../initializers' import * as Bluebird from 'bluebird' import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils' import { generateHlsPlaylist, optimizeVideofile, transcodeOriginalVideofile } from '../../video-transcoding' import { Notifier } from '../../notifier' +import { CONFIG } from '../../../initializers/config' export type VideoTranscodingPayload = { 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' import { JobState, JobType } from '../../../shared/models' import { logger } from '../../helpers/logger' import { Redis } from '../redis' -import { CONFIG, JOB_ATTEMPTS, JOB_COMPLETED_LIFETIME, JOB_CONCURRENCY, JOB_TTL, REPEAT_JOBS } from '../../initializers' +import { JOB_ATTEMPTS, JOB_COMPLETED_LIFETIME, JOB_CONCURRENCY, JOB_TTL, REPEAT_JOBS, WEBSERVER } from '../../initializers' import { ActivitypubHttpBroadcastPayload, processActivityPubHttpBroadcast } from './handlers/activitypub-http-broadcast' import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './handlers/activitypub-http-fetcher' import { ActivitypubHttpUnicastPayload, processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast' @@ -68,7 +68,7 @@ class JobQueue { if (this.initialized === true) return this.initialized = true - this.jobRedisPrefix = 'bull-' + CONFIG.WEBSERVER.HOST + this.jobRedisPrefix = 'bull-' + WEBSERVER.HOST const queueOptions = { prefix: this.jobRedisPrefix, 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' import { VideoCommentModel } from '../models/video/video-comment' import { UserModel } from '../models/account/user' import { PeerTubeSocket } from './peertube-socket' -import { CONFIG } from '../initializers/constants' +import { CONFIG } from '../initializers/config' import { VideoPrivacy, VideoState } from '../../shared/models/videos' import { VideoAbuseModel } from '../models/video/video-abuse' import { 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' import { UserModel } from '../models/account/user' import { OAuthClientModel } from '../models/oauth/oauth-client' import { OAuthTokenModel } from '../models/oauth/oauth-token' -import { CONFIG, CACHE } from '../initializers/constants' +import { CACHE } from '../initializers/constants' import { Transaction } from 'sequelize' +import { CONFIG } from '../initializers/config' type TokenInfo = { accessToken: string, refreshToken: string, accessTokenExpiresAt: Date, refreshTokenExpiresAt: Date } let 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' import { logger } from '../helpers/logger' import { generateRandomString } from '../helpers/utils' import { - CONFIG, CONTACT_FORM_LIFETIME, USER_EMAIL_VERIFY_LIFETIME, USER_PASSWORD_RESET_LIFETIME, - VIDEO_VIEW_LIFETIME + VIDEO_VIEW_LIFETIME, + WEBSERVER } from '../initializers' +import { CONFIG } from '../initializers/config' type CachedRoute = { body: string, @@ -41,7 +42,7 @@ class Redis { this.client.auth(CONFIG.REDIS.AUTH) } - this.prefix = 'redis-' + CONFIG.WEBSERVER.HOST + '-' + this.prefix = 'redis-' + WEBSERVER.HOST + '-' } 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 @@ import { AbstractScheduler } from './abstract-scheduler' -import { CONFIG, HLS_REDUNDANCY_DIRECTORY, REDUNDANCY, VIDEO_IMPORT_TIMEOUT } from '../../initializers' +import { HLS_REDUNDANCY_DIRECTORY, REDUNDANCY, VIDEO_IMPORT_TIMEOUT, WEBSERVER } from '../../initializers' import { logger } from '../../helpers/logger' import { VideosRedundancy } from '../../../shared/models/redundancy' import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy' @@ -15,6 +15,7 @@ import { getOrCreateVideoAndAccountAndChannel } from '../activitypub' import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist' import { VideoModel } from '../../models/video/video' import { downloadPlaylistSegments } from '../hls' +import { CONFIG } from '../../initializers/config' type CandidateToDuplicate = { redundancy: VideosRedundancy, @@ -186,7 +187,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler { const createdModel = await VideoRedundancyModel.create({ expiresOn: this.buildNewExpiration(redundancy.minLifetime), url: getVideoCacheFileActivityPubUrl(file), - fileUrl: video.getVideoRedundancyUrl(file, CONFIG.WEBSERVER.URL), + fileUrl: video.getVideoRedundancyUrl(file, WEBSERVER.URL), strategy: redundancy.strategy, videoFileId: file.id, actorId: serverActor.id @@ -212,7 +213,7 @@ export class VideosRedundancyScheduler extends AbstractScheduler { const createdModel = await VideoRedundancyModel.create({ expiresOn: this.buildNewExpiration(redundancy.minLifetime), url: getVideoCacheStreamingPlaylistActivityPubUrl(video, playlist), - fileUrl: playlist.getVideoRedundancyUrl(CONFIG.WEBSERVER.URL), + fileUrl: playlist.getVideoRedundancyUrl(WEBSERVER.URL), strategy: redundancy.strategy, videoStreamingPlaylistId: playlist.id, 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 @@ import * as sequelize from 'sequelize' -import { CONFIG } from '../initializers/constants' +import { CONFIG } from '../initializers/config' import { VideoBlacklistType, UserRight } from '../../shared/models' import { VideoBlacklistModel } from '../models/video/video-blacklist' import { 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 @@ -import { CONFIG, HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION } from '../initializers' +import { HLS_STREAMING_PLAYLIST_DIRECTORY, P2P_MEDIA_LOADER_PEER_VERSION, WEBSERVER } from '../initializers' import { join } from 'path' import { getVideoFileFPS, transcode } from '../helpers/ffmpeg-utils' import { ensureDir, move, remove, stat } from 'fs-extra' @@ -9,6 +9,7 @@ import { VideoModel } from '../models/video/video' import { updateMasterHLSPlaylist, updateSha256Segments } from './hls' import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-playlist' import { VideoStreamingPlaylistType } from '../../shared/models/videos/video-streaming-playlist.type' +import { CONFIG } from '../initializers/config' async function optimizeVideofile (video: VideoModel, inputVideoFileArg?: VideoFileModel) { const videosDirectory = CONFIG.STORAGE.VIDEOS_DIR @@ -111,12 +112,12 @@ async function generateHlsPlaylist (video: VideoModel, resolution: VideoResoluti await updateMasterHLSPlaylist(video) await updateSha256Segments(video) - const playlistUrl = CONFIG.WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid) + const playlistUrl = WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsMasterPlaylistStaticPath(video.uuid) await VideoStreamingPlaylistModel.upsert({ videoId: video.id, playlistUrl, - segmentsSha256Url: CONFIG.WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid), + segmentsSha256Url: WEBSERVER.URL + VideoStreamingPlaylistModel.getHlsSha256SegmentsStaticPath(video.uuid), p2pMediaLoaderInfohashes: VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(playlistUrl, video.VideoFiles), p2pMediaLoaderPeerVersion: P2P_MEDIA_LOADER_PEER_VERSION, -- cgit v1.2.3