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/models/account/account.ts | 4 ++-- server/models/activitypub/actor.ts | 6 +++--- server/models/avatar/avatar.ts | 3 ++- server/models/redundancy/video-redundancy.ts | 3 ++- server/models/video/video-caption.ts | 3 ++- server/models/video/video-channel.ts | 7 ++++--- server/models/video/video-comment.ts | 4 ++-- server/models/video/video-format-utils.ts | 4 ++-- server/models/video/video-playlist.ts | 7 ++++--- server/models/video/video.ts | 22 ++++++++++++---------- 10 files changed, 35 insertions(+), 28 deletions(-) (limited to 'server/models') 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' import { VideoChannelModel } from '../video/video-channel' import { VideoCommentModel } from '../video/video-comment' import { UserModel } from './user' -import { CONFIG } from '../../initializers' import { AvatarModel } from '../avatar/avatar' import { VideoPlaylistModel } from '../video/video-playlist' +import { WEBSERVER } from '../../initializers/constants' export enum ScopeNames { SUMMARY = 'SUMMARY' @@ -199,7 +199,7 @@ export class AccountModel extends Model { static loadByNameWithHost (nameWithHost: string) { const [ accountName, host ] = nameWithHost.split('@') - if (!host || host === CONFIG.WEBSERVER.HOST) return AccountModel.loadLocalByName(accountName) + if (!host || host === WEBSERVER.HOST) return AccountModel.loadLocalByName(accountName) return AccountModel.loadByNameAndHost(accountName, host) } 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 { isActorPublicKeyValid } from '../../helpers/custom-validators/activitypub/actor' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' -import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' +import { ACTIVITY_PUB, ACTIVITY_PUB_ACTOR_TYPES, CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers' import { AccountModel } from '../account/account' import { AvatarModel } from '../avatar/avatar' import { ServerModel } from '../server/server' @@ -516,7 +516,7 @@ export class ActorModel extends Model { } getHost () { - return this.Server ? this.Server.host : CONFIG.WEBSERVER.HOST + return this.Server ? this.Server.host : WEBSERVER.HOST } getRedundancyAllowed () { @@ -526,7 +526,7 @@ export class ActorModel extends Model { getAvatarUrl () { if (!this.avatarId) return undefined - return CONFIG.WEBSERVER.URL + this.Avatar.getWebserverPath() + return WEBSERVER.URL + this.Avatar.getWebserverPath() } 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 @@ import { join } from 'path' import { AfterDestroy, AllowNull, Column, CreatedAt, Model, Table, UpdatedAt } from 'sequelize-typescript' import { Avatar } from '../../../shared/models/avatars/avatar.model' -import { CONFIG, STATIC_PATHS } from '../../initializers' +import { STATIC_PATHS } from '../../initializers' import { logger } from '../../helpers/logger' import { remove } from 'fs-extra' +import { CONFIG } from '../../initializers/config' @Table({ 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 { import { ActorModel } from '../activitypub/actor' import { getVideoSort, throwIfNotValid } from '../utils' import { isActivityPubUrlValid, isUrlValid } from '../../helpers/custom-validators/activitypub/misc' -import { CONFIG, CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers' +import { CONSTRAINTS_FIELDS, MIMETYPES } from '../../initializers' import { VideoFileModel } from '../video/video-file' import { getServerActor } from '../../helpers/utils' import { VideoModel } from '../video/video' @@ -29,6 +29,7 @@ import { isTestInstance } from '../../helpers/core-utils' import * as Bluebird from 'bluebird' import * as Sequelize from 'sequelize' import { VideoStreamingPlaylistModel } from '../video/video-streaming-playlist' +import { CONFIG } from '../../initializers/config' export enum ScopeNames { 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' import { VideoModel } from './video' import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions' import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model' -import { CONFIG, STATIC_PATHS, VIDEO_LANGUAGES } from '../../initializers' +import { STATIC_PATHS, VIDEO_LANGUAGES } from '../../initializers' import { join } from 'path' import { logger } from '../../helpers/logger' import { remove } from 'fs-extra' +import { CONFIG } from '../../initializers/config' export enum ScopeNames { 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 { Default, DefaultScope, ForeignKey, - HasMany, IFindOptions, + HasMany, + IFindOptions, Is, Model, Scopes, @@ -28,7 +29,7 @@ import { AccountModel, ScopeNames as AccountModelScopeNames } from '../account/a import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor' import { buildServerIdsFollowedBy, buildTrigramSearchIndex, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' -import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' +import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers' import { ServerModel } from '../server/server' import { DefineIndexesOptions } from 'sequelize' import { AvatarModel } from '../avatar/avatar' @@ -419,7 +420,7 @@ export class VideoChannelModel extends Model { static loadByNameWithHostAndPopulateAccount (nameWithHost: string) { const [ name, host ] = nameWithHost.split('@') - if (!host || host === CONFIG.WEBSERVER.HOST) return VideoChannelModel.loadLocalByNameAndPopulateAccount(name) + if (!host || host === WEBSERVER.HOST) return VideoChannelModel.loadLocalByNameAndPopulateAccount(name) return VideoChannelModel.loadByNameAndHostAndPopulateAccount(name, host) } 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 import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' import { VideoComment } from '../../../shared/models/videos/video-comment.model' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' -import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers' +import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers' import { sendDeleteVideoComment } from '../../lib/activitypub/send' import { AccountModel } from '../account/account' import { ActorModel } from '../activitypub/actor' @@ -482,7 +482,7 @@ export class VideoCommentModel extends Model { let result: string[] = [] const localMention = `@(${actorNameAlphabet}+)` - const remoteMention = `${localMention}@${CONFIG.WEBSERVER.HOST}` + const remoteMention = `${localMention}@${WEBSERVER.HOST}` const mentionRegex = this.isOwned() ? '(?:(?:' + 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 { ActivityUrlObject, VideoTorrentObject } from '../../../shared/models/activitypub/objects' -import { CONFIG, MIMETYPES, THUMBNAILS_SIZE } from '../../initializers' +import { MIMETYPES, THUMBNAILS_SIZE, WEBSERVER } from '../../initializers' import { VideoCaptionModel } from './video-caption' import { getVideoCommentsActivityPubUrl, @@ -290,7 +290,7 @@ function videoModelToActivityPubObject (video: VideoModel): VideoTorrentObject { type: 'Link', mimeType: 'text/html', mediaType: 'text/html', - href: CONFIG.WEBSERVER.URL + '/videos/watch/' + video.uuid + href: WEBSERVER.URL + '/videos/watch/' + video.uuid }) 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 { import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { ACTIVITY_PUB, - CONFIG, CONSTRAINTS_FIELDS, STATIC_PATHS, THUMBNAILS_SIZE, VIDEO_PLAYLIST_PRIVACIES, - VIDEO_PLAYLIST_TYPES + VIDEO_PLAYLIST_TYPES, + WEBSERVER } from '../../initializers' import { VideoPlaylist } from '../../../shared/models/videos/playlist/video-playlist.model' import { AccountModel, ScopeNames as AccountScopeNames } from '../account/account' @@ -43,6 +43,7 @@ import { activityPubCollectionPagination } from '../../helpers/activitypub' import { remove } from 'fs-extra' import { logger } from '../../helpers/logger' import { VideoPlaylistType } from '../../../shared/models/videos/playlist/video-playlist-type.model' +import { CONFIG } from '../../initializers/config' enum ScopeNames { AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', @@ -417,7 +418,7 @@ export class VideoPlaylistModel extends Model { } getThumbnailUrl () { - return CONFIG.WEBSERVER.URL + STATIC_PATHS.THUMBNAILS + this.getThumbnailName() + return WEBSERVER.URL + STATIC_PATHS.THUMBNAILS + this.getThumbnailName() } 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' import { ACTIVITY_PUB, API_VERSION, - CONFIG, CONSTRAINTS_FIELDS, - HLS_STREAMING_PLAYLIST_DIRECTORY, HLS_REDUNDANCY_DIRECTORY, + HLS_STREAMING_PLAYLIST_DIRECTORY, PREVIEWS_SIZE, REMOTE_SCHEME, STATIC_DOWNLOAD_PATHS, @@ -64,7 +63,8 @@ import { VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES, - VIDEO_STATES + VIDEO_STATES, + WEBSERVER } from '../../initializers' import { sendDeleteVideo } from '../../lib/activitypub/send' import { AccountModel } from '../account/account' @@ -77,12 +77,13 @@ import { buildTrigramSearchIndex, buildWhereIdOrUUID, createSimilarityAttribute, - getVideoSort, isOutdated, + getVideoSort, + isOutdated, throwIfNotValid } from '../utils' import { TagModel } from './tag' import { VideoAbuseModel } from './video-abuse' -import { VideoChannelModel, ScopeNames as VideoChannelScopeNames } from './video-channel' +import { ScopeNames as VideoChannelScopeNames, VideoChannelModel } from './video-channel' import { VideoCommentModel } from './video-comment' import { VideoFileModel } from './video-file' import { VideoShareModel } from './video-share' @@ -105,6 +106,7 @@ import { UserModel } from '../account/user' import { VideoImportModel } from './video-import' import { VideoStreamingPlaylistModel } from './video-streaming-playlist' import { VideoPlaylistElementModel } from './video-playlist-element' +import { CONFIG } from '../../initializers/config' // FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation const indexes: Sequelize.DefineIndexesOptions[] = [ @@ -1664,10 +1666,10 @@ export class VideoModel extends Model { name: `${this.name} ${videoFile.resolution}p${videoFile.extname}`, createdBy: 'PeerTube', announceList: [ - [ CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + '/tracker/socket' ], - [ CONFIG.WEBSERVER.URL + '/tracker/announce' ] + [ WEBSERVER.WS + '://' + WEBSERVER.HOSTNAME + ':' + WEBSERVER.PORT + '/tracker/socket' ], + [ WEBSERVER.URL + '/tracker/announce' ] ], - urlList: [ CONFIG.WEBSERVER.URL + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) ] + urlList: [ WEBSERVER.URL + STATIC_PATHS.WEBSEED + this.getVideoFilename(videoFile) ] } const torrent = await createTorrentPromise(this.getVideoFilePath(videoFile), options) @@ -1781,8 +1783,8 @@ export class VideoModel extends Model { let baseUrlWs if (this.isOwned()) { - baseUrlHttp = CONFIG.WEBSERVER.URL - baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT + baseUrlHttp = WEBSERVER.URL + baseUrlWs = WEBSERVER.WS + '://' + WEBSERVER.HOSTNAME + ':' + WEBSERVER.PORT } else { baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + this.VideoChannel.Account.Actor.Server.host baseUrlWs = REMOTE_SCHEME.WS + '://' + this.VideoChannel.Account.Actor.Server.host -- cgit v1.2.3