Use peertubeHelpers.plugin methods when available:

* getBaseStaticRoute use peertubeHelper when available
* getBaseRouter renamed getBaseRouterRoute and use peertubeHelper when available
* Backward compatibility is maintained.
This commit is contained in:
John Livingston 2021-05-18 18:06:11 +02:00
parent 4cf9ab51aa
commit 2a8df1dc3c
6 changed files with 27 additions and 15 deletions

View File

@ -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

View File

@ -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<string | undefined> {
const peertubeHelpers = options.peertubeHelpers
@ -101,7 +109,7 @@ async function getUserNickname (options: RegisterServerOptions, user: MUserDefau
}
export {
getBaseRouter,
getBaseRouterRoute,
getBaseStaticRoute,
isUserAdmin,
getAuthUser,

View File

@ -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<Prosod
const apikey = await getAPIKey(options)
const baseApiUrl = options.peertubeHelpers.config.getWebserverUrl() +
getBaseRouter() +
getBaseRouterRoute(options) +
'api/'
const authApiUrl = baseApiUrl + 'user' // FIXME: should be protected by apikey, but mod_auth_http cant handle params
const roomApiUrl = baseApiUrl + 'room?apikey=' + apikey + '&jid={room.jid|jid_node}'

View File

@ -11,7 +11,7 @@ async function initSettingsRouter (options: RegisterServerOptions): Promise<Rout
router.get('/diagnostic', asyncMiddleware(
async (req: Request, res: Response, _next: NextFunction) => {
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('<html><body><div>Loading...</div></body><script src="' + src + '"></script></html>')

View File

@ -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<Route
const prosodyDomain = await getProsodyDomain(options)
server = 'anon.' + prosodyDomain
room = '{{VIDEO_UUID}}@room.' + prosodyDomain
boshUri = getBaseRouter() + 'webchat/http-bind'
boshUri = getBaseRouterRoute(options) + 'webchat/http-bind'
wsUri = ''
authenticationUrl = options.peertubeHelpers.config.getWebserverUrl() +
getBaseRouter() +
getBaseRouterRoute(options) +
'api/auth'
advancedControls = true
} else if (settings['chat-use-builtin']) {

View File

@ -1,4 +1,4 @@
import { getBaseRouter } from './helpers'
import { getBaseRouterRoute } from './helpers'
import { ensureProsodyRunning, ensureProsodyNotRunning } from './prosody/ctl'
export function initSettings (options: RegisterServerOptions): void {
@ -49,7 +49,7 @@ There is 3 way to use it:
</ul>
<br>
Before asking for help, please use this diagnostic tool:
<a href="${getBaseRouter()}settings/diagnostic" target="_blank">Launch diagnostic</a>
<a href="${getBaseRouterRoute(options)}settings/diagnostic" target="_blank">Launch diagnostic</a>
<br>`
})
registerSetting({