1 import { merge } from 'lodash'
2 import { About, CustomConfig, HttpStatusCode, ServerConfig } from '@shared/models'
3 import { DeepPartial } from '@shared/typescript-utils'
4 import { AbstractCommand, OverrideCommandOptions } from '../shared/abstract-command'
6 export class ConfigCommand extends AbstractCommand {
8 static getCustomConfigResolutions (enabled: boolean) {
22 return this.updateExistingSubConfig({
39 enableLive (options: {
43 return this.updateExistingSubConfig({
47 allowReplay: options.allowReplay ?? true,
49 enabled: options.transcoding ?? true,
50 resolutions: ConfigCommand.getCustomConfigResolutions(true)
57 disableTranscoding () {
58 return this.updateExistingSubConfig({
67 enableTranscoding (webtorrent = true, hls = true) {
68 return this.updateExistingSubConfig({
72 resolutions: ConfigCommand.getCustomConfigResolutions(true),
85 getConfig (options: OverrideCommandOptions = {}) {
86 const path = '/api/v1/config'
88 return this.getRequestBody<ServerConfig>({
93 defaultExpectedStatus: HttpStatusCode.OK_200
97 getAbout (options: OverrideCommandOptions = {}) {
98 const path = '/api/v1/config/about'
100 return this.getRequestBody<About>({
104 implicitToken: false,
105 defaultExpectedStatus: HttpStatusCode.OK_200
109 getCustomConfig (options: OverrideCommandOptions = {}) {
110 const path = '/api/v1/config/custom'
112 return this.getRequestBody<CustomConfig>({
117 defaultExpectedStatus: HttpStatusCode.OK_200
121 updateCustomConfig (options: OverrideCommandOptions & {
122 newCustomConfig: CustomConfig
124 const path = '/api/v1/config/custom'
126 return this.putBodyRequest({
130 fields: options.newCustomConfig,
132 defaultExpectedStatus: HttpStatusCode.OK_200
136 deleteCustomConfig (options: OverrideCommandOptions = {}) {
137 const path = '/api/v1/config/custom'
139 return this.deleteRequest({
144 defaultExpectedStatus: HttpStatusCode.OK_200
148 async updateExistingSubConfig (options: OverrideCommandOptions & {
149 newConfig: DeepPartial<CustomConfig>
151 const existing = await this.getCustomConfig(options)
153 return this.updateCustomConfig({ ...options, newCustomConfig: merge({}, existing, options.newConfig) })
156 updateCustomSubConfig (options: OverrideCommandOptions & {
157 newConfig: DeepPartial<CustomConfig>
159 const newCustomConfig: CustomConfig = {
161 name: 'PeerTube updated',
162 shortDescription: 'my short description',
163 description: 'my super description',
164 terms: 'my super terms',
165 codeOfConduct: 'my super coc',
167 creationReason: 'my super creation reason',
168 moderationInformation: 'my super moderation information',
169 administrator: 'Kuja',
170 maintenanceLifetime: 'forever',
171 businessModel: 'my super business model',
172 hardwareInformation: '2vCore 3GB RAM',
174 languages: [ 'en', 'es' ],
175 categories: [ 1, 2 ],
178 defaultNSFWPolicy: 'blur',
180 defaultClientRoute: '/videos/recently-added',
183 javascript: 'alert("coucou")',
184 css: 'body { background-color: red; }'
192 username: '@MySuperUsername',
199 preferAuthorDisplayName: false
204 redirectOnSingleExternalAuth: false
222 requiresEmailVerification: false,
226 email: 'superadmin1@example.com'
233 videoQuotaDaily: 318742
240 allowAdditionalExtensions: true,
241 allowAudioFiles: true,
267 maxInstanceLives: -1,
299 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
314 manualApproval: false
323 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
341 url: 'https://search.joinpeertube.org',
342 disableLocalSearch: true,
343 isDefaultSearch: true
348 merge(newCustomConfig, options.newConfig)
350 return this.updateCustomConfig({ ...options, newCustomConfig })