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 --- .github/CONTRIBUTING.md | 2 +- config/dev.yaml | 105 +++++++++++++++++++++ config/test.yaml | 22 ----- scripts/dev/client.sh | 6 +- scripts/dev/embed.sh | 4 +- scripts/dev/index.sh | 2 +- scripts/dev/server.sh | 2 +- server.ts | 4 +- 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 +- support/doc/plugins/guide.md | 2 +- 26 files changed, 207 insertions(+), 106 deletions(-) create mode 100644 config/dev.yaml diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 4bc590bde..e8570dd2b 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -216,7 +216,7 @@ Instance configurations are in `config/test-{1,2,3}.yaml`. To test emails with PeerTube: * Run [mailslurper](http://mailslurper.com/) - * Run PeerTube using mailslurper SMTP port: `NODE_CONFIG='{ "smtp": { "hostname": "localhost", "port": 2500, "tls": false } }' NODE_ENV=test npm start` + * Run PeerTube using mailslurper SMTP port: `NODE_CONFIG='{ "smtp": { "hostname": "localhost", "port": 2500, "tls": false } }' NODE_ENV=dev node dist/server` ## Plugins & Themes diff --git a/config/dev.yaml b/config/dev.yaml new file mode 100644 index 000000000..15e239b29 --- /dev/null +++ b/config/dev.yaml @@ -0,0 +1,105 @@ +listen: + hostname: '::' + port: 9000 + +webserver: + https: false + +database: + hostname: 'localhost' + port: 5432 + +redis: + hostname: 'localhost' + +smtp: + hostname: null + port: 1025 + tls: false + disable_starttls: true + from_address: 'test-admin@localhost' + username: null + password: null + +log: + level: 'debug' + +contact_form: + enabled: true + +peertube: + check_latest_version: + enabled: false + +redundancy: + videos: + check_interval: '5 minutes' + strategies: + - + size: '1000MB' + min_lifetime: '10 minutes' + strategy: 'most-views' + - + size: '1000MB' + min_lifetime: '10 minutes' + strategy: 'trending' + - + size: '1000MB' + min_lifetime: '10 minutes' + strategy: 'recently-added' + min_views: 1 + +cache: + previews: + size: 10 + captions: + size: 10 + torrents: + size: 10 + +signup: + enabled: true + requires_email_verification: false + +live: + enabled: true + + allow_replay: true + + transcoding: + enabled: true + threads: 2 + + resolutions: + 360p: true + 720p: true + +import: + videos: + concurrency: 2 + http: + enabled: true + torrent: + enabled: true + +instance: + default_nsfw_policy: 'display' + +plugins: + index: + check_latest_versions_interval: '10 minutes' + +federation: + videos: + cleanup_remote_interactions: false + +views: + videos: + remote: + max_age: -1 + +geo_ip: + enabled: true + +video_studio: + enabled: true diff --git a/config/test.yaml b/config/test.yaml index 8118c479b..3e08f0ac8 100644 --- a/config/test.yaml +++ b/config/test.yaml @@ -133,28 +133,6 @@ plugins: index: check_latest_versions_interval: '10 minutes' -search: - # Add ability to fetch remote videos/actors by their URI, that may not be federated with your instance - # If enabled, the associated group will be able to "escape" from the instance follows - # That means they will be able to follow channels, watch videos, list videos of non followed instances - remote_uri: - users: true - anonymous: false - - # Use a third party index instead of your local index, only for search results - # Useful to discover content outside of your instance - search_index: - enabled: false - # URL of the search index, that should use the same search API and routes - # than PeerTube: https://docs.joinpeertube.org/api-rest-reference.html - # You should deploy your own with https://framagit.org/framasoft/peertube/search-index, - # and can use https://search.joinpeertube.org/ for tests, but keep in mind the latter is an unmoderated search index - url: 'http://localhost:3234' - # You can disable local search, so users only use the search index - disable_local_search: false - # If you did not disable local search, you can decide to use the search index by default - is_default_search: true - federation: videos: federate_unlisted: true diff --git a/scripts/dev/client.sh b/scripts/dev/client.sh index 1846f9a7d..92e8bb6ac 100755 --- a/scripts/dev/client.sh +++ b/scripts/dev/client.sh @@ -9,12 +9,12 @@ if [ ! -z ${2+x} ] && [ "$2" = "--ar-locale" ]; then fi clientCommand="cd client && node --max_old_space_size=4096 node_modules/.bin/ng serve --proxy-config proxy.config.json --hmr --configuration $clientConfiguration --host 0.0.0.0 --disable-host-check --port 3000" -serverCommand="npm run build:server && NODE_ENV=test node dist/server" +serverCommand="npm run build:server && NODE_ENV=dev node dist/server" if [ ! -z ${1+x} ] && [ "$1" = "--skip-server" ]; then - NODE_ENV=test eval $clientCommand + eval $clientCommand else - NODE_ENV=test node node_modules/.bin/concurrently -k \ + node node_modules/.bin/concurrently -k \ "$clientCommand" \ "$serverCommand" fi diff --git a/scripts/dev/embed.sh b/scripts/dev/embed.sh index b4835604e..e694950e6 100755 --- a/scripts/dev/embed.sh +++ b/scripts/dev/embed.sh @@ -2,6 +2,6 @@ set -eu -NODE_ENV=test npm run concurrently -- -k \ +npm run concurrently -- -k \ "cd client && npm run webpack -- --config webpack/webpack.video-embed.js --mode development --watch" \ - "npm run build:server && NODE_ENV=test npm start" + "npm run build:server && NODE_ENV=dev npm start" diff --git a/scripts/dev/index.sh b/scripts/dev/index.sh index beb88606f..7e0332115 100755 --- a/scripts/dev/index.sh +++ b/scripts/dev/index.sh @@ -2,6 +2,6 @@ set -eu -NODE_ENV=test npm run concurrently -- -k \ +npm run concurrently -- -k \ "sh scripts/dev/client.sh --skip-server ${1:-}" \ "sh scripts/dev/server.sh --skip-client" diff --git a/scripts/dev/server.sh b/scripts/dev/server.sh index 9dae43a63..c52c5124c 100755 --- a/scripts/dev/server.sh +++ b/scripts/dev/server.sh @@ -22,4 +22,4 @@ npm run resolve-tspaths:server cp -r ./server/static ./server/assets ./dist/server cp -r "./server/lib/emails" "./dist/server/lib" -./node_modules/.bin/tsc-watch --build --preserveWatchOutput --verbose --onSuccess 'sh -c "npm run resolve-tspaths:server && NODE_ENV=test node dist/server"' +./node_modules/.bin/tsc-watch --build --preserveWatchOutput --verbose --onSuccess 'sh -c "npm run resolve-tspaths:server && NODE_ENV=dev node dist/server"' diff --git a/server.ts b/server.ts index 73b7441f9..7ab20643b 100644 --- a/server.ts +++ b/server.ts @@ -134,7 +134,7 @@ import { HttpStatusCode } from './shared/models/http/http-error-codes' import { VideosTorrentCache } from '@server/lib/files-cache/videos-torrent-cache' import { ServerConfigManager } from '@server/lib/server-config-manager' import { VideoViewsManager } from '@server/lib/views/video-views-manager' -import { isTestInstance } from './server/helpers/core-utils' +import { isTestOrDevInstance } from './server/helpers/core-utils' import { OpenTelemetryMetrics } from '@server/lib/opentelemetry/metrics' // ----------- Command line ----------- @@ -148,7 +148,7 @@ cli // ----------- App ----------- // Enable CORS for develop -if (isTestInstance()) { +if (isTestOrDevInstance()) { app.use(cors({ origin: '*', exposedHeaders: 'Retry-After', 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 } diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md index e460f214e..e567e6c1b 100644 --- a/support/doc/plugins/guide.md +++ b/support/doc/plugins/guide.md @@ -1036,7 +1036,7 @@ $ npm run setup:cli * Run PeerTube (you can access to your instance on http://localhost:9000): ``` -$ NODE_ENV=test npm start +$ NODE_ENV=dev npm start ``` * Register the instance via the CLI: -- cgit v1.2.3