From 2a8df1dc3cc82392709573b0384ac72eb7ff9767 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Tue, 18 May 2021 18:06:11 +0200 Subject: [PATCH] Use peertubeHelpers.plugin methods when available: * getBaseStaticRoute use peertubeHelper when available * getBaseRouter renamed getBaseRouterRoute and use peertubeHelper when available * Backward compatibility is maintained. --- CHANGELOG.md | 4 ++++ server/lib/helpers.ts | 22 +++++++++++++++------- server/lib/prosody/config.ts | 4 ++-- server/lib/routers/settings.ts | 2 +- server/lib/routers/webchat.ts | 6 +++--- server/lib/settings.ts | 4 ++-- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9658d479..21795995 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ * Prosody log level will be the same as the Peertube's one. * Prosody log rotation every 24 hour. +### Peertube 3.2.0 + +* Use peertubeHelpers.plugin methods when available. Backward compatibility is maintained. + ### Fixes * Builtin Prosody: settings archive_expires_after was useless without mod_mam diff --git a/server/lib/helpers.ts b/server/lib/helpers.ts index cce42249..c0f4c3b9 100644 --- a/server/lib/helpers.ts +++ b/server/lib/helpers.ts @@ -11,13 +11,21 @@ if (!/^peertube-plugin-[-a-z]+$/.test(pluginName)) { } const pluginShortName = pluginName.substring('peertube-plugin-'.length) -// FIXME: in Peertube <= 3.1.0, PeertubeHelpers dont provide this function -function getBaseRouter (): string { - return '/plugins/' + pluginShortName + '/router/' +function getBaseRouterRoute (options: RegisterServerOptions): string { + // In Peertube <= 3.1.0, PeertubeHelpers dont provide this function + // Available in Peertube >= 3.2.0 + if (options.peertubeHelpers.plugin) { + return options.peertubeHelpers.plugin.getBaseRouterRoute() + } + return '/plugins/' + pluginShortName + '/' + version + '/router/' } -// FIXME: in Peertube <= 3.1.0, PeertubeHelpers dont provide this function -function getBaseStaticRoute (): string { +function getBaseStaticRoute (options: RegisterServerOptions): string { + // In Peertube <= 3.1.0, PeertubeHelpers dont provide this function. + // Available in Peertube >= 3.2.0 + if (options.peertubeHelpers.plugin) { + return options.peertubeHelpers.plugin.getBaseStaticRoute() + } return '/plugins/' + pluginShortName + '/' + version + '/static/' } @@ -49,7 +57,7 @@ async function getAuthUser (options: RegisterServerOptions, res: Response): Prom return res.locals.oauth?.token?.User } -// FIXME: Peertube <= 3.1.0 has no way to obtain user nickname/ +// Peertube <= 3.1.0 has no way to obtain user nickname/ // Peertube >= 3.2.0: getAuthUser has user.Account.name. async function getUserNickname (options: RegisterServerOptions, user: MUserDefault): Promise { const peertubeHelpers = options.peertubeHelpers @@ -101,7 +109,7 @@ async function getUserNickname (options: RegisterServerOptions, user: MUserDefau } export { - getBaseRouter, + getBaseRouterRoute, getBaseStaticRoute, isUserAdmin, getAuthUser, diff --git a/server/lib/prosody/config.ts b/server/lib/prosody/config.ts index 1837880f..8cd774aa 100644 --- a/server/lib/prosody/config.ts +++ b/server/lib/prosody/config.ts @@ -1,6 +1,6 @@ import * as fs from 'fs' import * as path from 'path' -import { pluginName, getBaseRouter } from '../helpers' +import { pluginName, getBaseRouterRoute } from '../helpers' import { ProsodyFilePaths } from './config/paths' import { ProsodyConfigContent } from './config/content' import { getProsodyDomain } from './config/domain' @@ -122,7 +122,7 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise { logger.info('Accessing peertube-plugin-livechat diagnostic tool.') - const src = getBaseStaticRoute() + 'settings/settings.js' + const src = getBaseStaticRoute(options) + 'settings/settings.js' res.status(200) res.type('html') res.send('
Loading...
') diff --git a/server/lib/routers/webchat.ts b/server/lib/routers/webchat.ts index f607219a..494c6103 100644 --- a/server/lib/routers/webchat.ts +++ b/server/lib/routers/webchat.ts @@ -1,6 +1,6 @@ import type { Router, RequestHandler, Request, Response, NextFunction } from 'express' import type { ProxyOptions } from 'express-http-proxy' -import { getBaseRouter } from '../helpers' +import { getBaseRouterRoute } from '../helpers' import { asyncMiddleware } from '../middlewares/async' import { getProsodyDomain } from '../prosody/config/domain' import * as path from 'path' @@ -41,10 +41,10 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise
Before asking for help, please use this diagnostic tool: -Launch diagnostic +Launch diagnostic
` }) registerSetting({