From 65e6e2602c0d5521f3a6740f7469bb92830ecb53 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 11:51:09 +0200 Subject: [PATCH] Introduce config command --- server/tests/api/check-params/live.ts | 75 ++--- server/tests/api/check-params/search.ts | 25 +- .../tests/api/check-params/video-imports.ts | 53 ++-- server/tests/api/live/live-constraints.ts | 33 ++- server/tests/api/live/live-permanent.ts | 35 +-- server/tests/api/live/live-save-replay.ts | 21 +- server/tests/api/live/live-socket-messages.ts | 15 +- server/tests/api/live/live-views.ts | 15 +- server/tests/api/live/live.ts | 43 +-- .../notifications/moderation-notifications.ts | 20 +- server/tests/api/search/search-index.ts | 55 ++-- server/tests/api/search/search-videos.ts | 5 +- server/tests/api/server/auto-follows.ts | 9 +- server/tests/api/server/config.ts | 48 +--- server/tests/api/server/follows-moderation.ts | 9 +- server/tests/api/server/homepage.ts | 5 +- server/tests/api/server/plugins.ts | 21 +- server/tests/api/server/stats.ts | 47 ++-- server/tests/api/users/users-verification.ts | 37 +-- server/tests/api/users/users.ts | 9 +- .../api/videos/video-change-ownership.ts | 15 +- server/tests/api/videos/video-hls.ts | 41 +-- server/tests/api/videos/video-imports.ts | 5 +- server/tests/api/videos/video-nsfw.ts | 25 +- server/tests/api/videos/video-transcoder.ts | 86 +++--- server/tests/cli/create-transcoding-job.ts | 5 +- server/tests/cli/plugins.ts | 8 +- server/tests/client.ts | 55 ++-- server/tests/plugins/external-auth.ts | 15 +- server/tests/plugins/filter-hooks.ts | 61 ++-- server/tests/plugins/id-and-pass-auth.ts | 15 +- server/tests/plugins/plugin-transcoding.ts | 50 ++-- shared/extra-utils/server/config-command.ts | 260 ++++++++++++++++++ shared/extra-utils/server/config.ts | 260 ------------------ shared/extra-utils/server/index.ts | 2 +- shared/extra-utils/server/servers.ts | 3 + 36 files changed, 740 insertions(+), 746 deletions(-) create mode 100644 shared/extra-utils/server/config-command.ts delete mode 100644 shared/extra-utils/server/config.ts diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 933d8abf2..7a623c169 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -19,7 +19,6 @@ import { ServerInfo, setAccessTokensToServers, stopFfmpeg, - updateCustomSubConfig, updateLive, uploadVideoAndGetId, userLogin, @@ -43,12 +42,14 @@ describe('Test video lives API validator', function () { await setAccessTokensToServers([ server ]) - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: true, - maxInstanceLives: 20, - maxUserLives: 20, - allowReplay: true + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + maxInstanceLives: 20, + maxUserLives: 20, + allowReplay: true + } } }) @@ -234,9 +235,11 @@ describe('Test video lives API validator', function () { }) it('Should forbid if live is disabled', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: false + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: false + } } }) @@ -252,10 +255,12 @@ describe('Test video lives API validator', function () { it('Should forbid to save replay if not enabled by the admin', async function () { const fields = immutableAssign(baseCorrectParams, { saveReplay: true }) - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: true, - allowReplay: false + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: false + } } }) @@ -271,10 +276,12 @@ describe('Test video lives API validator', function () { it('Should allow to save replay if enabled by the admin', async function () { const fields = immutableAssign(baseCorrectParams, { saveReplay: true }) - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: true, - allowReplay: true + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true + } } }) @@ -288,10 +295,12 @@ describe('Test video lives API validator', function () { }) it('Should not allow live if max instance lives is reached', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: true, - maxInstanceLives: 1 + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + maxInstanceLives: 1 + } } }) @@ -305,11 +314,13 @@ describe('Test video lives API validator', function () { }) it('Should not allow live if max user lives is reached', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: true, - maxInstanceLives: 20, - maxUserLives: 1 + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + maxInstanceLives: 20, + maxUserLives: 1 + } } }) @@ -393,10 +404,12 @@ describe('Test video lives API validator', function () { }) it('Should fail to update replay status if replay is not allowed on the instance', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - live: { - enabled: true, - allowReplay: false + await server.configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: false + } } }) diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index 20ad46cff..4a2fc1197 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts @@ -1,28 +1,27 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { HttpStatusCode } from '@shared/core-utils' import { + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, flushAndRunServer, immutableAssign, makeGetRequest, ServerInfo, - updateCustomSubConfig, setAccessTokensToServers -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { - return updateCustomSubConfig(server.url, server.accessToken, { - search: { - searchIndex: { - enabled, - disableLocalSearch + return server.configCommand.updateCustomSubConfig({ + newConfig: { + search: { + searchIndex: { + enabled, + disableLocalSearch + } } } }) diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index a27b624d0..dae3860ef 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -2,9 +2,12 @@ import 'mocha' import { omit } from 'lodash' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { buildAbsoluteFixturePath, + checkBadCountPagination, + checkBadSortPagination, + checkBadStartPagination, cleanupTests, createUser, flushAndRunServer, @@ -15,16 +18,10 @@ import { makeUploadRequest, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, userLogin -} from '../../../../shared/extra-utils' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination -} from '../../../../shared/extra-utils/requests/check-api-params' -import { getGoodVideoUrl, getMagnetURI } from '../../../../shared/extra-utils/videos/video-imports' -import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' +} from '@shared/extra-utils' +import { getGoodVideoUrl, getMagnetURI } from '@shared/extra-utils/videos/video-imports' +import { VideoPrivacy } from '@shared/models' describe('Test video imports API validator', function () { const path = '/api/v1/videos/imports' @@ -263,14 +260,16 @@ describe('Test video imports API validator', function () { }) it('Should forbid to import http videos', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - import: { - videos: { - http: { - enabled: false - }, - torrent: { - enabled: true + await server.configCommand.updateCustomSubConfig({ + newConfig: { + import: { + videos: { + http: { + enabled: false + }, + torrent: { + enabled: true + } } } } @@ -286,14 +285,16 @@ describe('Test video imports API validator', function () { }) it('Should forbid to import torrent videos', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - import: { - videos: { - http: { - enabled: true - }, - torrent: { - enabled: false + await server.configCommand.updateCustomSubConfig({ + newConfig: { + import: { + videos: { + http: { + enabled: true + }, + torrent: { + enabled: false + } } } } diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index cc635de33..c64d10dcd 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts @@ -6,17 +6,16 @@ import { VideoDetails, VideoPrivacy } from '@shared/models' import { checkLiveCleanup, cleanupTests, + ConfigCommand, createLive, doubleFollow, flushAndRunMultipleServers, generateUser, - getCustomConfigResolutions, getVideo, runAndTestFfmpegStreamError, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateCustomSubConfig, updateUser, wait, waitJobs, @@ -80,12 +79,14 @@ describe('Test live constraints', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - transcoding: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true, + transcoding: { + enabled: false + } } } }) @@ -157,14 +158,16 @@ describe('Test live constraints', function () { it('Should have max duration limit', async function () { this.timeout(60000) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - maxDuration: 1, - transcoding: { + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { enabled: true, - resolutions: getCustomConfigResolutions(true) + allowReplay: true, + maxDuration: 1, + transcoding: { + enabled: true, + resolutions: ConfigCommand.getCustomConfigResolutions(true) + } } } }) diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index 71b7d28a8..b9e37c834 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts @@ -5,10 +5,10 @@ import * as chai from 'chai' import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models' import { cleanupTests, + ConfigCommand, createLive, doubleFollow, flushAndRunMultipleServers, - getCustomConfigResolutions, getLive, getPlaylistsCount, getVideo, @@ -17,7 +17,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - updateCustomSubConfig, updateLive, wait, waitJobs, @@ -63,14 +62,16 @@ describe('Permanent live', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - maxDuration: -1, - transcoding: { + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { enabled: true, - resolutions: getCustomConfigResolutions(true) + allowReplay: true, + maxDuration: -1, + transcoding: { + enabled: true, + resolutions: ConfigCommand.getCustomConfigResolutions(true) + } } } }) @@ -145,14 +146,16 @@ describe('Permanent live', function () { it('Should be able to stream again in the permanent live', async function () { this.timeout(20000) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - maxDuration: -1, - transcoding: { + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { enabled: true, - resolutions: getCustomConfigResolutions(false) + allowReplay: true, + maxDuration: -1, + transcoding: { + enabled: true, + resolutions: ConfigCommand.getCustomConfigResolutions(false) + } } } }) diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 3d4736c8f..e74bc3e8d 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -9,10 +9,10 @@ import { addVideoToBlacklist, checkLiveCleanup, cleanupTests, + ConfigCommand, createLive, doubleFollow, flushAndRunMultipleServers, - getCustomConfigResolutions, getVideo, getVideosList, removeVideo, @@ -22,7 +22,6 @@ import { setDefaultVideoChannel, stopFfmpeg, testFfmpegStreamError, - updateCustomSubConfig, updateVideo, wait, waitJobs, @@ -102,14 +101,16 @@ describe('Save replay setting', function () { // Server 1 and server 2 follow each other await doubleFollow(servers[0], servers[1]) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - maxDuration: -1, - transcoding: { - enabled: false, - resolutions: getCustomConfigResolutions(true) + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true, + maxDuration: -1, + transcoding: { + enabled: false, + resolutions: ConfigCommand.getCustomConfigResolutions(true) + } } } }) diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts index e00909ade..0159d5199 100644 --- a/server/tests/api/live/live-socket-messages.ts +++ b/server/tests/api/live/live-socket-messages.ts @@ -15,7 +15,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - updateCustomSubConfig, viewVideo, wait, waitJobs, @@ -37,12 +36,14 @@ describe('Test live', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - transcoding: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true, + transcoding: { + enabled: false + } } } }) diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts index a44d21ffa..ca571c962 100644 --- a/server/tests/api/live/live-views.ts +++ b/server/tests/api/live/live-views.ts @@ -15,7 +15,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - updateCustomSubConfig, viewVideo, wait, waitJobs, @@ -36,12 +35,14 @@ describe('Test live', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - transcoding: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true, + transcoding: { + enabled: false + } } } }) diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 50397924e..2c3102994 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -34,7 +34,6 @@ import { stopFfmpeg, testFfmpegStreamError, testImage, - updateCustomSubConfig, updateLive, uploadVideoAndGetId, wait, @@ -59,12 +58,14 @@ describe('Test live', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - transcoding: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { + enabled: true, + allowReplay: true, + transcoding: { + enabled: false + } } } }) @@ -422,20 +423,22 @@ describe('Test live', function () { } function updateConf (resolutions: number[]) { - return updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { - enabled: true, - allowReplay: true, - maxDuration: -1, - transcoding: { + return servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { enabled: true, - resolutions: { - '240p': resolutions.includes(240), - '360p': resolutions.includes(360), - '480p': resolutions.includes(480), - '720p': resolutions.includes(720), - '1080p': resolutions.includes(1080), - '2160p': resolutions.includes(2160) + allowReplay: true, + maxDuration: -1, + transcoding: { + enabled: true, + resolutions: { + '240p': resolutions.includes(240), + '360p': resolutions.includes(360), + '480p': resolutions.includes(480), + '720p': resolutions.includes(720), + '1080p': resolutions.includes(1080), + '2160p': resolutions.includes(2160) + } } } } diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 9a93ce401..3e66e7517 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -23,7 +23,6 @@ import { createUser, generateUserAccessToken, getAccount, - getCustomConfig, getVideoCommentThreads, getVideoIdFromUUID, immutableAssign, @@ -34,8 +33,6 @@ import { removeUserSubscription, removeVideoFromBlacklist, ServerInfo, - updateCustomConfig, - updateCustomSubConfig, uploadVideo, wait, waitJobs @@ -407,7 +404,7 @@ describe('Test moderation notifications', function () { } } } - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) await servers[2].followsCommand.follow({ targets: [ servers[0].url ] }) @@ -421,7 +418,7 @@ describe('Test moderation notifications', function () { await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence') config.followings.instance.autoFollowBack.enabled = false - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) await servers[0].followsCommand.unfollow({ target: servers[2] }) await servers[2].followsCommand.unfollow({ target: servers[0] }) }) @@ -430,7 +427,7 @@ describe('Test moderation notifications', function () { this.timeout(30000) await servers[0].followsCommand.unfollow({ target: servers[1] }) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) await wait(5000) await waitJobs(servers) @@ -440,7 +437,7 @@ describe('Test moderation notifications', function () { await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') config.followings.instance.autoFollowIndex.enabled = false - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) await servers[0].followsCommand.unfollow({ target: servers[1] }) }) }) @@ -476,8 +473,8 @@ describe('Test moderation notifications', function () { token: userAccessToken } - const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken) - currentCustomConfig = resCustomConfig.body + currentCustomConfig = await servers[0].configCommand.getCustomConfig() + const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, { autoBlacklist: { videos: { @@ -487,9 +484,10 @@ describe('Test moderation notifications', function () { } } }) + // enable transcoding otherwise own publish notification after transcoding not expected autoBlacklistTestsCustomConfig.transcoding.enabled = true - await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig) + await servers[0].configCommand.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig }) await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) @@ -612,7 +610,7 @@ describe('Test moderation notifications', function () { }) after(async () => { - await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig) + await servers[0].configCommand.updateCustomConfig({ newCustomConfig: currentCustomConfig }) await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) diff --git a/server/tests/api/search/search-index.ts b/server/tests/api/search/search-index.ts index b2c0857a7..e4c5f5796 100644 --- a/server/tests/api/search/search-index.ts +++ b/server/tests/api/search/search-index.ts @@ -9,7 +9,6 @@ import { SearchCommand, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, uploadVideo } from '@shared/extra-utils' import { VideoPlaylistPrivacy, VideoPlaylistType, VideosSearchQuery } from '@shared/models' @@ -39,12 +38,14 @@ describe('Test videos search', function () { it('Should make a local videos search by default', async function () { this.timeout(10000) - await updateCustomSubConfig(server.url, server.accessToken, { - search: { - searchIndex: { - enabled: true, - isDefaultSearch: false, - disableLocalSearch: false + await server.configCommand.updateCustomSubConfig({ + newConfig: { + search: { + searchIndex: { + enabled: true, + isDefaultSearch: false, + disableLocalSearch: false + } } } }) @@ -64,12 +65,14 @@ describe('Test videos search', function () { }) it('Should make an index videos search by default', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - search: { - searchIndex: { - enabled: true, - isDefaultSearch: true, - disableLocalSearch: false + await server.configCommand.updateCustomSubConfig({ + newConfig: { + search: { + searchIndex: { + enabled: true, + isDefaultSearch: true, + disableLocalSearch: false + } } } }) @@ -84,12 +87,14 @@ describe('Test videos search', function () { }) it('Should make an index videos search if local search is disabled', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - search: { - searchIndex: { - enabled: true, - isDefaultSearch: false, - disableLocalSearch: true + await server.configCommand.updateCustomSubConfig({ + newConfig: { + search: { + searchIndex: { + enabled: true, + isDefaultSearch: false, + disableLocalSearch: true + } } } }) @@ -216,7 +221,11 @@ describe('Test videos search', function () { let nsfwUUID: string { - await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'display' } }) + await server.configCommand.updateCustomSubConfig({ + newConfig: { + instance: { defaultNSFWPolicy: 'display' } + } + }) const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' }) expect(body.data).to.have.length.greaterThan(0) @@ -228,7 +237,11 @@ describe('Test videos search', function () { } { - await updateCustomSubConfig(server.url, server.accessToken, { instance: { defaultNSFWPolicy: 'do_not_list' } }) + await server.configCommand.updateCustomSubConfig({ + newConfig: { + instance: { defaultNSFWPolicy: 'do_not_list' } + } + }) const body = await command.searchVideos({ search: 'NSFW search index', sort: '-match' }) diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index f0482c7e0..7dc89c447 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -14,7 +14,6 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - updateCustomSubConfig, uploadVideo, wait, waitUntilLivePublished @@ -486,13 +485,13 @@ describe('Test videos search', function () { this.timeout(30000) { - const options = { + const newConfig = { search: { searchIndex: { enabled: false } }, live: { enabled: true } } - await updateCustomSubConfig(server.url, server.accessToken, options) + await server.configCommand.updateCustomSubConfig({ newConfig }) } { diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts index 02389b1e9..34c4f6882 100644 --- a/server/tests/api/server/auto-follows.ts +++ b/server/tests/api/server/auto-follows.ts @@ -8,7 +8,6 @@ import { MockInstancesIndex, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, wait, waitJobs } from '@shared/extra-utils' @@ -87,7 +86,7 @@ describe('Test auto follows', function () { } } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) + await servers[1].configCommand.updateCustomSubConfig({ newConfig: config }) await server1Follows2(servers) @@ -112,7 +111,7 @@ describe('Test auto follows', function () { } } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) + await servers[1].configCommand.updateCustomSubConfig({ newConfig: config }) await server1Follows2(servers) @@ -129,7 +128,7 @@ describe('Test auto follows', function () { config.followings.instance.autoFollowBack.enabled = false config.followers.instance.manualApproval = false - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) + await servers[1].configCommand.updateCustomSubConfig({ newConfig: config }) }) }) @@ -166,7 +165,7 @@ describe('Test auto follows', function () { } } } - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) await wait(5000) await waitJobs(servers) diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 19bf9582c..037628c9d 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -2,15 +2,10 @@ import 'mocha' import * as chai from 'chai' -import { About } from '../../../../shared/models/server/about.model' -import { CustomConfig } from '../../../../shared/models/server/custom-config.model' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - deleteCustomConfig, flushAndRunServer, - getAbout, - getConfig, - getCustomConfig, killallServers, makeGetRequest, parallelTests, @@ -18,11 +13,9 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - updateCustomConfig, uploadVideo -} from '../../../../shared/extra-utils' -import { ServerConfig } from '../../../../shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +} from '@shared/extra-utils' +import { CustomConfig } from '@shared/models' const expect = chai.expect @@ -213,7 +206,7 @@ function checkUpdatedConfig (data: CustomConfig) { } describe('Test config', function () { - let server = null + let server: ServerInfo = null before(async function () { this.timeout(30000) @@ -223,8 +216,7 @@ describe('Test config', function () { }) it('Should have a correct config on a server with registration enabled', async function () { - const res = await getConfig(server.url) - const data: ServerConfig = res.body + const data = await server.configCommand.getConfig() expect(data.signup.allowed).to.be.true }) @@ -238,15 +230,13 @@ describe('Test config', function () { registerUser(server.url, 'user3', 'super password') ]) - const res = await getConfig(server.url) - const data: ServerConfig = res.body + const data = await server.configCommand.getConfig() expect(data.signup.allowed).to.be.false }) it('Should have the correct video allowed extensions', async function () { - const res = await getConfig(server.url) - const data: ServerConfig = res.body + const data = await server.configCommand.getConfig() expect(data.video.file.extensions).to.have.lengthOf(3) expect(data.video.file.extensions).to.contain('.mp4') @@ -260,8 +250,7 @@ describe('Test config', function () { }) it('Should get the customized configuration', async function () { - const res = await getCustomConfig(server.url, server.accessToken) - const data = res.body as CustomConfig + const data = await server.configCommand.getCustomConfig() checkInitialConfig(server, data) }) @@ -438,19 +427,16 @@ describe('Test config', function () { } } } - await updateCustomConfig(server.url, server.accessToken, newCustomConfig) - - const res = await getCustomConfig(server.url, server.accessToken) - const data = res.body + await server.configCommand.updateCustomConfig({ newCustomConfig }) + const data = await server.configCommand.getCustomConfig() checkUpdatedConfig(data) }) it('Should have the correct updated video allowed extensions', async function () { this.timeout(10000) - const res = await getConfig(server.url) - const data: ServerConfig = res.body + const data = await server.configCommand.getConfig() expect(data.video.file.extensions).to.have.length.above(4) expect(data.video.file.extensions).to.contain('.mp4') @@ -474,15 +460,13 @@ describe('Test config', function () { await reRunServer(server) - const res = await getCustomConfig(server.url, server.accessToken) - const data = res.body + const data = await server.configCommand.getCustomConfig() checkUpdatedConfig(data) }) it('Should fetch the about information', async function () { - const res = await getAbout(server.url) - const data: About = res.body + const data = await server.configCommand.getAbout() expect(data.instance.name).to.equal('PeerTube updated') expect(data.instance.shortDescription).to.equal('my short description') @@ -504,11 +488,9 @@ describe('Test config', function () { it('Should remove the custom configuration', async function () { this.timeout(10000) - await deleteCustomConfig(server.url, server.accessToken) - - const res = await getCustomConfig(server.url, server.accessToken) - const data = res.body + await server.configCommand.deleteCustomConfig() + const data = await server.configCommand.getCustomConfig() checkInitialConfig(server, data) }) diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index 4853b647d..6d6eca9a8 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -8,7 +8,6 @@ import { FollowsCommand, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, waitJobs } from '@shared/extra-utils' @@ -94,7 +93,7 @@ describe('Test follows moderation', function () { } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) + await servers[1].configCommand.updateCustomSubConfig({ newConfig: subConfig }) await commands[0].follow({ targets: [ servers[1].url ] }) await waitJobs(servers) @@ -114,7 +113,7 @@ describe('Test follows moderation', function () { } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) + await servers[1].configCommand.updateCustomSubConfig({ newConfig: subConfig }) await commands[0].follow({ targets: [ servers[1].url ] }) await waitJobs(servers) @@ -137,8 +136,8 @@ describe('Test follows moderation', function () { } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) - await updateCustomSubConfig(servers[2].url, servers[2].accessToken, subConfig) + await servers[1].configCommand.updateCustomSubConfig({ newConfig: subConfig }) + await servers[2].configCommand.updateCustomSubConfig({ newConfig: subConfig }) await commands[0].follow({ targets: [ servers[1].url ] }) await waitJobs(servers) diff --git a/server/tests/api/server/homepage.ts b/server/tests/api/server/homepage.ts index 4a3ec0479..c08067f3c 100644 --- a/server/tests/api/server/homepage.ts +++ b/server/tests/api/server/homepage.ts @@ -3,12 +3,10 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { ServerConfig } from '@shared/models' import { cleanupTests, CustomPagesCommand, flushAndRunServer, - getConfig, killallServers, reRunServer, ServerInfo, @@ -18,9 +16,8 @@ import { const expect = chai.expect async function getHomepageState (server: ServerInfo) { - const res = await getConfig(server.url) + const config = await server.configCommand.getConfig() - const config = res.body as ServerConfig return config.homepage.enabled } diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index 1536997d5..528bbbe58 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -7,7 +7,6 @@ import { cleanupTests, closeAllSequelize, flushAndRunServer, - getConfig, getMyUserInformation, killallServers, PluginsCommand, @@ -16,12 +15,11 @@ import { setAccessTokensToServers, setPluginVersion, testHelloWorldRegisteredSettings, - updateCustomSubConfig, updateMyUser, wait, waitUntilLog } from '@shared/extra-utils' -import { PluginType, ServerConfig, User } from '@shared/models' +import { PluginType, User } from '@shared/models' const expect = chai.expect @@ -102,8 +100,7 @@ describe('Test plugins', function () { }) it('Should have the plugin loaded in the configuration', async function () { - const res = await getConfig(server.url) - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const theme = config.theme.registered.find(r => r.name === 'background-red') expect(theme).to.not.be.undefined @@ -113,11 +110,13 @@ describe('Test plugins', function () { }) it('Should update the default theme in the configuration', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { theme: { default: 'background-red' } }) - - const res = await getConfig(server.url) - const config: ServerConfig = res.body + await server.configCommand.updateCustomSubConfig({ + newConfig: { + theme: { default: 'background-red' } + } + }) + const config = await server.configCommand.getConfig() expect(config.theme.default).to.equal('background-red') }) @@ -302,9 +301,7 @@ describe('Test plugins', function () { }) it('Should have updated the configuration', async function () { - // get /config (default theme + registered themes + registered plugins) - const res = await getConfig(server.url) - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() expect(config.theme.default).to.equal('default') diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index 36114a297..f01188d67 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -12,7 +12,6 @@ import { flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, uploadVideo, userLogin, viewVideo, @@ -197,24 +196,26 @@ describe('Test stats (excluding redundancy)', function () { it('Should correctly count video file sizes if transcoding is enabled', async function () { this.timeout(60000) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - enabled: true, - webtorrent: { - enabled: true - }, - hls: { - enabled: true - }, - resolutions: { - '0p': false, - '240p': false, - '360p': false, - '480p': false, - '720p': false, - '1080p': false, - '1440p': false, - '2160p': false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: true, + webtorrent: { + enabled: true + }, + hls: { + enabled: true + }, + resolutions: { + '0p': false, + '240p': false, + '360p': false, + '480p': false, + '720p': false, + '1080p': false, + '1440p': false, + '2160p': false + } } } }) @@ -238,9 +239,11 @@ describe('Test stats (excluding redundancy)', function () { it('Should have the correct AP stats', async function () { this.timeout(60000) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: false + } } }) diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 265cd6050..23f81d804 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -11,7 +11,6 @@ import { login, registerUser, ServerInfo, - updateCustomSubConfig, updateMyUser, userLogin, verifyEmail @@ -58,11 +57,13 @@ describe('Test users account verification', function () { it('Should register user and send verification email if verification required', async function () { this.timeout(30000) - await updateCustomSubConfig(server.url, server.accessToken, { - signup: { - enabled: true, - requiresEmailVerification: true, - limit: 10 + await server.configCommand.updateCustomSubConfig({ + newConfig: { + signup: { + enabled: true, + requiresEmailVerification: true, + limit: 10 + } } }) @@ -148,11 +149,13 @@ describe('Test users account verification', function () { it('Should register user not requiring email verification if setting not enabled', async function () { this.timeout(5000) - await updateCustomSubConfig(server.url, server.accessToken, { - signup: { - enabled: true, - requiresEmailVerification: false, - limit: 10 + await server.configCommand.updateCustomSubConfig({ + newConfig: { + signup: { + enabled: true, + requiresEmailVerification: false, + limit: 10 + } } }) @@ -168,11 +171,13 @@ describe('Test users account verification', function () { }) it('Should allow login for user with unverified email when setting later enabled', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - signup: { - enabled: true, - requiresEmailVerification: true, - limit: 10 + await server.configCommand.updateCustomSubConfig({ + newConfig: { + signup: { + enabled: true, + requiresEmailVerification: true, + limit: 10 + } } }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index ba4183e08..33bcc8701 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -13,7 +13,6 @@ import { flushAndRunServer, getAccountRatings, getBlacklistedVideosList, - getCustomConfig, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, @@ -38,7 +37,6 @@ import { setTokenField, testImage, unblockUser, - updateCustomSubConfig, updateMyAvatar, updateMyUser, updateUser, @@ -46,7 +44,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { AbuseState, CustomConfig, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' +import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' const expect = chai.expect @@ -418,12 +416,11 @@ describe('Test users', function () { this.timeout(60000) { - const res = await getCustomConfig(server.url, server.accessToken) - const config = res.body as CustomConfig + const config = await server.configCommand.getCustomConfig() config.transcoding.webtorrent.enabled = false config.transcoding.hls.enabled = true config.transcoding.enabled = true - await updateCustomSubConfig(server.url, server.accessToken, config) + await server.configCommand.updateCustomSubConfig({ newConfig: config }) } { diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts index a3384851b..89dba14b1 100644 --- a/server/tests/api/videos/video-change-ownership.ts +++ b/server/tests/api/videos/video-change-ownership.ts @@ -20,7 +20,6 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateCustomSubConfig, uploadVideo, userLogin } from '../../../../shared/extra-utils' @@ -58,12 +57,14 @@ describe('Test video change ownership - nominal', function () { await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - enabled: false - }, - live: { - enabled: true + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: false + }, + live: { + enabled: true + } } }) diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index 03ac3f321..3821cfed0 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -3,6 +3,7 @@ import 'mocha' import * as chai from 'chai' import { join } from 'path' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { checkDirectoryIsEmpty, checkResolutionsInMasterPlaylist, @@ -17,7 +18,6 @@ import { removeVideo, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, updateVideo, uploadVideo, waitJobs, @@ -26,7 +26,6 @@ import { import { VideoDetails } from '../../../../shared/models/videos' import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type' import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -192,24 +191,26 @@ describe('Test HLS videos', function () { describe('With only HLS enabled', function () { before(async function () { - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - enabled: true, - allowAudioFiles: true, - resolutions: { - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true - }, - hls: { - enabled: true - }, - webtorrent: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: true, + allowAudioFiles: true, + resolutions: { + '240p': true, + '360p': true, + '480p': true, + '720p': true, + '1080p': true, + '1440p': true, + '2160p': true + }, + hls: { + enabled: true + }, + webtorrent: { + enabled: false + } } } }) diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 80834ca86..a4a9132b4 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -14,8 +14,7 @@ import { listVideoCaptions, ServerInfo, setAccessTokensToServers, - testCaptionFile, - updateCustomSubConfig + testCaptionFile } from '../../../../shared/extra-utils' import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' @@ -333,7 +332,7 @@ Ajouter un sous-titre est vraiment facile`) } } } - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) const attributes = { name: 'hdr video', diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index 24a4c6152..65813517d 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts @@ -7,8 +7,6 @@ import { createUser, flushAndRunServer, getAccountVideos, - getConfig, - getCustomConfig, getMyUserInformation, getMyVideos, getVideoChannelVideos, @@ -16,12 +14,11 @@ import { getVideosListWithToken, ServerInfo, setAccessTokensToServers, - updateCustomConfig, updateMyUser, uploadVideo, userLogin } from '@shared/extra-utils' -import { BooleanBothQuery, CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' +import { BooleanBothQuery, CustomConfig, User, VideosOverview } from '@shared/models' const expect = chai.expect @@ -97,16 +94,12 @@ describe('Test video NSFW policy', function () { await uploadVideo(server.url, server.accessToken, attributes) } - { - const res = await getCustomConfig(server.url, server.accessToken) - customConfig = res.body - } + customConfig = await server.configCommand.getCustomConfig() }) describe('Instance default NSFW policy', function () { it('Should display NSFW videos with display default NSFW policy', async function () { - const resConfig = await getConfig(server.url) - const serverConfig: ServerConfig = resConfig.body + const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') for (const res of await getVideosFunctions()) { @@ -121,10 +114,9 @@ describe('Test video NSFW policy', function () { it('Should not display NSFW videos with do_not_list default NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'do_not_list' - await updateCustomConfig(server.url, server.accessToken, customConfig) + await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) - const resConfig = await getConfig(server.url) - const serverConfig: ServerConfig = resConfig.body + const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') for (const res of await getVideosFunctions()) { @@ -138,10 +130,9 @@ describe('Test video NSFW policy', function () { it('Should display NSFW videos with blur default NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'blur' - await updateCustomConfig(server.url, server.accessToken, customConfig) + await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) - const resConfig = await getConfig(server.url) - const serverConfig: ServerConfig = resConfig.body + const serverConfig = await server.configCommand.getConfig() expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') for (const res of await getVideosFunctions()) { @@ -172,7 +163,7 @@ describe('Test video NSFW policy', function () { it('Should display NSFW videos with blur user NSFW policy', async function () { customConfig.instance.defaultNSFWPolicy = 'do_not_list' - await updateCustomConfig(server.url, server.accessToken, customConfig) + await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) for (const res of await getVideosFunctions(userAccessToken)) { expect(res.body.total).to.equal(2) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index c95053a29..e74fb5bef 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -5,7 +5,6 @@ import * as chai from 'chai' import { FfprobeData } from 'fluent-ffmpeg' import { omit } from 'lodash' import { join } from 'path' -import { Job } from '@shared/models' import { VIDEO_TRANSCODING_FPS } from '../../../../server/initializers/constants' import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { @@ -24,7 +23,6 @@ import { makeGetRequest, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, uploadVideo, uploadVideoAndGetId, waitJobs, @@ -43,22 +41,24 @@ import { const expect = chai.expect function updateConfigForTranscoding (server: ServerInfo) { - return updateCustomSubConfig(server.url, server.accessToken, { - transcoding: { - enabled: true, - allowAdditionalExtensions: true, - allowAudioFiles: true, - hls: { enabled: true }, - webtorrent: { enabled: true }, - resolutions: { - '0p': false, - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true + return server.configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: true, + allowAdditionalExtensions: true, + allowAudioFiles: true, + hls: { enabled: true }, + webtorrent: { enabled: true }, + resolutions: { + '0p': false, + '240p': true, + '360p': true, + '480p': true, + '720p': true, + '1080p': true, + '1440p': true, + '2160p': true + } } } }) @@ -363,19 +363,21 @@ describe('Test video transcoding', function () { function runSuite (mode: 'legacy' | 'resumable') { before(async function () { - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { - transcoding: { - hls: { enabled: true }, - webtorrent: { enabled: true }, - resolutions: { - '0p': false, - '240p': false, - '360p': false, - '480p': false, - '720p': false, - '1080p': false, - '1440p': false, - '2160p': false + await servers[1].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + hls: { enabled: true }, + webtorrent: { enabled: true }, + resolutions: { + '0p': false, + '240p': false, + '360p': false, + '480p': false, + '720p': false, + '1080p': false, + '1440p': false, + '2160p': false + } } } }) @@ -434,14 +436,16 @@ describe('Test video transcoding', function () { it('Should upload an audio file and create an audio version only', async function () { this.timeout(60_000) - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, { - transcoding: { - hls: { enabled: true }, - webtorrent: { enabled: true }, - resolutions: { - '0p': true, - '240p': false, - '360p': false + await servers[1].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + hls: { enabled: true }, + webtorrent: { enabled: true }, + resolutions: { + '0p': true, + '240p': false, + '360p': false + } } } }) @@ -601,7 +605,7 @@ describe('Test video transcoding', function () { it('Should not transcode to an higher bitrate than the original file', async function () { this.timeout(160_000) - const config = { + const newConfig = { transcoding: { enabled: true, resolutions: { @@ -617,7 +621,7 @@ describe('Test video transcoding', function () { hls: { enabled: true } } } - await updateCustomSubConfig(servers[1].url, servers[1].accessToken, config) + await servers[1].configCommand.updateCustomSubConfig({ newConfig }) const videoAttributes = { name: 'low bitrate', diff --git a/server/tests/cli/create-transcoding-job.ts b/server/tests/cli/create-transcoding-job.ts index be46dec25..e3211882d 100644 --- a/server/tests/cli/create-transcoding-job.ts +++ b/server/tests/cli/create-transcoding-job.ts @@ -10,7 +10,6 @@ import { getVideosList, ServerInfo, setAccessTokensToServers, - updateCustomSubConfig, uploadVideo } from '../../../shared/extra-utils' import { waitJobs } from '../../../shared/extra-utils/server/jobs' @@ -47,7 +46,7 @@ describe('Test create transcoding jobs', function () { servers = await flushAndRunMultipleServers(2) await setAccessTokensToServers(servers) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) await doubleFollow(servers[0], servers[1]) @@ -199,7 +198,7 @@ describe('Test create transcoding jobs', function () { this.timeout(120000) config.transcoding.hls.enabled = true - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomSubConfig({ newConfig: config }) await servers[0].cliCommand.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[4]}`) diff --git a/server/tests/cli/plugins.ts b/server/tests/cli/plugins.ts index 7b8746a5d..e5efae36b 100644 --- a/server/tests/cli/plugins.ts +++ b/server/tests/cli/plugins.ts @@ -5,14 +5,12 @@ import { expect } from 'chai' import { cleanupTests, flushAndRunServer, - getConfig, killallServers, PluginsCommand, reRunServer, ServerInfo, setAccessTokensToServers } from '../../../shared/extra-utils' -import { ServerConfig } from '../../../shared/models/server' describe('Test plugin scripts', function () { let server: ServerInfo @@ -44,8 +42,7 @@ describe('Test plugin scripts', function () { killallServers([ server ]) await reRunServer(server) - const res = await getConfig(server.url) - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const plugin = config.plugin.registered .find(p => p.name === 'test') @@ -68,8 +65,7 @@ describe('Test plugin scripts', function () { killallServers([ server ]) await reRunServer(server) - const res = await getConfig(server.url) - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const plugin = config.plugin.registered .find(p => p.name === 'test') diff --git a/server/tests/client.ts b/server/tests/client.ts index 7c4fb4e46..be7ce18b4 100644 --- a/server/tests/client.ts +++ b/server/tests/client.ts @@ -4,7 +4,7 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' -import { Account, CustomConfig, HTMLServerConfig, ServerConfig, VideoPlaylistCreateResult, VideoPlaylistPrivacy } from '@shared/models' +import { Account, HTMLServerConfig, ServerConfig, VideoPlaylistCreateResult, VideoPlaylistPrivacy } from '@shared/models' import { addVideoInPlaylist, cleanupTests, @@ -12,16 +12,12 @@ import { doubleFollow, flushAndRunMultipleServers, getAccount, - getConfig, - getCustomConfig, getVideosList, makeGetRequest, makeHTMLRequest, ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateCustomConfig, - updateCustomSubConfig, updateMyUser, updateVideoChannel, uploadVideo, @@ -307,14 +303,13 @@ describe('Test a client controllers', function () { describe('Whitelisted', function () { before(async function () { - const res = await getCustomConfig(servers[0].url, servers[0].accessToken) - const config = res.body as CustomConfig + const config = await servers[0].configCommand.getCustomConfig() config.services.twitter = { username: '@Kuja', whitelisted: true } - await updateCustomConfig(servers[0].url, servers[0].accessToken, config) + await servers[0].configCommand.updateCustomConfig({ newCustomConfig: config }) }) async function accountPageTest (path: string) { @@ -382,40 +377,42 @@ describe('Test a client controllers', function () { describe('Index HTML', function () { it('Should have valid index html tags (title, description...)', async function () { - const resConfig = await getConfig(servers[0].url) + const config = await servers[0].configCommand.getConfig() const res = await makeHTMLRequest(servers[0].url, '/videos/trending') const description = 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' - checkIndexTags(res.text, 'PeerTube', description, '', resConfig.body) + checkIndexTags(res.text, 'PeerTube', description, '', config) }) it('Should update the customized configuration and have the correct index html tags', async function () { - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - instance: { - name: 'PeerTube updated', - shortDescription: 'my short description', - description: 'my super description', - terms: 'my super terms', - defaultNSFWPolicy: 'blur', - defaultClientRoute: '/videos/recently-added', - customizations: { - javascript: 'alert("coucou")', - css: 'body { background-color: red; }' + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + instance: { + name: 'PeerTube updated', + shortDescription: 'my short description', + description: 'my super description', + terms: 'my super terms', + defaultNSFWPolicy: 'blur', + defaultClientRoute: '/videos/recently-added', + customizations: { + javascript: 'alert("coucou")', + css: 'body { background-color: red; }' + } } } }) - const resConfig = await getConfig(servers[0].url) + const config = await servers[0].configCommand.getConfig() const res = await makeHTMLRequest(servers[0].url, '/videos/trending') - checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', resConfig.body) + checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', config) }) it('Should have valid index html updated tags (title, description...)', async function () { - const resConfig = await getConfig(servers[0].url) + const config = await servers[0].configCommand.getConfig() const res = await makeHTMLRequest(servers[0].url, '/videos/trending') - checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', resConfig.body) + checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', config) }) it('Should use the original video URL for the canonical tag', async function () { @@ -428,7 +425,7 @@ describe('Test a client controllers', function () { }) it('Should use the original account URL for the canonical tag', async function () { - const accountURLtest = (res) => { + const accountURLtest = res => { expect(res.text).to.contain(``) } @@ -438,7 +435,7 @@ describe('Test a client controllers', function () { }) it('Should use the original channel URL for the canonical tag', async function () { - const channelURLtests = (res) => { + const channelURLtests = res => { expect(res.text).to.contain(``) } @@ -460,10 +457,10 @@ describe('Test a client controllers', function () { describe('Embed HTML', function () { it('Should have the correct embed html tags', async function () { - const resConfig = await getConfig(servers[0].url) + const config = await servers[0].configCommand.getConfig() const res = await makeHTMLRequest(servers[0].url, servers[0].video.embedPath) - checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', resConfig.body) + checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }', config) }) }) diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index 424302786..09a107ca2 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts @@ -8,7 +8,6 @@ import { createUser, decodeQueryString, flushAndRunServer, - getConfig, getMyUserInformation, loginUsingExternalToken, logout, @@ -21,7 +20,7 @@ import { wait, waitUntilLog } from '@shared/extra-utils' -import { ServerConfig, User, UserRole } from '@shared/models' +import { User, UserRole } from '@shared/models' async function loginExternal (options: { server: ServerInfo @@ -78,9 +77,7 @@ describe('Test external auth plugins', function () { }) it('Should display the correct configuration', async function () { - const res = await getConfig(server.url) - - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const auths = config.plugin.registeredExternalAuths expect(auths).to.have.lengthOf(8) @@ -288,9 +285,7 @@ describe('Test external auth plugins', function () { }) it('Should have disabled this auth', async function () { - const res = await getConfig(server.url) - - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const auths = config.plugin.registeredExternalAuths expect(auths).to.have.lengthOf(7) @@ -354,9 +349,7 @@ describe('Test external auth plugins', function () { }) it('Should display the correct configuration', async function () { - const res = await getConfig(server.url) - - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const auths = config.plugin.registeredExternalAuths expect(auths).to.have.lengthOf(6) diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index c51e96ab7..e254046bf 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -12,7 +12,6 @@ import { doubleFollow, flushAndRunMultipleServers, getAccountVideos, - getConfig, getMyVideos, getVideo, getVideoChannelVideos, @@ -28,7 +27,6 @@ import { ServerInfo, setAccessTokensToServers, setDefaultVideoChannel, - updateCustomSubConfig, updateVideo, uploadVideo, uploadVideoAndGetId, @@ -37,7 +35,6 @@ import { } from '@shared/extra-utils' import { getGoodVideoUrl, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports' import { - ServerConfig, VideoCommentThreadTree, VideoDetails, VideoImport, @@ -72,13 +69,15 @@ describe('Test plugin filter hooks', function () { const res = await getVideosList(servers[0].url) videoUUID = res.body.data[0].uuid - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - live: { enabled: true }, - signup: { enabled: true }, - import: { - videos: { - http: { enabled: true }, - torrent: { enabled: true } + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + live: { enabled: true }, + signup: { enabled: true }, + import: { + videos: { + http: { enabled: true }, + torrent: { enabled: true } + } } } }) @@ -344,8 +343,8 @@ describe('Test plugin filter hooks', function () { describe('Should run filter:api.user.signup.allowed.result', function () { it('Should run on config endpoint', async function () { - const res = await getConfig(servers[0].url) - expect((res.body as ServerConfig).signup.allowed).to.be.true + const body = await servers[0].configCommand.getConfig() + expect(body.signup.allowed).to.be.true }) it('Should allow a signup', async function () { @@ -365,13 +364,15 @@ describe('Test plugin filter hooks', function () { before(async function () { this.timeout(120000) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - webtorrent: { - enabled: true - }, - hls: { - enabled: true + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + webtorrent: { + enabled: true + }, + hls: { + enabled: true + } } } }) @@ -427,9 +428,11 @@ describe('Test plugin filter hooks', function () { before(async function () { this.timeout(60000) - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - transcoding: { - enabled: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + transcoding: { + enabled: false + } } }) @@ -464,12 +467,14 @@ describe('Test plugin filter hooks', function () { describe('Search filters', function () { before(async function () { - await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { - search: { - searchIndex: { - enabled: true, - isDefaultSearch: false, - disableLocalSearch: false + await servers[0].configCommand.updateCustomSubConfig({ + newConfig: { + search: { + searchIndex: { + enabled: true, + isDefaultSearch: false, + disableLocalSearch: false + } } } }) diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index 545968040..99de28d3f 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts @@ -5,7 +5,6 @@ import { expect } from 'chai' import { cleanupTests, flushAndRunServer, - getConfig, getMyUserInformation, getUsersList, login, @@ -19,7 +18,7 @@ import { wait, waitUntilLog } from '@shared/extra-utils' -import { ServerConfig, User, UserRole } from '@shared/models' +import { User, UserRole } from '@shared/models' describe('Test id and pass auth plugins', function () { let server: ServerInfo @@ -42,9 +41,7 @@ describe('Test id and pass auth plugins', function () { }) it('Should display the correct configuration', async function () { - const res = await getConfig(server.url) - - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const auths = config.plugin.registeredIdAndPassAuths expect(auths).to.have.lengthOf(8) @@ -190,9 +187,7 @@ describe('Test id and pass auth plugins', function () { }) it('Should have disabled this auth', async function () { - const res = await getConfig(server.url) - - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const auths = config.plugin.registeredIdAndPassAuths expect(auths).to.have.lengthOf(7) @@ -208,9 +203,7 @@ describe('Test id and pass auth plugins', function () { }) it('Should display the correct configuration', async function () { - const res = await getConfig(server.url) - - const config: ServerConfig = res.body + const config = await server.configCommand.getConfig() const auths = config.plugin.registeredIdAndPassAuths expect(auths).to.have.lengthOf(6) diff --git a/server/tests/plugins/plugin-transcoding.ts b/server/tests/plugins/plugin-transcoding.ts index f1ff91077..71c2adc72 100644 --- a/server/tests/plugins/plugin-transcoding.ts +++ b/server/tests/plugins/plugin-transcoding.ts @@ -9,7 +9,6 @@ import { cleanupTests, createLive, flushAndRunServer, - getConfig, getVideo, PluginsCommand, sendRTMPStreamInVideo, @@ -17,12 +16,11 @@ import { setAccessTokensToServers, setDefaultVideoChannel, testFfmpegStreamError, - updateCustomSubConfig, uploadVideoAndGetId, waitJobs, waitUntilLivePublished } from '@shared/extra-utils' -import { ServerConfig, VideoDetails, VideoPrivacy } from '@shared/models' +import { VideoDetails, VideoPrivacy } from '@shared/models' async function createLiveWrapper (server: ServerInfo) { const liveAttributes = { @@ -36,33 +34,35 @@ async function createLiveWrapper (server: ServerInfo) { } function updateConf (server: ServerInfo, vodProfile: string, liveProfile: string) { - return updateCustomSubConfig(server.url, server.accessToken, { - transcoding: { - enabled: true, - profile: vodProfile, - hls: { - enabled: true - }, - webtorrent: { - enabled: true - }, - resolutions: { - '240p': true, - '360p': false, - '480p': false, - '720p': true - } - }, - live: { + return server.configCommand.updateCustomSubConfig({ + newConfig: { transcoding: { - profile: liveProfile, enabled: true, + profile: vodProfile, + hls: { + enabled: true + }, + webtorrent: { + enabled: true + }, resolutions: { '240p': true, '360p': false, '480p': false, '720p': true } + }, + live: { + transcoding: { + profile: liveProfile, + enabled: true, + resolutions: { + '240p': true, + '360p': false, + '480p': false, + '720p': true + } + } } } }) @@ -113,8 +113,7 @@ describe('Test transcoding plugins', function () { }) it('Should have the appropriate available profiles', async function () { - const res = await getConfig(server.url) - const config = res.body as ServerConfig + const config = await server.configCommand.getConfig() expect(config.transcoding.availableProfiles).to.have.members([ 'default', 'low-vod', 'input-options-vod', 'bad-scale-vod' ]) expect(config.live.transcoding.availableProfiles).to.have.members([ 'default', 'low-live', 'input-options-live', 'bad-scale-live' ]) @@ -223,8 +222,7 @@ describe('Test transcoding plugins', function () { await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-transcoding-one' }) - const res = await getConfig(server.url) - const config = res.body as ServerConfig + const config = await server.configCommand.getConfig() expect(config.transcoding.availableProfiles).to.deep.equal([ 'default' ]) expect(config.live.transcoding.availableProfiles).to.deep.equal([ 'default' ]) diff --git a/shared/extra-utils/server/config-command.ts b/shared/extra-utils/server/config-command.ts new file mode 100644 index 000000000..959848706 --- /dev/null +++ b/shared/extra-utils/server/config-command.ts @@ -0,0 +1,260 @@ +import { merge } from 'lodash' +import { DeepPartial, HttpStatusCode } from '@shared/core-utils' +import { About, ServerConfig } from '@shared/models' +import { CustomConfig } from '../../models/server/custom-config.model' +import { AbstractCommand, OverrideCommandOptions } from '../shared' + +export class ConfigCommand extends AbstractCommand { + + static getCustomConfigResolutions (enabled: boolean) { + return { + '240p': enabled, + '360p': enabled, + '480p': enabled, + '720p': enabled, + '1080p': enabled, + '1440p': enabled, + '2160p': enabled + } + } + + getConfig (options: OverrideCommandOptions = {}) { + const path = '/api/v1/config' + + return this.getRequestBody({ + ...options, + + token: null, + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getAbout (options: OverrideCommandOptions = {}) { + const path = '/api/v1/config/about' + + return this.getRequestBody({ + ...options, + + token: null, + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + getCustomConfig (options: OverrideCommandOptions = {}) { + const path = '/api/v1/config/custom' + + return this.getRequestBody({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + updateCustomConfig (options: OverrideCommandOptions & { + newCustomConfig: CustomConfig + }) { + const path = '/api/v1/config/custom' + + return this.putBodyRequest({ + ...options, + + path, + fields: options.newCustomConfig, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + deleteCustomConfig (options: OverrideCommandOptions = {}) { + const path = '/api/v1/config/custom' + + return this.deleteRequest({ + ...options, + + path, + defaultExpectedStatus: HttpStatusCode.OK_200 + }) + } + + updateCustomSubConfig (options: OverrideCommandOptions & { + newConfig: DeepPartial + }) { + const newCustomConfig: CustomConfig = { + instance: { + name: 'PeerTube updated', + shortDescription: 'my short description', + description: 'my super description', + terms: 'my super terms', + codeOfConduct: 'my super coc', + + creationReason: 'my super creation reason', + moderationInformation: 'my super moderation information', + administrator: 'Kuja', + maintenanceLifetime: 'forever', + businessModel: 'my super business model', + hardwareInformation: '2vCore 3GB RAM', + + languages: [ 'en', 'es' ], + categories: [ 1, 2 ], + + isNSFW: true, + defaultNSFWPolicy: 'blur', + + defaultClientRoute: '/videos/recently-added', + + customizations: { + javascript: 'alert("coucou")', + css: 'body { background-color: red; }' + } + }, + theme: { + default: 'default' + }, + services: { + twitter: { + username: '@MySuperUsername', + whitelisted: true + } + }, + cache: { + previews: { + size: 2 + }, + captions: { + size: 3 + }, + torrents: { + size: 4 + } + }, + signup: { + enabled: false, + limit: 5, + requiresEmailVerification: false, + minimumAge: 16 + }, + admin: { + email: 'superadmin1@example.com' + }, + contactForm: { + enabled: true + }, + user: { + videoQuota: 5242881, + videoQuotaDaily: 318742 + }, + transcoding: { + enabled: true, + allowAdditionalExtensions: true, + allowAudioFiles: true, + threads: 1, + concurrency: 3, + profile: 'default', + resolutions: { + '0p': false, + '240p': false, + '360p': true, + '480p': true, + '720p': false, + '1080p': false, + '1440p': false, + '2160p': false + }, + webtorrent: { + enabled: true + }, + hls: { + enabled: false + } + }, + live: { + enabled: true, + allowReplay: false, + maxDuration: -1, + maxInstanceLives: -1, + maxUserLives: 50, + transcoding: { + enabled: true, + threads: 4, + profile: 'default', + resolutions: { + '240p': true, + '360p': true, + '480p': true, + '720p': true, + '1080p': true, + '1440p': true, + '2160p': true + } + } + }, + import: { + videos: { + concurrency: 3, + http: { + enabled: false + }, + torrent: { + enabled: false + } + } + }, + trending: { + videos: { + algorithms: { + enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], + default: 'hot' + } + } + }, + autoBlacklist: { + videos: { + ofUsers: { + enabled: false + } + } + }, + followers: { + instance: { + enabled: true, + manualApproval: false + } + }, + followings: { + instance: { + autoFollowBack: { + enabled: false + }, + autoFollowIndex: { + indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts', + enabled: false + } + } + }, + broadcastMessage: { + enabled: true, + level: 'warning', + message: 'hello', + dismissable: true + }, + search: { + remoteUri: { + users: true, + anonymous: true + }, + searchIndex: { + enabled: true, + url: 'https://search.joinpeertube.org', + disableLocalSearch: true, + isDefaultSearch: true + } + } + } + + merge(newCustomConfig, options.newConfig) + + return this.updateCustomConfig({ ...options, newCustomConfig }) + } +} diff --git a/shared/extra-utils/server/config.ts b/shared/extra-utils/server/config.ts deleted file mode 100644 index 9fcfb31fd..000000000 --- a/shared/extra-utils/server/config.ts +++ /dev/null @@ -1,260 +0,0 @@ -import { makeDeleteRequest, makeGetRequest, makePutBodyRequest } from '../requests/requests' -import { CustomConfig } from '../../models/server/custom-config.model' -import { DeepPartial, HttpStatusCode } from '@shared/core-utils' -import { merge } from 'lodash' - -function getConfig (url: string) { - const path = '/api/v1/config' - - return makeGetRequest({ - url, - path, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function getAbout (url: string) { - const path = '/api/v1/config/about' - - return makeGetRequest({ - url, - path, - statusCodeExpected: HttpStatusCode.OK_200 - }) -} - -function getCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) { - const path = '/api/v1/config/custom' - - return makeGetRequest({ - url, - token, - path, - statusCodeExpected - }) -} - -function updateCustomConfig (url: string, token: string, newCustomConfig: CustomConfig, statusCodeExpected = HttpStatusCode.OK_200) { - const path = '/api/v1/config/custom' - - return makePutBodyRequest({ - url, - token, - path, - fields: newCustomConfig, - statusCodeExpected - }) -} - -function updateCustomSubConfig (url: string, token: string, newConfig: DeepPartial) { - const updateParams: CustomConfig = { - instance: { - name: 'PeerTube updated', - shortDescription: 'my short description', - description: 'my super description', - terms: 'my super terms', - codeOfConduct: 'my super coc', - - creationReason: 'my super creation reason', - moderationInformation: 'my super moderation information', - administrator: 'Kuja', - maintenanceLifetime: 'forever', - businessModel: 'my super business model', - hardwareInformation: '2vCore 3GB RAM', - - languages: [ 'en', 'es' ], - categories: [ 1, 2 ], - - isNSFW: true, - defaultNSFWPolicy: 'blur', - - defaultClientRoute: '/videos/recently-added', - - customizations: { - javascript: 'alert("coucou")', - css: 'body { background-color: red; }' - } - }, - theme: { - default: 'default' - }, - services: { - twitter: { - username: '@MySuperUsername', - whitelisted: true - } - }, - cache: { - previews: { - size: 2 - }, - captions: { - size: 3 - }, - torrents: { - size: 4 - } - }, - signup: { - enabled: false, - limit: 5, - requiresEmailVerification: false, - minimumAge: 16 - }, - admin: { - email: 'superadmin1@example.com' - }, - contactForm: { - enabled: true - }, - user: { - videoQuota: 5242881, - videoQuotaDaily: 318742 - }, - transcoding: { - enabled: true, - allowAdditionalExtensions: true, - allowAudioFiles: true, - threads: 1, - concurrency: 3, - profile: 'default', - resolutions: { - '0p': false, - '240p': false, - '360p': true, - '480p': true, - '720p': false, - '1080p': false, - '1440p': false, - '2160p': false - }, - webtorrent: { - enabled: true - }, - hls: { - enabled: false - } - }, - live: { - enabled: true, - allowReplay: false, - maxDuration: -1, - maxInstanceLives: -1, - maxUserLives: 50, - transcoding: { - enabled: true, - threads: 4, - profile: 'default', - resolutions: { - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true - } - } - }, - import: { - videos: { - concurrency: 3, - http: { - enabled: false - }, - torrent: { - enabled: false - } - } - }, - trending: { - videos: { - algorithms: { - enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ], - default: 'hot' - } - } - }, - autoBlacklist: { - videos: { - ofUsers: { - enabled: false - } - } - }, - followers: { - instance: { - enabled: true, - manualApproval: false - } - }, - followings: { - instance: { - autoFollowBack: { - enabled: false - }, - autoFollowIndex: { - indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts', - enabled: false - } - } - }, - broadcastMessage: { - enabled: true, - level: 'warning', - message: 'hello', - dismissable: true - }, - search: { - remoteUri: { - users: true, - anonymous: true - }, - searchIndex: { - enabled: true, - url: 'https://search.joinpeertube.org', - disableLocalSearch: true, - isDefaultSearch: true - } - } - } - - merge(updateParams, newConfig) - - return updateCustomConfig(url, token, updateParams) -} - -function getCustomConfigResolutions (enabled: boolean) { - return { - '240p': enabled, - '360p': enabled, - '480p': enabled, - '720p': enabled, - '1080p': enabled, - '1440p': enabled, - '2160p': enabled - } -} - -function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) { - const path = '/api/v1/config/custom' - - return makeDeleteRequest({ - url, - token, - path, - statusCodeExpected - }) -} - -// --------------------------------------------------------------------------- - -export { - getConfig, - getCustomConfig, - updateCustomConfig, - getAbout, - deleteCustomConfig, - updateCustomSubConfig, - getCustomConfigResolutions -} diff --git a/shared/extra-utils/server/index.ts b/shared/extra-utils/server/index.ts index d37f46321..03c3b0123 100644 --- a/shared/extra-utils/server/index.ts +++ b/shared/extra-utils/server/index.ts @@ -1,4 +1,4 @@ -export * from './config' +export * from './config-command' export * from './contact-form-command' export * from './debug-command' export * from './follows-command' diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 4603cf62e..c33b68316 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts @@ -16,6 +16,7 @@ import { AbusesCommand } from '../moderation' import { OverviewsCommand } from '../overviews' import { makeGetRequest } from '../requests/requests' import { SearchCommand } from '../search' +import { ConfigCommand } from './config-command' import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' import { FollowsCommand } from './follows-command' @@ -91,6 +92,7 @@ interface ServerInfo { pluginsCommand?: PluginsCommand redundancyCommand?: RedundancyCommand statsCommand?: StatsCommand + configCommand?: ConfigCommand } function parallelTests () { @@ -311,6 +313,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] server.pluginsCommand = new PluginsCommand(server) server.redundancyCommand = new RedundancyCommand(server) server.statsCommand = new StatsCommand(server) + server.configCommand = new ConfigCommand(server) res(server) })