From b4dabfeeb920c7f27e6529010eef6611f3461cfa Mon Sep 17 00:00:00 2001 From: John Livingston Date: Thu, 13 Apr 2023 15:41:46 +0200 Subject: [PATCH] New debug mode: Debug mode is no more triggered by the NODE_ENV value, but by testing the existance of a file in the plugin data directory. --- CHANGELOG.md | 1 + server/lib/debug.ts | 19 +++++++++++++++++++ server/lib/diagnostic/backend.ts | 2 +- server/lib/diagnostic/debug.ts | 12 ++++++++++++ server/lib/diagnostic/index.ts | 3 +++ server/lib/diagnostic/utils.ts | 2 +- server/lib/prosody/ctl.ts | 2 +- server/lib/prosody/logrotate.ts | 6 ++++-- .../content/contributing/develop/_index.de.md | 13 +++++++++++++ .../content/contributing/develop/_index.en.md | 13 +++++++++++++ .../content/contributing/develop/_index.fr.md | 14 ++++++++++++++ 11 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 server/lib/debug.ts create mode 100644 server/lib/diagnostic/debug.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index e64cabe1..02c8a67f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Minor changes and fixes * Diagnostic tool: add the result of `prosodyctl check` in the debug section. +* New debug mode ## 6.2.3 diff --git a/server/lib/debug.ts b/server/lib/debug.ts new file mode 100644 index 00000000..10408939 --- /dev/null +++ b/server/lib/debug.ts @@ -0,0 +1,19 @@ +import type { RegisterServerOptions } from '@peertube/peertube-types' +import * as path from 'path' +import * as fs from 'fs' + +export function isDebugMode (options: RegisterServerOptions): boolean { + const peertubeHelpers = options.peertubeHelpers + const logger = peertubeHelpers.logger + + if (!peertubeHelpers.plugin) { + return false + } + const filepath = path.resolve(peertubeHelpers.plugin.getDataDirectoryPath(), 'debug_mode') + logger.debug('Testing debug mode by testing if file exists: ' + filepath) + if (fs.existsSync(filepath)) { + logger.info('Plugin livechat Debug mode is on.') + return true + } + return false +} diff --git a/server/lib/diagnostic/backend.ts b/server/lib/diagnostic/backend.ts index d3500e88..19ec75d8 100644 --- a/server/lib/diagnostic/backend.ts +++ b/server/lib/diagnostic/backend.ts @@ -5,6 +5,6 @@ export async function diagBackend (test: string, _options: RegisterServerOptions const result = newResult(test) result.label = 'Backend connection' result.ok = true - result.next = 'webchat-video' + result.next = 'debug' return result } diff --git a/server/lib/diagnostic/debug.ts b/server/lib/diagnostic/debug.ts new file mode 100644 index 00000000..91bb16d8 --- /dev/null +++ b/server/lib/diagnostic/debug.ts @@ -0,0 +1,12 @@ +import type { RegisterServerOptions } from '@peertube/peertube-types' +import { newResult, TestResult } from './utils' +import { isDebugMode } from '../../lib/debug' + +export async function diagDebug (test: string, options: RegisterServerOptions): Promise { + const result = newResult(test) + result.label = 'Test debug mode' + result.ok = true + result.messages = [isDebugMode(options) ? 'Debug mode is ON' : 'Debug mode is OFF'] + result.next = 'webchat-video' + return result +} diff --git a/server/lib/diagnostic/index.ts b/server/lib/diagnostic/index.ts index 60fe3bf1..56a3ae06 100644 --- a/server/lib/diagnostic/index.ts +++ b/server/lib/diagnostic/index.ts @@ -1,6 +1,7 @@ import type { RegisterServerOptions } from '@peertube/peertube-types' import { diagBackend } from './backend' import { TestResult, newResult } from './utils' +import { diagDebug } from './debug' import { diagProsody } from './prosody' import { diagVideo } from './video' @@ -9,6 +10,8 @@ export async function diag (test: string, options: RegisterServerOptions): Promi if (test === 'backend') { result = await diagBackend(test, options) + } else if (test === 'debug') { + result = await diagDebug(test, options) } else if (test === 'webchat-video') { result = await diagVideo(test, options) } else if (test === 'prosody') { diff --git a/server/lib/diagnostic/utils.ts b/server/lib/diagnostic/utils.ts index 105de414..a7ccbbaa 100644 --- a/server/lib/diagnostic/utils.ts +++ b/server/lib/diagnostic/utils.ts @@ -1,4 +1,4 @@ -type nextValue = 'backend' | 'webchat-video' | 'prosody' +type nextValue = 'backend' | 'debug' | 'webchat-video' | 'prosody' interface MessageWithLevel { level: 'info' | 'warning' | 'error' diff --git a/server/lib/prosody/ctl.ts b/server/lib/prosody/ctl.ts index 10103543..9a1b36e5 100644 --- a/server/lib/prosody/ctl.ts +++ b/server/lib/prosody/ctl.ts @@ -347,7 +347,7 @@ async function ensureProsodyRunning (options: RegisterServerOptions): Promise { diff --git a/server/lib/prosody/logrotate.ts b/server/lib/prosody/logrotate.ts index 4eb3abf6..e5e6f464 100644 --- a/server/lib/prosody/logrotate.ts +++ b/server/lib/prosody/logrotate.ts @@ -1,5 +1,6 @@ import type { RegisterServerOptions } from '@peertube/peertube-types' import type { ProsodyFilePaths } from './config/paths' +import { isDebugMode } from '../debug' type Rotate = (file: string, options: { count?: number @@ -32,8 +33,9 @@ async function _rotate (options: RegisterServerOptions, path: string): Promise