From ad8b71b58238d10d67356c9b40aed051f1f7a053 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Thu, 6 Jul 2023 16:39:32 +0200 Subject: [PATCH] New debug modes for AP/RSS publishing. --- server/lib/debug.ts | 18 ++++++++++++++++-- server/lib/federation/outgoing.ts | 4 +++- server/lib/rss/init.ts | 9 +++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/server/lib/debug.ts b/server/lib/debug.ts index c032ede5..5bfbe83d 100644 --- a/server/lib/debug.ts +++ b/server/lib/debug.ts @@ -15,6 +15,8 @@ interface DebugContent { logRotateEvery?: number remoteServerInfosMaxAge?: number prosodyDebuggerOptions?: ProsodyDebuggerOptions + alwaysPublishXMPPRoom?: boolean + enablePodcastChatTagForNonLive?: boolean } type DebugNumericValue = 'renewCertCheckInterval' @@ -23,6 +25,8 @@ type DebugNumericValue = 'renewCertCheckInterval' | 'logRotateCheckInterval' | 'remoteServerInfosMaxAge' +type DebugBooleanValue = 'alwaysPublishXMPPRoom' | 'enablePodcastChatTagForNonLive' + let debugContent: DebugContent | null | false = null function _readDebugFile (options: RegisterServerOptions): DebugContent | false { if (debugContent !== null) { return debugContent } @@ -55,6 +59,8 @@ function _readDebugFile (options: RegisterServerOptions): DebugContent | false { debugContent.renewCertCheckInterval = _getNumericOptions(options, json, 'renew_cert_check_interval') debugContent.renewSelfSignedCertInterval = _getNumericOptions(options, json, 'renew_self_signed_cert_interval') debugContent.remoteServerInfosMaxAge = _getNumericOptions(options, json, 'remote_server_infos_max_age') + debugContent.alwaysPublishXMPPRoom = json.always_publish_xmpp_room === true + debugContent.enablePodcastChatTagForNonLive = json.enable_podcast_chat_tag_for_nonlive === true } catch (err) { logger.error('Failed to read the debug_mode file content:', err) } @@ -100,11 +106,19 @@ function unloadDebugMode (): void { /** * Check if debug mode is enabled * @param options server options + * @param feature optional feature name. + * Returns true only if the debug_mode file contains a key with that name, and that is true. * @returns true if debug mode enabled */ -function isDebugMode (options: RegisterServerOptions): boolean { +function isDebugMode (options: RegisterServerOptions, feature?: DebugBooleanValue): boolean { const debugContent = _readDebugFile(options) - return !!debugContent + if (!debugContent) { + return false + } + if (!feature) { + return true + } + return debugContent[feature] === true } /** diff --git a/server/lib/federation/outgoing.ts b/server/lib/federation/outgoing.ts index 721532c8..cbf14d1b 100644 --- a/server/lib/federation/outgoing.ts +++ b/server/lib/federation/outgoing.ts @@ -13,6 +13,7 @@ import { canonicalizePluginUri } from '../uri/canonicalize' import { getProsodyDomain } from '../prosody/config/domain' import { fillVideoCustomFields } from '../custom-fields' import { loc } from '../loc' +import { isDebugMode } from '../debug' /** * This function adds LiveChat information on video ActivityPub data if relevant. @@ -99,7 +100,8 @@ async function videoBuildJSONLD ( // - prosody-room-allow-s2s // - prosody-s2s-port // For now, this can be tested reading serverInfos.directs2s - if (serverInfos.directs2s) { + // There is a debug_mode flag to always enable it. + if (!!serverInfos.directs2s || isDebugMode(options, 'alwaysPublishXMPPRoom')) { discussionLinks.push({ type: 'Link', name: chatTitle, diff --git a/server/lib/rss/init.ts b/server/lib/rss/init.ts index 037b3fe1..72ce9047 100644 --- a/server/lib/rss/init.ts +++ b/server/lib/rss/init.ts @@ -4,6 +4,7 @@ import { videoHasWebchat } from '../../../shared/lib/video' import { fillVideoCustomFields } from '../custom-fields' import { getProsodyDomain } from '../prosody/config/domain' import { getPublicChatUri } from '../uri/webchat' +import { isDebugMode } from '../debug' async function initRSS (options: RegisterServerOptions): Promise { const logger = options.peertubeHelpers.logger @@ -15,7 +16,7 @@ async function initRSS (options: RegisterServerOptions): Promise { handler: async ( result: CustomTag[], { video, liveItem }: { video: Video, liveItem: boolean } ): Promise => { - if (!liveItem) { + if (!liveItem && !isDebugMode(options, 'enablePodcastChatTagForNonLive')) { // Note: the Podcast RSS feed specification does not handle chats for non-live. // So we just return here. return result @@ -67,7 +68,11 @@ async function initRSS (options: RegisterServerOptions): Promise { // In order to connect to the chat using standard xmpp, it requires these settings: // - prosody-room-allow-s2s // - prosody-s2s-port - if (settings['prosody-room-allow-s2s'] && settings['prosody-s2s-port']) { + // Or there is a special debug_mode option + if ( + (settings['prosody-room-allow-s2s'] && settings['prosody-s2s-port']) || + isDebugMode(options, 'alwaysPublishXMPPRoom') + ) { let roomJID: string if (settings['prosody-room-type'] === 'channel') { roomJID = `channel.${video.channel.id}@room.${prosodyDomain}`