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({
70 enableTranscoding (webtorrent = true, hls = true) {
71 return this.updateExistingSubConfig({
76 allowAudioFiles: true,
77 allowAdditionalExtensions: true,
79 resolutions: ConfigCommand.getCustomConfigResolutions(true),
92 enableMinimumTranscoding (webtorrent = true, hls = true) {
93 return this.updateExistingSubConfig({
98 ...ConfigCommand.getCustomConfigResolutions(false),
114 getConfig (options: OverrideCommandOptions = {}) {
115 const path = '/api/v1/config'
117 return this.getRequestBody<ServerConfig>({
121 implicitToken: false,
122 defaultExpectedStatus: HttpStatusCode.OK_200
126 getAbout (options: OverrideCommandOptions = {}) {
127 const path = '/api/v1/config/about'
129 return this.getRequestBody<About>({
133 implicitToken: false,
134 defaultExpectedStatus: HttpStatusCode.OK_200
138 getCustomConfig (options: OverrideCommandOptions = {}) {
139 const path = '/api/v1/config/custom'
141 return this.getRequestBody<CustomConfig>({
146 defaultExpectedStatus: HttpStatusCode.OK_200
150 updateCustomConfig (options: OverrideCommandOptions & {
151 newCustomConfig: CustomConfig
153 const path = '/api/v1/config/custom'
155 return this.putBodyRequest({
159 fields: options.newCustomConfig,
161 defaultExpectedStatus: HttpStatusCode.OK_200
165 deleteCustomConfig (options: OverrideCommandOptions = {}) {
166 const path = '/api/v1/config/custom'
168 return this.deleteRequest({
173 defaultExpectedStatus: HttpStatusCode.OK_200
177 async updateExistingSubConfig (options: OverrideCommandOptions & {
178 newConfig: DeepPartial<CustomConfig>
180 const existing = await this.getCustomConfig({ ...options, expectedStatus: HttpStatusCode.OK_200 })
182 return this.updateCustomConfig({ ...options, newCustomConfig: merge({}, existing, options.newConfig) })
185 updateCustomSubConfig (options: OverrideCommandOptions & {
186 newConfig: DeepPartial<CustomConfig>
188 const newCustomConfig: CustomConfig = {
190 name: 'PeerTube updated',
191 shortDescription: 'my short description',
192 description: 'my super description',
193 terms: 'my super terms',
194 codeOfConduct: 'my super coc',
196 creationReason: 'my super creation reason',
197 moderationInformation: 'my super moderation information',
198 administrator: 'Kuja',
199 maintenanceLifetime: 'forever',
200 businessModel: 'my super business model',
201 hardwareInformation: '2vCore 3GB RAM',
203 languages: [ 'en', 'es' ],
204 categories: [ 1, 2 ],
207 defaultNSFWPolicy: 'blur',
209 defaultClientRoute: '/videos/recently-added',
212 javascript: 'alert("coucou")',
213 css: 'body { background-color: red; }'
221 username: '@MySuperUsername',
228 preferAuthorDisplayName: false
233 redirectOnSingleExternalAuth: false
251 requiresEmailVerification: false,
255 email: 'superadmin1@example.com'
262 videoQuotaDaily: 318742
269 allowAdditionalExtensions: true,
270 allowAudioFiles: true,
299 maxInstanceLives: -1,
334 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
349 manualApproval: false
358 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
376 url: 'https://search.joinpeertube.org',
377 disableLocalSearch: true,
378 isDefaultSearch: true
383 merge(newCustomConfig, options.newConfig)
385 return this.updateCustomConfig({ ...options, newCustomConfig })