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 level will be the same as the Peertube's one.
* Prosody log rotation every 24 hour. * Prosody log rotation every 24 hour.
### Peertube 3.2.0
* Use peertubeHelpers.plugin methods when available. Backward compatibility is maintained.
### Fixes ### Fixes
* Builtin Prosody: settings archive_expires_after was useless without mod_mam * 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) const pluginShortName = pluginName.substring('peertube-plugin-'.length)
// FIXME: in Peertube <= 3.1.0, PeertubeHelpers dont provide this function function getBaseRouterRoute (options: RegisterServerOptions): string {
function getBaseRouter (): string { // In Peertube <= 3.1.0, PeertubeHelpers dont provide this function
return '/plugins/' + pluginShortName + '/router/' // 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 (options: RegisterServerOptions): string {
function getBaseStaticRoute (): 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/' return '/plugins/' + pluginShortName + '/' + version + '/static/'
} }
@ -49,7 +57,7 @@ async function getAuthUser (options: RegisterServerOptions, res: Response): Prom
return res.locals.oauth?.token?.User 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. // Peertube >= 3.2.0: getAuthUser has user.Account.name.
async function getUserNickname (options: RegisterServerOptions, user: MUserDefault): Promise<string | undefined> { async function getUserNickname (options: RegisterServerOptions, user: MUserDefault): Promise<string | undefined> {
const peertubeHelpers = options.peertubeHelpers const peertubeHelpers = options.peertubeHelpers
@ -101,7 +109,7 @@ async function getUserNickname (options: RegisterServerOptions, user: MUserDefau
} }
export { export {
getBaseRouter, getBaseRouterRoute,
getBaseStaticRoute, getBaseStaticRoute,
isUserAdmin, isUserAdmin,
getAuthUser, getAuthUser,

View File

@ -1,6 +1,6 @@
import * as fs from 'fs' import * as fs from 'fs'
import * as path from 'path' import * as path from 'path'
import { pluginName, getBaseRouter } from '../helpers' import { pluginName, getBaseRouterRoute } from '../helpers'
import { ProsodyFilePaths } from './config/paths' import { ProsodyFilePaths } from './config/paths'
import { ProsodyConfigContent } from './config/content' import { ProsodyConfigContent } from './config/content'
import { getProsodyDomain } from './config/domain' import { getProsodyDomain } from './config/domain'
@ -122,7 +122,7 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
const apikey = await getAPIKey(options) const apikey = await getAPIKey(options)
const baseApiUrl = options.peertubeHelpers.config.getWebserverUrl() + const baseApiUrl = options.peertubeHelpers.config.getWebserverUrl() +
getBaseRouter() + getBaseRouterRoute(options) +
'api/' 'api/'
const authApiUrl = baseApiUrl + 'user' // FIXME: should be protected by apikey, but mod_auth_http cant handle params 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}' 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( router.get('/diagnostic', asyncMiddleware(
async (req: Request, res: Response, _next: NextFunction) => { async (req: Request, res: Response, _next: NextFunction) => {
logger.info('Accessing peertube-plugin-livechat diagnostic tool.') 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.status(200)
res.type('html') res.type('html')
res.send('<html><body><div>Loading...</div></body><script src="' + src + '"></script></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 { Router, RequestHandler, Request, Response, NextFunction } from 'express'
import type { ProxyOptions } from 'express-http-proxy' import type { ProxyOptions } from 'express-http-proxy'
import { getBaseRouter } from '../helpers' import { getBaseRouterRoute } from '../helpers'
import { asyncMiddleware } from '../middlewares/async' import { asyncMiddleware } from '../middlewares/async'
import { getProsodyDomain } from '../prosody/config/domain' import { getProsodyDomain } from '../prosody/config/domain'
import * as path from 'path' import * as path from 'path'
@ -41,10 +41,10 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
const prosodyDomain = await getProsodyDomain(options) const prosodyDomain = await getProsodyDomain(options)
server = 'anon.' + prosodyDomain server = 'anon.' + prosodyDomain
room = '{{VIDEO_UUID}}@room.' + prosodyDomain room = '{{VIDEO_UUID}}@room.' + prosodyDomain
boshUri = getBaseRouter() + 'webchat/http-bind' boshUri = getBaseRouterRoute(options) + 'webchat/http-bind'
wsUri = '' wsUri = ''
authenticationUrl = options.peertubeHelpers.config.getWebserverUrl() + authenticationUrl = options.peertubeHelpers.config.getWebserverUrl() +
getBaseRouter() + getBaseRouterRoute(options) +
'api/auth' 'api/auth'
advancedControls = true advancedControls = true
} else if (settings['chat-use-builtin']) { } 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' import { ensureProsodyRunning, ensureProsodyNotRunning } from './prosody/ctl'
export function initSettings (options: RegisterServerOptions): void { export function initSettings (options: RegisterServerOptions): void {
@ -49,7 +49,7 @@ There is 3 way to use it:
</ul> </ul>
<br> <br>
Before asking for help, please use this diagnostic tool: 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>` <br>`
}) })
registerSetting({ registerSetting({