import { merge } from 'lodash'
+import { About, CustomConfig, HttpStatusCode, ServerConfig } from '@shared/models'
import { DeepPartial } from '@shared/typescript-utils'
-import { About, HttpStatusCode, ServerConfig } from '@shared/models'
-import { CustomConfig } from '../../models/server/custom-config.model'
-import { AbstractCommand, OverrideCommandOptions } from '../shared'
+import { AbstractCommand, OverrideCommandOptions } from '../shared/abstract-command'
export class ConfigCommand extends AbstractCommand {
}
}
+ // ---------------------------------------------------------------------------
+
+ static getEmailOverrideConfig (emailPort: number) {
+ return {
+ smtp: {
+ hostname: '127.0.0.1',
+ port: emailPort
+ }
+ }
+ }
+
+ // ---------------------------------------------------------------------------
+
+ enableSignup (requiresApproval: boolean, limit = -1) {
+ return this.updateExistingSubConfig({
+ newConfig: {
+ signup: {
+ enabled: true,
+ requiresApproval,
+ limit
+ }
+ }
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ disableImports () {
+ return this.setImportsEnabled(false)
+ }
+
enableImports () {
+ return this.setImportsEnabled(true)
+ }
+
+ private setImportsEnabled (enabled: boolean) {
return this.updateExistingSubConfig({
newConfig: {
import: {
videos: {
http: {
- enabled: true
+ enabled
},
torrent: {
- enabled: true
+ enabled
}
}
}
})
}
+ // ---------------------------------------------------------------------------
+
+ enableChannelSync () {
+ return this.setChannelSyncEnabled(true)
+ }
+
+ disableChannelSync () {
+ return this.setChannelSyncEnabled(false)
+ }
+
+ private setChannelSyncEnabled (enabled: boolean) {
+ return this.updateExistingSubConfig({
+ newConfig: {
+ import: {
+ videoChannelSynchronization: {
+ enabled
+ }
+ }
+ }
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
enableLive (options: {
allowReplay?: boolean
transcoding?: boolean
+ resolutions?: 'min' | 'max' // Default max
} = {}) {
+ const { allowReplay, transcoding, resolutions = 'max' } = options
+
return this.updateExistingSubConfig({
newConfig: {
live: {
enabled: true,
- allowReplay: options.allowReplay ?? true,
+ allowReplay: allowReplay ?? true,
transcoding: {
- enabled: options.transcoding ?? true,
- resolutions: ConfigCommand.getCustomConfigResolutions(true)
+ enabled: transcoding ?? true,
+ resolutions: ConfigCommand.getCustomConfigResolutions(resolutions === 'max')
}
}
}
newConfig: {
transcoding: {
enabled: false
+ },
+ videoStudio: {
+ enabled: false
}
}
})
newConfig: {
transcoding: {
enabled: true,
+
+ allowAudioFiles: true,
+ allowAdditionalExtensions: true,
+
resolutions: ConfigCommand.getCustomConfigResolutions(true),
webtorrent: {
})
}
+ enableMinimumTranscoding (webtorrent = true, hls = true) {
+ return this.updateExistingSubConfig({
+ newConfig: {
+ transcoding: {
+ enabled: true,
+ resolutions: {
+ ...ConfigCommand.getCustomConfigResolutions(false),
+
+ '240p': true
+ },
+
+ webtorrent: {
+ enabled: webtorrent
+ },
+ hls: {
+ enabled: hls
+ }
+ }
+ }
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
+ enableStudio () {
+ return this.updateExistingSubConfig({
+ newConfig: {
+ videoStudio: {
+ enabled: true
+ }
+ }
+ })
+ }
+
+ // ---------------------------------------------------------------------------
+
getConfig (options: OverrideCommandOptions = {}) {
const path = '/api/v1/config'
})
}
+ async getIndexHTMLConfig (options: OverrideCommandOptions = {}) {
+ const text = await this.getRequestText({
+ ...options,
+
+ path: '/',
+ implicitToken: false,
+ defaultExpectedStatus: HttpStatusCode.OK_200
+ })
+
+ const match = text.match('<script type="application/javascript">window.PeerTubeServerConfig = (".+?")</script>')
+
+ // We parse the string twice, first to extract the string and then to extract the JSON
+ return JSON.parse(JSON.parse(match[1])) as ServerConfig
+ }
+
getAbout (options: OverrideCommandOptions = {}) {
const path = '/api/v1/config/about'
async updateExistingSubConfig (options: OverrideCommandOptions & {
newConfig: DeepPartial<CustomConfig>
}) {
- const existing = await this.getCustomConfig(options)
+ const existing = await this.getCustomConfig({ ...options, expectedStatus: HttpStatusCode.OK_200 })
return this.updateCustomConfig({ ...options, newCustomConfig: merge({}, existing, options.newConfig) })
}
signup: {
enabled: false,
limit: 5,
+ requiresApproval: true,
requiresEmailVerification: false,
minimumAge: 16
},
'1440p': false,
'2160p': false
},
+ alwaysTranscodeOriginalResolution: true,
webtorrent: {
enabled: true
},
live: {
enabled: true,
allowReplay: false,
+ latencySetting: {
+ enabled: false
+ },
maxDuration: -1,
maxInstanceLives: -1,
maxUserLives: 50,
'1080p': true,
'1440p': true,
'2160p': true
- }
+ },
+ alwaysTranscodeOriginalResolution: true
}
},
+ videoStudio: {
+ enabled: false
+ },
import: {
videos: {
concurrency: 3,
torrent: {
enabled: false
}
+ },
+ videoChannelSynchronization: {
+ enabled: false,
+ maxPerUser: 10
}
},
trending: {
videos: {
algorithms: {
- enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
+ enabled: [ 'hot', 'most-viewed', 'most-liked' ],
default: 'hot'
}
}