Add warning if admin disables webtorrent
authorChocobozzz <me@florianbigard.com>
Mon, 6 Jan 2020 15:43:15 +0000 (16:43 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 6 Jan 2020 16:10:02 +0000 (17:10 +0100)
client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.html
client/src/app/+admin/config/edit-custom-config/edit-custom-config.component.ts
config/default.yaml
config/production.yaml.example
server/middlewares/validators/config.ts

index 27f5ef7224263f510b9a9272dead54c8584b0e99..ac0447d257d2c069aa21e0b26d98d30c1b08272f 100644 (file)
                       <strong>Experimental, we suggest you to not disable webtorrent support for now</strong>
 
                       <p>If you also enabled HLS support, it will multiply videos storage by 2</p>
+
+                      <br />
+
+                      <strong>If disabled, breaks federation with PeerTube instances < 2.1</strong>
                     </ng-container>
                   </ng-template>
                 </my-peertube-checkbox>
index 3fda0851efa9da12e0807788f120251cf6e8427d..49bb4db0e10f04eff0aadf321798da0e0ea3682f 100644 (file)
@@ -222,25 +222,8 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
     }
 
     this.buildForm(formGroupData)
-
-    forkJoin([
-      this.configService.getCustomConfig(),
-      this.serverService.getVideoLanguages(),
-      this.serverService.getVideoCategories()
-    ]).subscribe(
-      ([ config, languages, categories ]) => {
-        this.customConfig = config
-
-        this.languageItems = languages.map(l => ({ label: l.label, value: l.id }))
-        this.categoryItems = categories.map(l => ({ label: l.label, value: l.id }))
-
-        this.updateForm()
-        // Force form validation
-        this.forceCheck()
-      },
-
-      err => this.notifier.error(err.message)
-    )
+    this.loadForm()
+    this.checkTranscodingFields()
   }
 
   isTranscodingEnabled () {
@@ -252,9 +235,7 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
   }
 
   async formValidated () {
-    this.configService.updateCustomConfig(this.form.value)
-      .pipe(
-      )
+    this.configService.updateCustomConfig(this.form.getRawValue())
       .subscribe(
         res => {
           this.customConfig = res
@@ -290,4 +271,52 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit {
   private updateForm () {
     this.form.patchValue(this.customConfig)
   }
+
+  private loadForm () {
+    forkJoin([
+      this.configService.getCustomConfig(),
+      this.serverService.getVideoLanguages(),
+      this.serverService.getVideoCategories()
+    ]).subscribe(
+      ([ config, languages, categories ]) => {
+        this.customConfig = config
+
+        this.languageItems = languages.map(l => ({ label: l.label, value: l.id }))
+        this.categoryItems = categories.map(l => ({ label: l.label, value: l.id }))
+
+        this.updateForm()
+        // Force form validation
+        this.forceCheck()
+      },
+
+      err => this.notifier.error(err.message)
+    )
+  }
+
+  private checkTranscodingFields () {
+    const hlsControl = this.form.get('transcoding.hls.enabled')
+    const webtorrentControl = this.form.get('transcoding.webtorrent.enabled')
+
+    webtorrentControl.valueChanges
+                     .subscribe(newValue => {
+                       if (newValue === false && !hlsControl.disabled) {
+                         hlsControl.disable()
+                       }
+
+                       if (newValue === true && !hlsControl.enabled) {
+                         hlsControl.enable()
+                       }
+                     })
+
+    hlsControl.valueChanges
+              .subscribe(newValue => {
+                if (newValue === false && !webtorrentControl.disabled) {
+                  webtorrentControl.disable()
+                }
+
+                if (newValue === true && !webtorrentControl.enabled) {
+                  webtorrentControl.enable()
+                }
+              })
+  }
 }
index 7fe817aa08d37864fa409d5a79ddb8f3200e1b44..8e866c1264029ac9683514b33d914e13e44bceb2 100644 (file)
@@ -216,6 +216,7 @@ transcoding:
 
   # Generate videos in a WebTorrent format (what we do since the first PeerTube release)
   # If you also enabled the hls format, it will multiply videos storage by 2
+  # If disabled, breaks federation with PeerTube instances < 2.1
   webtorrent:
     enabled: true
 
index 629d0c4b620b158ffc2a43c2bca115879ffaf7e3..68d29d26faf85a301588aacb5580d12c379d7d60 100644 (file)
@@ -230,6 +230,7 @@ transcoding:
 
   # Generate videos in a WebTorrent format (what we do since the first PeerTube release)
   # If you also enabled the hls format, it will multiply videos storage by 2
+  # If disabled, breaks federation with PeerTube instances < 2.1
   webtorrent:
     enabled: true
 
index d86fa700b5ecd421205ba7ae373c93cf0dc6af84..2d1f61947036a7b095b24b11e2e4ce13b27beedc 100644 (file)
@@ -45,7 +45,7 @@ const customConfigUpdateValidator = [
   body('transcoding.resolutions.1080p').isBoolean().withMessage('Should have a valid transcoding 1080p resolution enabled boolean'),
 
   body('transcoding.webtorrent.enabled').isBoolean().withMessage('Should have a valid webtorrent transcoding enabled boolean'),
-  body('transcoding.hls.enabled').isBoolean().withMessage('Should have a valid webtorrent transcoding enabled boolean'),
+  body('transcoding.hls.enabled').isBoolean().withMessage('Should have a valid hls transcoding enabled boolean'),
 
   body('import.videos.http.enabled').isBoolean().withMessage('Should have a valid import video http enabled boolean'),
   body('import.videos.torrent.enabled').isBoolean().withMessage('Should have a valid import video torrent enabled boolean'),