Initializing a diagnostic tools. WIP
This commit is contained in:
parent
8b3763761b
commit
59cd78ee82
1
client/settings.ts
Normal file
1
client/settings.ts
Normal file
@ -0,0 +1 @@
|
||||
// TODO: launch test one by one, using authent Bearer.
|
@ -69,7 +69,8 @@
|
||||
"staticDirs": {
|
||||
"static": "dist/client/static",
|
||||
"conversejs": "dist/client/conversejs/",
|
||||
"images": "dist/client/images/"
|
||||
"images": "dist/client/images/",
|
||||
"settings": "dist/client/settings"
|
||||
},
|
||||
"translations": {
|
||||
"fr-FR": "./languages/fr.json"
|
||||
|
25
server/lib/helpers.ts
Normal file
25
server/lib/helpers.ts
Normal file
@ -0,0 +1,25 @@
|
||||
const packagejson: any = require('../../../package.json')
|
||||
const version: string = packagejson.version || ''
|
||||
if (!/^\d+\.\d+\.\d+/.test(version)) {
|
||||
throw new Error('Incorrect version in package.json.')
|
||||
}
|
||||
const name: string = packagejson.name || ''
|
||||
if (!/^peertube-plugin-[-a-z]+$/.test(name)) {
|
||||
throw new Error('Incorrect plugin name in package.json.')
|
||||
}
|
||||
const shortName = name.substring('peertube-plugin-'.length)
|
||||
|
||||
// FIXME: in Peertube <= 3.1.0, PeertubeHelpers dont provide this function
|
||||
function getBaseRouter (): string {
|
||||
return '/plugins/' + shortName + '/router/'
|
||||
}
|
||||
|
||||
// FIXME: in Peertube <= 3.1.0, PeertubeHelpers dont provide this function
|
||||
function getBaseStaticRoute (): string {
|
||||
return '/plugins/' + shortName + '/' + version + '/static/'
|
||||
}
|
||||
|
||||
export {
|
||||
getBaseRouter,
|
||||
getBaseStaticRoute
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import type { NextFunction, Request, Response } from 'express'
|
||||
import { initWebchatRouter } from './webchat'
|
||||
import { initSettingsRouter } from './settings'
|
||||
|
||||
async function initRouters (options: RegisterServerOptions): Promise<void> {
|
||||
const { getRouter } = options
|
||||
@ -8,6 +9,7 @@ async function initRouters (options: RegisterServerOptions): Promise<void> {
|
||||
router.get('/ping', (req: Request, res: Response, _next: NextFunction) => res.json({ message: 'pong' }))
|
||||
|
||||
router.use('/webchat', await initWebchatRouter(options))
|
||||
router.use('/settings', await initSettingsRouter(options))
|
||||
}
|
||||
|
||||
export {
|
||||
|
52
server/lib/routers/settings.ts
Normal file
52
server/lib/routers/settings.ts
Normal file
@ -0,0 +1,52 @@
|
||||
import type { Router, Request, Response, NextFunction } from 'express'
|
||||
import { getBaseStaticRoute } from '../helpers'
|
||||
|
||||
async function initSettingsRouter ({
|
||||
peertubeHelpers,
|
||||
getRouter
|
||||
}: RegisterServerOptions): Promise<Router> {
|
||||
const router = getRouter()
|
||||
const logger = peertubeHelpers.logger
|
||||
|
||||
router.get('/diagnostic', async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
logger.info('Accessing peertube-plugin-livechat diagnostic tool.')
|
||||
const src = getBaseStaticRoute() + 'settings/settings.js'
|
||||
res.status(200)
|
||||
res.type('html')
|
||||
res.send('<html><body><div>Loading...</div></body><script src="' + src + '"></script></html>')
|
||||
} catch (error) {
|
||||
return next(error)
|
||||
}
|
||||
})
|
||||
|
||||
router.post('/diagnostic/test', async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
if (!res.locals.authenticated) {
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
// FIXME: test that user is admin.
|
||||
logger.error('FIXME: test that user is admin')
|
||||
|
||||
const test: string = req.body.test || ''
|
||||
logger.info('Accessing peertube-plugin-livechat diagnostic tool, test "' + test + '".')
|
||||
const result: any = {
|
||||
test: test,
|
||||
message: null,
|
||||
next: null,
|
||||
ok: false
|
||||
}
|
||||
|
||||
res.status(200)
|
||||
res.json(result)
|
||||
} catch (error) {
|
||||
return next(error)
|
||||
}
|
||||
})
|
||||
|
||||
return router
|
||||
}
|
||||
|
||||
export {
|
||||
initSettingsRouter
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
interface InitSettingsOptions {
|
||||
registerSetting: (options: RegisterServerSettingOptions) => void
|
||||
}
|
||||
import { getBaseRouter } from './helpers'
|
||||
|
||||
export function initSettings ({
|
||||
registerSetting
|
||||
}: InitSettingsOptions): void {
|
||||
}: RegisterServerOptions): void {
|
||||
registerSetting({
|
||||
name: 'chat-auto-display',
|
||||
label: 'Automatically open the chat',
|
||||
@ -54,6 +52,18 @@ export function initSettings ({
|
||||
private: false
|
||||
})
|
||||
|
||||
registerSetting({
|
||||
name: 'chat-use-prosody',
|
||||
label: 'Use builtin Prosody XMPP Server',
|
||||
type: 'input-checkbox',
|
||||
// /!\ dont auto-activate on existing settups. FIXME: how to do this?
|
||||
default: false, // TODO: set to true when peertube has fixed https://github.com/Chocobozzz/PeerTube/issues/3838
|
||||
private: false,
|
||||
descriptionHTML: 'If checked, this will use a builtin XMPP server. This is the recommanded setup.<br>' +
|
||||
'TODO: add link to documentation.<br>' +
|
||||
'<a href="' + getBaseRouter() + 'settings/diagnostic" target="_blank">Launch diagnostic</a>.<br>'
|
||||
})
|
||||
|
||||
registerSetting({
|
||||
name: 'chat-use-builtin',
|
||||
label: 'Use builtin ConverseJS',
|
||||
|
@ -37,4 +37,23 @@ config.push({
|
||||
}
|
||||
})
|
||||
|
||||
config.push({
|
||||
entry: "./client/settings.ts",
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
use: 'ts-loader'
|
||||
}
|
||||
]
|
||||
},
|
||||
resolve: {
|
||||
extensions: [ '.tsx', '.ts', '.js' ],
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, "./dist/client/settings"),
|
||||
filename: "./settings.js"
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = config
|
||||
|
Loading…
x
Reference in New Issue
Block a user