]> git.immae.eu Git - github/bastienwirtz/homer.git/blobdiff - src/components/services/Sonarr.vue
Fix lint issues
[github/bastienwirtz/homer.git] / src / components / services / Sonarr.vue
index 972a1c9fc3a001887860db1d9eb199783dd8ba69..bb83b6b00a485055f747d934d51ef72b2ab94756 100644 (file)
@@ -27,6 +27,9 @@
 import service from "@/mixins/service.js";
 import Generic from "./Generic.vue";
 
+const V3_API = "/api/v3";
+const LEGACY_API = "/api";
+
 export default {
   name: "Sonarr",
   mixins: [service],
@@ -36,6 +39,11 @@ export default {
   components: {
     Generic,
   },
+  computed: {
+    apiPath() {
+      return this.item.legacyApi ? LEGACY_API : V3_API;
+    },
+  },
   data: () => {
     return {
       activity: null,
@@ -49,7 +57,7 @@ export default {
   },
   methods: {
     fetchConfig: function () {
-      this.fetch(`/api/v3/health?apikey=${this.item.apikey}`)
+      this.fetch(`${this.apiPath}/health?apikey=${this.item.apikey}`)
         .then((health) => {
           this.warnings = 0;
           this.errors = 0;
@@ -65,13 +73,17 @@ export default {
           console.error(e);
           this.serverError = true;
         });
-      this.fetch(`/api/v3/queue?apikey=${this.item.apikey}`)
+      this.fetch(`${this.apiPath}/queue?apikey=${this.item.apikey}`)
         .then((queue) => {
           this.activity = 0;
-          for (var i = 0; i < queue.length; i++) {
-            if (queue[i].series) {
-              this.activity++;
+          if (this.item.legacyApi) {
+            for (var i = 0; i < queue.length; i++) {
+              if (queue[i].series) {
+                this.activity++;
+              }
             }
+          } else {
+            this.activity = queue.totalRecords;
           }
         })
         .catch((e) => {