ActivityPub-federated video streaming platform using P2P directly in your web browser
Check API search invalid config
Chocobozzz38e04969df75
diff --git a/packages/tests/src/api/check-params/config.ts b/packages/tests/src/api/check-params/config.tsindex 7e33e565fc..aeec3df350 100644--- a/packages/tests/src/api/check-params/config.ts+++ b/packages/tests/src/api/check-params/config.ts@@ -13,6 +13,7 @@ import {setAccessTokensToServers} from '@peertube/peertube-server-commands'import merge from 'lodash-es/merge.js'+import { DeepPartial } from '../../../../typescript-utils/src/types.js'describe('Test config API validators', function () {const path = '/api/v1/config/custom'@@ -185,6 +186,32 @@ describe('Test config API validators', function () {})})+ it('Should fail with an invalid search configuration', async function () {+ const newUpdateParams = merge(+ {},+ {},+ updateParams,+ {+ search: {+ remoteUri: {+ users: false+ },+ searchIndex: {+ enabled: true+ }+ }+ } satisfies DeepPartial<CustomConfig>+ )++ await makePutBodyRequest({+ url: server.url,+ path,+ fields: newUpdateParams,+ token: server.accessToken,+ expectedStatus: HttpStatusCode.BAD_REQUEST_400+ })+ })+it('Should succeed with the correct parameters', async function () {await makePutBodyRequest({url: server.url,diff --git a/server/core/middlewares/validators/config.ts b/server/core/middlewares/validators/config.tsindex 29e1dcd3cf..e47e331297 100644--- a/server/core/middlewares/validators/config.ts+++ b/server/core/middlewares/validators/config.ts@@ -153,11 +153,12 @@ export const customConfigUpdateValidator = [(req: express.Request, res: express.Response, next: express.NextFunction) => {if (areValidationErrors(req, res)) return- if (!checkInvalidConfigIfEmailDisabled(req.body, res)) return- if (!checkInvalidTranscodingConfig(req.body, res)) return- if (!checkInvalidSynchronizationConfig(req.body, res)) return- if (!checkInvalidLiveConfig(req.body, res)) return- if (!checkInvalidVideoStudioConfig(req.body, res)) return+ if (!checkInvalidConfigIfEmailDisabled(req.body, req, res)) return+ if (!checkInvalidTranscodingConfig(req.body, req, res)) return+ if (!checkInvalidSynchronizationConfig(req.body, req, res)) return+ if (!checkInvalidLiveConfig(req.body, req, res)) return+ if (!checkInvalidVideoStudioConfig(req.body, req, res)) return+ if (!checkInvalidSearchConfig(req.body, req, res)) returnreturn next()}@@ -167,7 +168,7 @@ export function ensureConfigIsEditable (req: express.Request, res: express.Respoif (!CONFIG.WEBADMIN.CONFIGURATION.EDITION.ALLOWED) {return res.fail({status: HttpStatusCode.METHOD_NOT_ALLOWED_405,- message: 'Server configuration is static and cannot be edited'+ message: req.t('Server configuration is static and cannot be edited')})}@@ -191,52 +192,63 @@ export const updateInstanceLogoValidator = updateActorImageValidatorFactory('log// Private// ----------------------------------------------------------------------------function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, res: express.Response) {+function checkInvalidConfigIfEmailDisabled (customConfig: CustomConfig, req: express.Request, res: express.Response) {if (isEmailEnabled()) return trueif (customConfig.signup.requiresEmailVerification === true) {- res.fail({ message: 'SMTP is not configured but you require signup email verification.' })+ res.fail({ message: req.t('SMTP is not configured but you require signup email verification.') })return false}return true}-function checkInvalidTranscodingConfig (customConfig: CustomConfig, res: express.Response) {+function checkInvalidTranscodingConfig (customConfig: CustomConfig, req: express.Request, res: express.Response) {if (customConfig.transcoding.enabled === false) return trueif (customConfig.transcoding.webVideos.enabled === false && customConfig.transcoding.hls.enabled === false) {- res.fail({ message: 'You need to enable at least web_videos transcoding or hls transcoding' })+ res.fail({ message: req.t('You need to enable at least web_videos transcoding or hls transcoding') })return false}return true}-function checkInvalidSynchronizationConfig (customConfig: CustomConfig, res: express.Response) {+function checkInvalidSynchronizationConfig (customConfig: CustomConfig, req: express.Request, res: express.Response) {if (customConfig.import.videoChannelSynchronization.enabled && !customConfig.import.videos.http.enabled) {- res.fail({ message: 'You need to enable HTTP video import in order to enable channel synchronization' })+ res.fail({ message: req.t('You need to enable HTTP video import in order to enable channel synchronization') })return false}return true}-function checkInvalidLiveConfig (customConfig: CustomConfig, res: express.Response) {+function checkInvalidLiveConfig (customConfig: CustomConfig, req: express.Request, res: express.Response) {if (customConfig.live.enabled === false) return trueif (customConfig.live.allowReplay === true && customConfig.transcoding.enabled === false) {- res.fail({ message: 'You cannot allow live replay if transcoding is not enabled' })+ res.fail({ message: req.t('You cannot allow live replay if transcoding is not enabled') })return false}return true}-function checkInvalidVideoStudioConfig (customConfig: CustomConfig, res: express.Response) {+function checkInvalidVideoStudioConfig (customConfig: CustomConfig, req: express.Request, res: express.Response) {if (customConfig.videoStudio.enabled === false) return trueif (customConfig.videoStudio.enabled === true && customConfig.transcoding.enabled === false) {- res.fail({ message: 'You cannot enable video studio if transcoding is not enabled' })+ res.fail({ message: req.t('You cannot enable video studio if transcoding is not enabled') })+ return false+ }++ return true+}++function checkInvalidSearchConfig (customConfig: CustomConfig, req: express.Request, res: express.Response) {+ if (customConfig.search.searchIndex.enabled === false) return true++ if (customConfig.search.searchIndex.enabled === true && customConfig.search.remoteUri.users === false) {+ res.fail({ message: req.t('You cannot enable search index without enabling remote URI search for users.') })return false}