From 10bbb7f04008071edb3efd140effa1f5f9a52522 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 2 Jun 2021 15:48:56 +0200 Subject: [PATCH] Remove backward compatibility (peertubeHelpers.plugin always available). --- server/@types/peertube.d.ts | 3 +-- server/lib/helpers.ts | 16 ++++++---------- server/lib/prosody/config.ts | 4 ++-- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/server/@types/peertube.d.ts b/server/@types/peertube.d.ts index 0e286a7b..b5596cee 100644 --- a/server/@types/peertube.d.ts +++ b/server/@types/peertube.d.ts @@ -150,8 +150,7 @@ interface PeerTubeHelpers { user: { getAuthUser: (res: express.Response) => Promise } - // Added in Peertube 3.2.0 - plugin?: { + plugin: { getBaseStaticRoute: () => string getBaseRouterRoute: () => string getDataDirectoryPath: () => string diff --git a/server/lib/helpers.ts b/server/lib/helpers.ts index 5a592802..b420af5a 100644 --- a/server/lib/helpers.ts +++ b/server/lib/helpers.ts @@ -12,21 +12,17 @@ if (!/^peertube-plugin-[-a-z]+$/.test(pluginName)) { const pluginShortName = pluginName.substring('peertube-plugin-'.length) 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() + if (!options.peertubeHelpers.plugin) { + throw new Error('Missing peertubeHelpers.plugin, have you the correct Peertube version?') } - return '/plugins/' + pluginShortName + '/' + version + '/router/' + return options.peertubeHelpers.plugin.getBaseRouterRoute() } 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() + if (!options.peertubeHelpers.plugin) { + throw new Error('Missing peertubeHelpers.plugin, have you the correct Peertube version?') } - return '/plugins/' + pluginShortName + '/' + version + '/static/' + return options.peertubeHelpers.plugin.getBaseStaticRoute() } async function isUserAdmin (options: RegisterServerOptions, res: Response): Promise { diff --git a/server/lib/prosody/config.ts b/server/lib/prosody/config.ts index 5ec4be49..75c96bf6 100644 --- a/server/lib/prosody/config.ts +++ b/server/lib/prosody/config.ts @@ -12,8 +12,8 @@ async function getWorkingDir (options: RegisterServerOptions): Promise { const logger = peertubeHelpers.logger logger.debug('Calling getWorkingDir') - if (!peertubeHelpers.plugin?.getDataDirectoryPath) { - throw new Error('Cant get the plugin Data Directory') + if (!peertubeHelpers.plugin) { + throw new Error('Missing peertubeHelpers.plugin, have you the correct Peertube version?') } const dir = path.resolve(peertubeHelpers.plugin.getDataDirectoryPath(), 'prosody') logger.debug('getWorkingDir will return the dir ' + dir)