]> git.immae.eu Git - github/bastienwirtz/homer.git/commitdiff
Merge pull request #365 from nthduy-deevotech/fix/sonarr-radarr-api
authorBastien Wirtz <bastien.wirtz@gmail.com>
Thu, 10 Feb 2022 20:52:05 +0000 (21:52 +0100)
committerGitHub <noreply@github.com>
Thu, 10 Feb 2022 20:52:05 +0000 (21:52 +0100)
Support for Radarr, Sonarr V3 API

docs/customservices.md
src/components/services/Radarr.vue
src/components/services/Sonarr.vue

index 747d7a4638e0fbdb804b3a3328e626a338114486..7e3e6b3e60a9c4f48962e10b3087f73e6ab180a3 100644 (file)
@@ -79,6 +79,16 @@ Two lines are needed in the config.yml :
 
 The url must be the root url of Lidarr, Prowlarr, Radarr or Sonarr application.
 The Lidarr, Prowlarr, Radarr or Sonarr API key can be found in Settings > General. It is needed to access the API.
+If you are using an older version of Radarr or Sonarr which don't support the new V3 api endpoints, add the following line to your service config "legacyApi: true", example: 
+
+```yaml
+- name: "Radarr"
+  type: "Radarr"
+  url: "http://localhost:7878/"
+  apikey: "MY-SUPER-SECRET-API-KEY"
+  target: "_blank"
+  legacyApi: true
+```
 
 ## PaperlessNG
 
index a57c895f0e0e9bc9e10b48f5ef5c08c3df837e1b..757366717bef380bfdad099ff69126e947d278ab 100644 (file)
@@ -26,6 +26,9 @@
 import service from "@/mixins/service.js";
 import Generic from "./Generic.vue";
 
+const V3_API = "/api/v3";
+const LEGACY_API = "/api";
+
 export default {
   name: "Radarr",
   mixins: [service],
@@ -46,9 +49,14 @@ export default {
   created: function () {
     this.fetchConfig();
   },
+  computed: {
+    apiPath() {
+      return this.item.legacyApi ? LEGACY_API : V3_API;
+    },
+  },
   methods: {
     fetchConfig: function () {
-      this.fetch(`/api/health?apikey=${this.item.apikey}`)
+      this.fetch(`${this.apiPath}/health?apikey=${this.item.apikey}`)
         .then((health) => {
           this.warnings = 0;
           this.errors = 0;
@@ -64,12 +72,21 @@ export default {
           console.error(e);
           this.serverError = true;
         });
-      this.fetch(`/api/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].movie) {
-              this.activity++;
+
+          if (this.item.legacyApi) {
+            for (var i = 0; i < queue.length; i++) {
+              if (queue[i].movie) {
+                this.activity++;
+              }
+            }
+          } else {
+            for (const record of queue.records) {
+              if (record.movieId) {
+                this.activity++;
+              }
             }
           }
         })
index f8dd0d1ac4e0e0db80bc19645161f6d79987b9d6..55df43748ae73512055b3663f328717c0664fc54 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/health?apikey=${this.item.apikey}`)
+      this.fetch(`${this.apiPath}/health?apikey=${this.item.apikey}`)
         .then((health) => {
           this.warnings = 0;
           this.errors = 0;
@@ -65,12 +73,20 @@ export default {
           console.error(e);
           this.serverError = true;
         });
-      this.fetch(`/api/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 {
+            for (const record of queue.records) {
+              if (record.seriesId) {
+                this.activity++;
+              }
             }
           }
         })