From 9452d4fd3321148fb80b64a67bd9983fee6c208e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 6 Jul 2022 15:44:14 +0200 Subject: /!\ Use a dedicated config file for development It means you have to replace NODE_ENV=test to NODE_ENV=dev if you use it npm run dev:* commands are already updated --- server/controllers/api/oauth-clients.ts | 3 +- server/controllers/plugins.ts | 4 +- server/helpers/core-utils.ts | 9 +++ .../helpers/custom-validators/activitypub/misc.ts | 4 +- server/helpers/custom-validators/servers.ts | 6 +- server/initializers/checker-after-init.ts | 7 +- server/initializers/constants.ts | 81 ++++++++++++---------- server/initializers/database.ts | 8 +-- server/lib/client-html.ts | 4 +- server/lib/emailer.ts | 6 +- server/lib/job-queue/handlers/video-views-stats.ts | 4 +- server/lib/schedulers/actor-follow-scheduler.ts | 4 +- server/lib/schedulers/remove-old-jobs-scheduler.ts | 6 +- server/lib/views/shared/video-viewer-counters.ts | 4 +- server/lib/views/shared/video-viewer-stats.ts | 4 +- server/middlewares/validators/follows.ts | 6 +- server/middlewares/validators/oembed.ts | 4 +- 17 files changed, 91 insertions(+), 73 deletions(-) (limited to 'server') diff --git a/server/controllers/api/oauth-clients.ts b/server/controllers/api/oauth-clients.ts index 2d847bdc1..eb7942fd6 100644 --- a/server/controllers/api/oauth-clients.ts +++ b/server/controllers/api/oauth-clients.ts @@ -1,4 +1,5 @@ import express from 'express' +import { isTestOrDevInstance } from '@server/helpers/core-utils' import { OAuthClientModel } from '@server/models/oauth/oauth-client' import { HttpStatusCode, OAuthClientLocal } from '@shared/models' import { logger } from '../../helpers/logger' @@ -22,7 +23,7 @@ async function getLocalClient (req: express.Request, res: express.Response, next } // Don't make this check if this is a test instance - if (process.env.NODE_ENV !== 'test' && req.get('host') !== headerHostShouldBe) { + if (!isTestOrDevInstance() && req.get('host') !== headerHostShouldBe) { logger.info('Getting client tokens for host %s is forbidden (expected %s).', req.get('host'), headerHostShouldBe) return res.fail({ status: HttpStatusCode.FORBIDDEN_403, diff --git a/server/controllers/plugins.ts b/server/controllers/plugins.ts index 28fffc9e1..51db1ad89 100644 --- a/server/controllers/plugins.ts +++ b/server/controllers/plugins.ts @@ -5,7 +5,7 @@ import { optionalAuthenticate } from '@server/middlewares/auth' import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n' import { HttpStatusCode } from '../../shared/models/http/http-error-codes' import { PluginType } from '../../shared/models/plugins/plugin.type' -import { isTestInstance } from '../helpers/core-utils' +import { isProdInstance } from '../helpers/core-utils' import { PLUGIN_GLOBAL_CSS_PATH } from '../initializers/constants' import { PluginManager, RegisteredPlugin } from '../lib/plugins/plugin-manager' import { getExternalAuthValidator, getPluginValidator, pluginStaticDirectoryValidator } from '../middlewares/validators/plugins' @@ -13,7 +13,7 @@ import { serveThemeCSSValidator } from '../middlewares/validators/themes' const sendFileOptions = { maxAge: '30 days', - immutable: !isTestInstance() + immutable: isProdInstance() } const pluginsRouter = express.Router() diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts index 6ebe8e2ac..4bbf0228d 100644 --- a/server/helpers/core-utils.ts +++ b/server/helpers/core-utils.ts @@ -165,6 +165,14 @@ function isTestInstance () { return process.env.NODE_ENV === 'test' } +function isDevInstance () { + return process.env.NODE_ENV === 'dev' +} + +function isTestOrDevInstance () { + return isTestInstance() || isDevInstance() +} + function isProdInstance () { return process.env.NODE_ENV === 'production' } @@ -270,6 +278,7 @@ const pipelinePromise = promisify(pipeline) export { isTestInstance, + isTestOrDevInstance, isProdInstance, getAppNumber, diff --git a/server/helpers/custom-validators/activitypub/misc.ts b/server/helpers/custom-validators/activitypub/misc.ts index 9d823299f..ff15f115f 100644 --- a/server/helpers/custom-validators/activitypub/misc.ts +++ b/server/helpers/custom-validators/activitypub/misc.ts @@ -1,6 +1,6 @@ import validator from 'validator' import { CONSTRAINTS_FIELDS } from '../../../initializers/constants' -import { isTestInstance } from '../../core-utils' +import { isTestOrDevInstance } from '../../core-utils' import { exists } from '../misc' function isUrlValid (url: string) { @@ -13,7 +13,7 @@ function isUrlValid (url: string) { } // We validate 'localhost', so we don't have the top level domain - if (isTestInstance()) { + if (isTestOrDevInstance()) { isURLOptions.require_tld = false } diff --git a/server/helpers/custom-validators/servers.ts b/server/helpers/custom-validators/servers.ts index c0f8b6aeb..b9f45c282 100644 --- a/server/helpers/custom-validators/servers.ts +++ b/server/helpers/custom-validators/servers.ts @@ -1,7 +1,7 @@ import validator from 'validator' -import { exists, isArray } from './misc' -import { isTestInstance } from '../core-utils' import { CONSTRAINTS_FIELDS } from '../../initializers/constants' +import { isTestOrDevInstance } from '../core-utils' +import { exists, isArray } from './misc' function isHostValid (host: string) { const isURLOptions = { @@ -10,7 +10,7 @@ function isHostValid (host: string) { } // We validate 'localhost', so we don't have the top level domain - if (isTestInstance()) { + if (isTestOrDevInstance()) { isURLOptions.require_tld = false } diff --git a/server/initializers/checker-after-init.ts b/server/initializers/checker-after-init.ts index f65798c42..e542a5395 100644 --- a/server/initializers/checker-after-init.ts +++ b/server/initializers/checker-after-init.ts @@ -4,7 +4,7 @@ import { URL } from 'url' import { getFFmpegVersion } from '@server/helpers/ffmpeg' import { VideoRedundancyConfigFilter } from '@shared/models/redundancy/video-redundancy-config-filter.type' import { RecentlyAddedStrategy } from '../../shared/models/redundancy' -import { isProdInstance, isTestInstance, parseSemVersion } from '../helpers/core-utils' +import { isProdInstance, parseSemVersion } from '../helpers/core-utils' import { isArray } from '../helpers/custom-validators/misc' import { logger } from '../helpers/logger' import { ApplicationModel, getServerActor } from '../models/application/application' @@ -34,6 +34,9 @@ async function checkActivityPubUrls () { // Some checks on configuration files or throw if there is an error function checkConfig () { + const configFiles = config.util.getConfigSources().map(s => s.name).join(' -> ') + logger.info('Using following configuration file hierarchy: %s.', configFiles) + // Moved configuration keys if (config.has('services.csp-logger')) { logger.warn('services.csp-logger configuration has been renamed to csp.report_uri. Please update your configuration file.') @@ -128,7 +131,7 @@ function checkLocalRedundancyConfig () { } // Lifetime should not be < 10 hours - if (!isTestInstance() && r.minLifetime < 1000 * 3600 * 10) { + if (isProdInstance() && r.minLifetime < 1000 * 3600 * 10) { throw new Error('Video redundancy minimum lifetime should be >= 10 hours for strategy ' + r.strategy) } } diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index e3683269c..009f878fc 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -19,7 +19,7 @@ import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model' import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model' // Do not use barrels, remain constants as independent as possible -import { isTestInstance, parseDurationToMs, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' +import { isTestInstance, isTestOrDevInstance, parseDurationToMs, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' import { CONFIG, registerConfigChangedHandler } from './config' // --------------------------------------------------------------------------- @@ -822,57 +822,62 @@ const STATS_TIMESERIE = { // --------------------------------------------------------------------------- // Special constants for a test instance -if (isTestInstance() === true && process.env.PRODUCTION_CONSTANTS !== 'true') { - PRIVATE_RSA_KEY_SIZE = 1024 +if (process.env.PRODUCTION_CONSTANTS !== 'true') { + if (isTestOrDevInstance()) { + PRIVATE_RSA_KEY_SIZE = 1024 - ACTOR_FOLLOW_SCORE.BASE = 20 + ACTOR_FOLLOW_SCORE.BASE = 20 - REMOTE_SCHEME.HTTP = 'http' - REMOTE_SCHEME.WS = 'ws' + REMOTE_SCHEME.HTTP = 'http' + REMOTE_SCHEME.WS = 'ws' - STATIC_MAX_AGE.SERVER = '0' + STATIC_MAX_AGE.SERVER = '0' - ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2 - ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds - ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds - ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds + SCHEDULER_INTERVALS_MS.ACTOR_FOLLOW_SCORES = 1000 + SCHEDULER_INTERVALS_MS.REMOVE_OLD_JOBS = 10000 + SCHEDULER_INTERVALS_MS.REMOVE_OLD_HISTORY = 5000 + SCHEDULER_INTERVALS_MS.REMOVE_OLD_VIEWS = 5000 + SCHEDULER_INTERVALS_MS.UPDATE_VIDEOS = 5000 + SCHEDULER_INTERVALS_MS.AUTO_FOLLOW_INDEX_INSTANCES = 5000 + SCHEDULER_INTERVALS_MS.UPDATE_INBOX_STATS = 5000 + SCHEDULER_INTERVALS_MS.CHECK_PEERTUBE_VERSION = 2000 - CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max = 100 * 1024 // 100KB - CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max = 400 * 1024 // 400KB + REPEAT_JOBS['videos-views-stats'] = { every: 5000 } - SCHEDULER_INTERVALS_MS.ACTOR_FOLLOW_SCORES = 1000 - SCHEDULER_INTERVALS_MS.REMOVE_OLD_JOBS = 10000 - SCHEDULER_INTERVALS_MS.REMOVE_OLD_HISTORY = 5000 - SCHEDULER_INTERVALS_MS.REMOVE_OLD_VIEWS = 5000 - SCHEDULER_INTERVALS_MS.UPDATE_VIDEOS = 5000 - SCHEDULER_INTERVALS_MS.AUTO_FOLLOW_INDEX_INSTANCES = 5000 - SCHEDULER_INTERVALS_MS.UPDATE_INBOX_STATS = 5000 - SCHEDULER_INTERVALS_MS.CHECK_PEERTUBE_VERSION = 2000 + REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 } + AP_CLEANER.PERIOD = 5000 - REPEAT_JOBS['videos-views-stats'] = { every: 5000 } + REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1 - REPEAT_JOBS['activitypub-cleaner'] = { every: 5000 } - AP_CLEANER.PERIOD = 5000 + CONTACT_FORM_LIFETIME = 1000 // 1 second - REDUNDANCY.VIDEOS.RANDOMIZED_FACTOR = 1 + JOB_ATTEMPTS['email'] = 1 - VIEW_LIFETIME.VIEWER_COUNTER = 1000 * 5 // 5 second - VIEW_LIFETIME.VIEWER_STATS = 1000 * 5 // 5 second - CONTACT_FORM_LIFETIME = 1000 // 1 second + FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000 + MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000 + MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000 + OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2 - JOB_ATTEMPTS['email'] = 1 + PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000 + } + + if (isTestInstance()) { + ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE = 2 + ACTIVITY_PUB.ACTOR_REFRESH_INTERVAL = 10 * 1000 // 10 seconds + ACTIVITY_PUB.VIDEO_REFRESH_INTERVAL = 10 * 1000 // 10 seconds + ACTIVITY_PUB.VIDEO_PLAYLIST_REFRESH_INTERVAL = 10 * 1000 // 10 seconds - FILES_CACHE.VIDEO_CAPTIONS.MAX_AGE = 3000 - MEMOIZE_TTL.OVERVIEWS_SAMPLE = 3000 - MEMOIZE_TTL.LIVE_ABLE_TO_UPLOAD = 3000 - OVERVIEWS.VIDEOS.SAMPLE_THRESHOLD = 2 + CONSTRAINTS_FIELDS.ACTORS.IMAGE.FILE_SIZE.max = 100 * 1024 // 100KB + CONSTRAINTS_FIELDS.VIDEOS.IMAGE.FILE_SIZE.max = 400 * 1024 // 400KB - PLUGIN_EXTERNAL_AUTH_TOKEN_LIFETIME = 5000 + VIEW_LIFETIME.VIEWER_COUNTER = 1000 * 5 // 5 second + VIEW_LIFETIME.VIEWER_STATS = 1000 * 5 // 5 second - VIDEO_LIVE.CLEANUP_DELAY = getIntEnv('PEERTUBE_TEST_CONSTANTS_VIDEO_LIVE_CLEANUP_DELAY') ?? 5000 - VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY = 2 - VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY = 1 - VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1 + VIDEO_LIVE.CLEANUP_DELAY = getIntEnv('PEERTUBE_TEST_CONSTANTS_VIDEO_LIVE_CLEANUP_DELAY') ?? 5000 + VIDEO_LIVE.SEGMENT_TIME_SECONDS.DEFAULT_LATENCY = 2 + VIDEO_LIVE.SEGMENT_TIME_SECONDS.SMALL_LATENCY = 1 + VIDEO_LIVE.EDGE_LIVE_DELAY_SEGMENTS_NOTIFICATION = 1 + } } updateWebserverUrls() diff --git a/server/initializers/database.ts b/server/initializers/database.ts index 09786a91f..91286241b 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts @@ -8,9 +8,10 @@ import { UserNotificationModel } from '@server/models/user/user-notification' import { UserVideoHistoryModel } from '@server/models/user/user-video-history' import { VideoJobInfoModel } from '@server/models/video/video-job-info' import { VideoLiveSessionModel } from '@server/models/video/video-live-session' +import { VideoSourceModel } from '@server/models/video/video-source' import { LocalVideoViewerModel } from '@server/models/view/local-video-viewer' import { LocalVideoViewerWatchSectionModel } from '@server/models/view/local-video-viewer-watch-section' -import { isTestInstance } from '../helpers/core-utils' +import { isTestOrDevInstance } from '../helpers/core-utils' import { logger } from '../helpers/logger' import { AbuseModel } from '../models/abuse/abuse' import { AbuseMessageModel } from '../models/abuse/abuse-message' @@ -49,7 +50,6 @@ import { VideoStreamingPlaylistModel } from '../models/video/video-streaming-pla import { VideoTagModel } from '../models/video/video-tag' import { VideoViewModel } from '../models/view/video-view' import { CONFIG } from './config' -import { VideoSourceModel } from '@server/models/video/video-source' require('pg').defaults.parseInt8 = true // Avoid BIGINT to be converted to string @@ -81,13 +81,13 @@ const sequelizeTypescript = new SequelizeTypescript({ pool: { max: poolMax }, - benchmark: isTestInstance(), + benchmark: isTestOrDevInstance(), isolationLevel: Transaction.ISOLATION_LEVELS.SERIALIZABLE, logging: (message: string, benchmark: number) => { if (process.env.NODE_DB_LOG === 'false') return let newMessage = 'Executed SQL request' - if (isTestInstance() === true && benchmark !== undefined) { + if (isTestOrDevInstance() === true && benchmark !== undefined) { newMessage += ' in ' + benchmark + 'ms' } diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index 1e8d03023..899d80c15 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts @@ -2,6 +2,7 @@ import express from 'express' import { readFile } from 'fs-extra' import { join } from 'path' import validator from 'validator' +import { isTestOrDevInstance } from '@server/helpers/core-utils' import { toCompleteUUID } from '@server/helpers/custom-validators/misc' import { mdToOneLinePlainText } from '@server/helpers/markdown' import { ActorImageModel } from '@server/models/actor/actor-image' @@ -30,7 +31,6 @@ import { MAccountActor, MChannelActor } from '../types/models' import { getActivityStreamDuration } from './activitypub/activity' import { getBiggestActorImage } from './actor-image' import { ServerConfigManager } from './server-config-manager' -import { isTestInstance } from '@server/helpers/core-utils' type Tags = { ogType: string @@ -234,7 +234,7 @@ class ClientHtml { const path = ClientHtml.getEmbedPath() // Disable HTML cache in dev mode because webpack can regenerate JS files - if (!isTestInstance() && ClientHtml.htmlCache[path]) { + if (!isTestOrDevInstance() && ClientHtml.htmlCache[path]) { return ClientHtml.htmlCache[path] } diff --git a/server/lib/emailer.ts b/server/lib/emailer.ts index edc99057c..42d7650dd 100644 --- a/server/lib/emailer.ts +++ b/server/lib/emailer.ts @@ -2,10 +2,10 @@ import { readFileSync } from 'fs-extra' import { isArray, merge } from 'lodash' import { createTransport, Transporter } from 'nodemailer' import { join } from 'path' +import { root } from '@shared/core-utils' import { EmailPayload } from '@shared/models' import { SendEmailDefaultOptions } from '../../shared/models/server/emailer.model' -import { isTestInstance } from '../helpers/core-utils' -import { root } from '@shared/core-utils' +import { isTestOrDevInstance } from '../helpers/core-utils' import { bunyanLogger, logger } from '../helpers/logger' import { CONFIG, isEmailEnabled } from '../initializers/config' import { WEBSERVER } from '../initializers/constants' @@ -29,7 +29,7 @@ class Emailer { this.initialized = true if (!isEmailEnabled()) { - if (!isTestInstance()) { + if (!isTestOrDevInstance()) { logger.error('Cannot use SMTP server because of lack of configuration. PeerTube will not be able to send mails!') } diff --git a/server/lib/job-queue/handlers/video-views-stats.ts b/server/lib/job-queue/handlers/video-views-stats.ts index 689a5a3b4..c9aa218e5 100644 --- a/server/lib/job-queue/handlers/video-views-stats.ts +++ b/server/lib/job-queue/handlers/video-views-stats.ts @@ -1,5 +1,5 @@ import { VideoViewModel } from '@server/models/view/video-view' -import { isTestInstance } from '../../../helpers/core-utils' +import { isTestOrDevInstance } from '../../../helpers/core-utils' import { logger } from '../../../helpers/logger' import { VideoModel } from '../../../models/video/video' import { Redis } from '../../redis' @@ -8,7 +8,7 @@ async function processVideosViewsStats () { const lastHour = new Date() // In test mode, we run this function multiple times per hour, so we don't want the values of the previous hour - if (!isTestInstance()) lastHour.setHours(lastHour.getHours() - 1) + if (!isTestOrDevInstance()) lastHour.setHours(lastHour.getHours() - 1) const hour = lastHour.getHours() const startDate = lastHour.setMinutes(0, 0, 0) diff --git a/server/lib/schedulers/actor-follow-scheduler.ts b/server/lib/schedulers/actor-follow-scheduler.ts index 560f97f3e..e1c56c135 100644 --- a/server/lib/schedulers/actor-follow-scheduler.ts +++ b/server/lib/schedulers/actor-follow-scheduler.ts @@ -1,4 +1,4 @@ -import { isTestInstance } from '../../helpers/core-utils' +import { isTestOrDevInstance } from '../../helpers/core-utils' import { logger } from '../../helpers/logger' import { ACTOR_FOLLOW_SCORE, SCHEDULER_INTERVALS_MS } from '../../initializers/constants' import { ActorFollowModel } from '../../models/actor/actor-follow' @@ -39,7 +39,7 @@ export class ActorFollowScheduler extends AbstractScheduler { } private async removeBadActorFollows () { - if (!isTestInstance()) logger.info('Removing bad actor follows (scheduler).') + if (!isTestOrDevInstance()) logger.info('Removing bad actor follows (scheduler).') try { await ActorFollowModel.removeBadActorFollows() diff --git a/server/lib/schedulers/remove-old-jobs-scheduler.ts b/server/lib/schedulers/remove-old-jobs-scheduler.ts index dffef3542..879846999 100644 --- a/server/lib/schedulers/remove-old-jobs-scheduler.ts +++ b/server/lib/schedulers/remove-old-jobs-scheduler.ts @@ -1,8 +1,8 @@ -import { isTestInstance } from '../../helpers/core-utils' +import { isTestOrDevInstance } from '../../helpers/core-utils' import { logger } from '../../helpers/logger' +import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' import { JobQueue } from '../job-queue' import { AbstractScheduler } from './abstract-scheduler' -import { SCHEDULER_INTERVALS_MS } from '../../initializers/constants' export class RemoveOldJobsScheduler extends AbstractScheduler { @@ -15,7 +15,7 @@ export class RemoveOldJobsScheduler extends AbstractScheduler { } protected internalExecute () { - if (!isTestInstance()) logger.info('Removing old jobs in scheduler.') + if (!isTestOrDevInstance()) logger.info('Removing old jobs in scheduler.') return JobQueue.Instance.removeOldJobs() } diff --git a/server/lib/views/shared/video-viewer-counters.ts b/server/lib/views/shared/video-viewer-counters.ts index cf3fa5882..f851ce050 100644 --- a/server/lib/views/shared/video-viewer-counters.ts +++ b/server/lib/views/shared/video-viewer-counters.ts @@ -1,4 +1,4 @@ -import { isTestInstance } from '@server/helpers/core-utils' +import { isTestOrDevInstance } from '@server/helpers/core-utils' import { logger, loggerTagsFactory } from '@server/helpers/logger' import { VIEW_LIFETIME } from '@server/initializers/constants' import { sendView } from '@server/lib/activitypub/send/send-view' @@ -117,7 +117,7 @@ export class VideoViewerCounters { if (this.processingViewerCounters) return this.processingViewerCounters = true - if (!isTestInstance()) logger.info('Cleaning video viewers.', lTags()) + if (!isTestOrDevInstance()) logger.info('Cleaning video viewers.', lTags()) try { for (const videoId of this.viewersPerVideo.keys()) { diff --git a/server/lib/views/shared/video-viewer-stats.ts b/server/lib/views/shared/video-viewer-stats.ts index a56c20559..542bd51cf 100644 --- a/server/lib/views/shared/video-viewer-stats.ts +++ b/server/lib/views/shared/video-viewer-stats.ts @@ -1,5 +1,5 @@ import { Transaction } from 'sequelize/types' -import { isTestInstance } from '@server/helpers/core-utils' +import { isTestOrDevInstance } from '@server/helpers/core-utils' import { GeoIP } from '@server/helpers/geo-ip' import { logger, loggerTagsFactory } from '@server/helpers/logger' import { MAX_LOCAL_VIEWER_WATCH_SECTIONS, VIEW_LIFETIME } from '@server/initializers/constants' @@ -118,7 +118,7 @@ export class VideoViewerStats { if (this.processingViewersStats) return this.processingViewersStats = true - if (!isTestInstance()) logger.info('Processing viewer statistics.', lTags()) + if (!isTestOrDevInstance()) logger.info('Processing viewer statistics.', lTags()) const now = new Date().getTime() diff --git a/server/middlewares/validators/follows.ts b/server/middlewares/validators/follows.ts index df4cefe28..86d2d6228 100644 --- a/server/middlewares/validators/follows.ts +++ b/server/middlewares/validators/follows.ts @@ -1,12 +1,13 @@ import express from 'express' import { body, param, query } from 'express-validator' +import { isProdInstance } from '@server/helpers/core-utils' import { isEachUniqueHandleValid, isFollowStateValid, isRemoteHandleValid } from '@server/helpers/custom-validators/follows' import { loadActorUrlOrGetFromWebfinger } from '@server/lib/activitypub/actors' import { getRemoteNameAndHost } from '@server/lib/activitypub/follow' import { getServerActor } from '@server/models/application/application' import { MActorFollowActorsDefault } from '@server/types/models' +import { ServerFollowCreate } from '@shared/models' import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' -import { isTestInstance } from '../../helpers/core-utils' import { isActorTypeValid, isValidActorHandle } from '../../helpers/custom-validators/activitypub/actor' import { isEachUniqueHostValid, isHostValid } from '../../helpers/custom-validators/servers' import { logger } from '../../helpers/logger' @@ -14,7 +15,6 @@ import { WEBSERVER } from '../../initializers/constants' import { ActorModel } from '../../models/actor/actor' import { ActorFollowModel } from '../../models/actor/actor-follow' import { areValidationErrors } from './shared' -import { ServerFollowCreate } from '@shared/models' const listFollowsValidator = [ query('state') @@ -42,7 +42,7 @@ const followValidator = [ (req: express.Request, res: express.Response, next: express.NextFunction) => { // Force https if the administrator wants to follow remote actors - if (isTestInstance() === false && WEBSERVER.SCHEME === 'http') { + if (isProdInstance() && WEBSERVER.SCHEME === 'http') { return res .status(HttpStatusCode.INTERNAL_SERVER_ERROR_500) .json({ diff --git a/server/middlewares/validators/oembed.ts b/server/middlewares/validators/oembed.ts index fc1a294e0..8e7b44a86 100644 --- a/server/middlewares/validators/oembed.ts +++ b/server/middlewares/validators/oembed.ts @@ -5,7 +5,7 @@ import { loadVideo } from '@server/lib/model-loaders' import { VideoPlaylistModel } from '@server/models/video/video-playlist' import { VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' -import { isTestInstance } from '../../helpers/core-utils' +import { isTestOrDevInstance } from '../../helpers/core-utils' import { isIdOrUUIDValid, isUUIDValid, toCompleteUUID } from '../../helpers/custom-validators/misc' import { logger } from '../../helpers/logger' import { WEBSERVER } from '../../initializers/constants' @@ -34,7 +34,7 @@ const isURLOptions = { } // We validate 'localhost', so we don't have the top level domain -if (isTestInstance()) { +if (isTestOrDevInstance()) { isURLOptions.require_tld = false } -- cgit v1.2.3