1 import { merge } from 'lodash'
2 import { DeepPartial } from '@shared/typescript-utils'
3 import { About, HttpStatusCode, ServerConfig } from '@shared/models'
4 import { CustomConfig } from '../../models/server/custom-config.model'
5 import { AbstractCommand, OverrideCommandOptions } from '../shared'
7 export class ConfigCommand extends AbstractCommand {
9 static getCustomConfigResolutions (enabled: boolean) {
23 return this.updateExistingSubConfig({
40 enableLive (options: {
44 return this.updateExistingSubConfig({
48 allowReplay: options.allowReplay ?? true,
50 enabled: options.transcoding ?? true,
51 resolutions: ConfigCommand.getCustomConfigResolutions(true)
58 disableTranscoding () {
59 return this.updateExistingSubConfig({
68 enableTranscoding (webtorrent = true, hls = true) {
69 return this.updateExistingSubConfig({
73 resolutions: ConfigCommand.getCustomConfigResolutions(true),
86 getConfig (options: OverrideCommandOptions = {}) {
87 const path = '/api/v1/config'
89 return this.getRequestBody<ServerConfig>({
94 defaultExpectedStatus: HttpStatusCode.OK_200
98 getAbout (options: OverrideCommandOptions = {}) {
99 const path = '/api/v1/config/about'
101 return this.getRequestBody<About>({
105 implicitToken: false,
106 defaultExpectedStatus: HttpStatusCode.OK_200
110 getCustomConfig (options: OverrideCommandOptions = {}) {
111 const path = '/api/v1/config/custom'
113 return this.getRequestBody<CustomConfig>({
118 defaultExpectedStatus: HttpStatusCode.OK_200
122 updateCustomConfig (options: OverrideCommandOptions & {
123 newCustomConfig: CustomConfig
125 const path = '/api/v1/config/custom'
127 return this.putBodyRequest({
131 fields: options.newCustomConfig,
133 defaultExpectedStatus: HttpStatusCode.OK_200
137 deleteCustomConfig (options: OverrideCommandOptions = {}) {
138 const path = '/api/v1/config/custom'
140 return this.deleteRequest({
145 defaultExpectedStatus: HttpStatusCode.OK_200
149 async updateExistingSubConfig (options: OverrideCommandOptions & {
150 newConfig: DeepPartial<CustomConfig>
152 const existing = await this.getCustomConfig(options)
154 return this.updateCustomConfig({ ...options, newCustomConfig: merge({}, existing, options.newConfig) })
157 updateCustomSubConfig (options: OverrideCommandOptions & {
158 newConfig: DeepPartial<CustomConfig>
160 const newCustomConfig: CustomConfig = {
162 name: 'PeerTube updated',
163 shortDescription: 'my short description',
164 description: 'my super description',
165 terms: 'my super terms',
166 codeOfConduct: 'my super coc',
168 creationReason: 'my super creation reason',
169 moderationInformation: 'my super moderation information',
170 administrator: 'Kuja',
171 maintenanceLifetime: 'forever',
172 businessModel: 'my super business model',
173 hardwareInformation: '2vCore 3GB RAM',
175 languages: [ 'en', 'es' ],
176 categories: [ 1, 2 ],
179 defaultNSFWPolicy: 'blur',
181 defaultClientRoute: '/videos/recently-added',
184 javascript: 'alert("coucou")',
185 css: 'body { background-color: red; }'
193 username: '@MySuperUsername',
200 preferAuthorDisplayName: false
205 redirectOnSingleExternalAuth: false
223 requiresEmailVerification: false,
227 email: 'superadmin1@example.com'
234 videoQuotaDaily: 318742
241 allowAdditionalExtensions: true,
242 allowAudioFiles: true,
268 maxInstanceLives: -1,
300 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
315 manualApproval: false
324 indexUrl: 'https://instances.joinpeertube.org/api/v1/instances/hosts',
342 url: 'https://search.joinpeertube.org',
343 disableLocalSearch: true,
344 isDefaultSearch: true
349 merge(newCustomConfig, options.newConfig)
351 return this.updateCustomConfig({ ...options, newCustomConfig })