2024-05-23 09:42:14 +00:00
|
|
|
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-09-06 13:56:55 +00:00
|
|
|
import type { RegisterServerOptions } from '@peertube/peertube-types'
|
|
|
|
import type { Request, Response, NextFunction } from 'express'
|
|
|
|
import type { RequestPromiseHandler } from '../async'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a middleware handler to check if advanced configuration is not disabled
|
|
|
|
* @param options Peertube server options
|
|
|
|
* @returns middleware function
|
|
|
|
*/
|
|
|
|
function checkConfigurationEnabledMiddleware (options: RegisterServerOptions): RequestPromiseHandler {
|
|
|
|
return async (req: Request, res: Response, next: NextFunction) => {
|
|
|
|
const settings = await options.settingsManager.getSettings([
|
2023-09-18 16:53:07 +00:00
|
|
|
'disable-channel-configuration'
|
2023-09-06 13:56:55 +00:00
|
|
|
])
|
2023-09-18 16:53:07 +00:00
|
|
|
if (!settings['disable-channel-configuration']) {
|
2023-09-06 13:56:55 +00:00
|
|
|
next()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
options.peertubeHelpers.logger.info('Advanced Configuration is disabled, blocking the request.')
|
|
|
|
res.sendStatus(403)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
checkConfigurationEnabledMiddleware
|
|
|
|
}
|