]> git.immae.eu Git - github/bastienwirtz/homer.git/blobdiff - src/components/services/PiHole.vue
Merge pull request #225 from bastienwirtz/dependabot/npm_and_yarn/dns-packet-1.3.4
[github/bastienwirtz/homer.git] / src / components / services / PiHole.vue
index 10d5ece9e25327341e8a0df5cc70fbd750b1dd68..a9fd369c2a87ba30bc048f352aeab276f4dac187 100644 (file)
                 <template v-if="item.subtitle">
                   {{ item.subtitle }}
                 </template>
-                <template v-else-if="status">
-                  {{ percentage }}% blocked
+                <template v-else-if="api">
+                  {{ percentage }}&percnt; blocked
                 </template>
               </p>
             </div>
-            <div v-if="status" class="status" :class="status.status">
-              {{ status.status }}
+            <div v-if="api" class="status" :class="api.status">
+              {{ api.status }}
             </div>
           </div>
           <div class="tag" :class="item.tagstyle" v-if="item.tag">
@@ -44,27 +44,29 @@ export default {
   props: {
     item: Object,
   },
-  data: () => {
-    return {
-      status: null,
-    };
-  },
+  data: () => ({
+    api: {
+      status: "",
+      ads_percentage_today: 0,
+    },
+  }),
   computed: {
-    blocked: function () {
-      if (this.status) {
-        return this.status.dns_queries_today.toFixed(0);
+    percentage: function () {
+      if (this.api) {
+        return this.api.ads_percentage_today.toFixed(1);
       }
       return "";
     },
   },
-  created: function () {
+  created() {
     this.fetchStatus();
   },
   methods: {
     fetchStatus: async function () {
-      this.status = await fetch(`${this.item.url}/api.php`).then((response) =>
-        response.json()
-      );
+      const url = `${this.item.url}/api.php`;
+      this.api = await fetch(url)
+        .then((response) => response.json())
+        .catch((e) => console.log(e));
     },
   },
 };