Initializing a diagnostic tools. WIP

This commit is contained in:
John Livingston
2021-04-09 21:28:16 +02:00
parent 8b3763761b
commit 59cd78ee82
7 changed files with 115 additions and 5 deletions

View File

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

View 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
}