ActivityPub-federated video streaming platform using P2P directly in your web browser
fix(config): Browse Videos custom config validation errors have missing details (#7302)
Gianantonio Pini809d30af0383
diff --git a/packages/tests/src/api/check-params/config.ts b/packages/tests/src/api/check-params/config.tsindex a1e3f5658c..ae014f5a20 100644--- a/packages/tests/src/api/check-params/config.ts+++ b/packages/tests/src/api/check-params/config.ts@@ -1,4 +1,5 @@/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */+import { expect } from 'chai'import { omit } from '@peertube/peertube-core-utils'import { ActorImageType, CustomConfig, HttpStatusCode, LogoType } from '@peertube/peertube-models'import { buildAbsoluteFixturePath } from '@peertube/peertube-node-utils'@@ -232,13 +233,18 @@ describe('Test config API validators', function () {}})- await makePutBodyRequest({+ const response = await makePutBodyRequest({url: server.url,path,fields: newUpdateParams,token: server.accessToken,expectedStatus: HttpStatusCode.BAD_REQUEST_400})++ expect(response.body.detail).to.equal(+ 'Browse videos default sort should be -publishedAt or -originallyPublishedAt ' ++ 'or name or -trending or -hot or -likes or -views, instead of hello'+ )})it('Should fail with a trending default sort & disabled trending algorithm', async function () {@@ -257,13 +263,18 @@ describe('Test config API validators', function () {}})- await makePutBodyRequest({+ const response = await makePutBodyRequest({url: server.url,path,fields: newUpdateParams,token: server.accessToken,expectedStatus: HttpStatusCode.BAD_REQUEST_400})++ expect(response.body.detail).to.equal(+ 'Trending videos algorithm most-viewed should be enabled ' ++ 'if browse videos default sort is -trending'+ )})it('Should fail with an invalid default scope', async function () {@@ -275,13 +286,17 @@ describe('Test config API validators', function () {}})- await makePutBodyRequest({+ const response = await makePutBodyRequest({url: server.url,path,fields: newUpdateParams,token: server.accessToken,expectedStatus: HttpStatusCode.BAD_REQUEST_400})++ expect(response.body.detail).to.equal(+ 'Browse videos default scope should be local or federated, instead of hello'+ )})})})diff --git a/server/core/helpers/custom-validators/browse-videos.ts b/server/core/helpers/custom-validators/browse-videos.tsindex 8de59ef0fa..8582e3f801 100644--- a/server/core/helpers/custom-validators/browse-videos.ts+++ b/server/core/helpers/custom-validators/browse-videos.ts@@ -4,14 +4,14 @@ export function getBrowseVideosDefaultSortError (value: string, enabledTrendingAconst availableOptions = [ '-publishedAt', '-originallyPublishedAt', 'name', '-trending', '-hot', '-likes', '-views' ]if (availableOptions.includes(value) === false) {- const options = availableOptions.join('\' or \'')+ const options = availableOptions.join(' or ')// Only use `t` if language is provided, because i18n might not be initialized yet and can return `undefined`if (language) {- return t(`Browse videos default sort should be {options}, instead of {value}`, language, { options, value })+ return t('Browse videos default sort should be {options}, instead of {value}', language, { options, value })}- return `Browse videos default sort should be '${options}', instead of '${value}'`+ return `Browse videos default sort should be ${options}, instead of ${value}`}const trendingSortAlgorithmMap = new Map<string, string>([@@ -24,13 +24,13 @@ export function getBrowseVideosDefaultSortError (value: string, enabledTrendingAif (currentTrendingSortAlgorithm && enabledTrendingAlgorithms.includes(currentTrendingSortAlgorithm) === false) {if (language) {return t(- `Trending videos algorithm {currentTrendingSortAlgorithm} should be enabled if browse videos default sort is {value}`,+ 'Trending videos algorithm {currentTrendingSortAlgorithm} should be enabled if browse videos default sort is {value}',language,{ currentTrendingSortAlgorithm, value })}- return `Trending videos algorithm '${currentTrendingSortAlgorithm}' should be enabled if browse videos default sort is '${value}'`+ return `Trending videos algorithm ${currentTrendingSortAlgorithm} should be enabled if browse videos default sort is ${value}`}return null@@ -40,13 +40,13 @@ export function getBrowseVideosDefaultScopeError (value: string, language?: striconst availableOptions = [ 'local', 'federated' ]if (availableOptions.includes(value) === false) {- const options = availableOptions.join('\' or \'')+ const options = availableOptions.join(' or ')if (language) {- return t(`Browse videos default scope should be {options}, instead of {value}`, language, { options, value })+ return t('Browse videos default scope should be {options}, instead of {value}', language, { options, value })}- return `Browse videos default scope should be '${options}', instead of '${value}'`+ return `Browse videos default scope should be ${options}, instead of ${value}`}return null