]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/server-commands/server/config-command.ts
Display live info in my videos
[github/Chocobozzz/PeerTube.git] / shared / server-commands / server / config-command.ts
index 89ae8eb4f69da3dd5e483594b2a2b2eb61f27403..ed4961bc3f72ea5c62990b15b7536a2882990e03 100644 (file)
@@ -1,8 +1,7 @@
 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 {
 
@@ -60,6 +59,9 @@ export class ConfigCommand extends AbstractCommand {
       newConfig: {
         transcoding: {
           enabled: false
+        },
+        videoStudio: {
+          enabled: false
         }
       }
     })
@@ -70,6 +72,10 @@ export class ConfigCommand extends AbstractCommand {
       newConfig: {
         transcoding: {
           enabled: true,
+
+          allowAudioFiles: true,
+          allowAdditionalExtensions: true,
+
           resolutions: ConfigCommand.getCustomConfigResolutions(true),
 
           webtorrent: {
@@ -83,6 +89,38 @@ export class ConfigCommand extends AbstractCommand {
     })
   }
 
+  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'
 
@@ -95,6 +133,21 @@ export class ConfigCommand extends AbstractCommand {
     })
   }
 
+  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'
 
@@ -149,7 +202,7 @@ export class ConfigCommand extends AbstractCommand {
   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) })
   }
@@ -264,6 +317,9 @@ export class ConfigCommand extends AbstractCommand {
       live: {
         enabled: true,
         allowReplay: false,
+        latencySetting: {
+          enabled: false
+        },
         maxDuration: -1,
         maxInstanceLives: -1,
         maxUserLives: 50,
@@ -283,6 +339,9 @@ export class ConfigCommand extends AbstractCommand {
           }
         }
       },
+      videoStudio: {
+        enabled: false
+      },
       import: {
         videos: {
           concurrency: 3,