Adding asyncMiddleware.
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import type { Router, Request, Response, NextFunction } from 'express'
|
||||
import { videoHasWebchat } from '../../../shared/lib/video'
|
||||
import { asyncMiddleware } from '../middlewares/async'
|
||||
|
||||
// See here for description: https://modules.prosody.im/mod_muc_http_defaults.html
|
||||
interface RoomDefaults {
|
||||
@ -30,8 +31,8 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
||||
const router = getRouter()
|
||||
const logger = peertubeHelpers.logger
|
||||
|
||||
router.get('/room', async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
router.get('/room', asyncMiddleware(
|
||||
async (req: Request, res: Response, _next: NextFunction) => {
|
||||
const jid: string = req.query.jid as string || ''
|
||||
logger.info(`Requesting room information for room '${jid}'.`)
|
||||
|
||||
@ -69,10 +70,8 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
||||
affiliations: [] // so that the first user will not be moderator/admin
|
||||
}
|
||||
res.json(roomDefaults)
|
||||
} catch (error) {
|
||||
next(error)
|
||||
}
|
||||
})
|
||||
))
|
||||
|
||||
return router
|
||||
}
|
||||
|
@ -1,31 +1,32 @@
|
||||
import type { Router, Request, Response, NextFunction } from 'express'
|
||||
import { diag } from '../diagnostic'
|
||||
import { getBaseStaticRoute, isUserAdmin } from '../helpers'
|
||||
import { asyncMiddleware } from '../middlewares/async'
|
||||
|
||||
async function initSettingsRouter (options: RegisterServerOptions): Promise<Router> {
|
||||
const { peertubeHelpers, getRouter } = options
|
||||
const router = getRouter()
|
||||
const logger = peertubeHelpers.logger
|
||||
|
||||
router.get('/diagnostic', async (req: Request, res: Response, next: NextFunction) => {
|
||||
try {
|
||||
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'
|
||||
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 {
|
||||
router.post('/diagnostic/test', asyncMiddleware(
|
||||
async (req: Request, res: Response, _next: NextFunction) => {
|
||||
if (!res.locals.authenticated) {
|
||||
return res.sendStatus(403)
|
||||
res.sendStatus(403)
|
||||
return
|
||||
}
|
||||
if (!isUserAdmin(res)) {
|
||||
return res.sendStatus(403)
|
||||
res.sendStatus(403)
|
||||
return
|
||||
}
|
||||
|
||||
const test: string = req.body.test || ''
|
||||
@ -35,10 +36,8 @@ async function initSettingsRouter (options: RegisterServerOptions): Promise<Rout
|
||||
|
||||
res.status(200)
|
||||
res.json(result)
|
||||
} catch (error) {
|
||||
return next(error)
|
||||
}
|
||||
})
|
||||
))
|
||||
|
||||
return router
|
||||
}
|
||||
|
Reference in New Issue
Block a user