mirror of https://github.com/bastienwirtz/homer
Added download and upload speed to Sabnzbd
parent
68441f2b81
commit
ef95630225
|
@ -16,12 +16,45 @@
|
||||||
></i>
|
></i>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
<template #content>
|
||||||
|
<p class="title is-4">{{ item.name }}</p>
|
||||||
|
<p class="subtitle is-6">
|
||||||
|
<span v-if="error" class="error">An error has occurred.</span>
|
||||||
|
<template v-else>
|
||||||
|
<span class="down monospace">
|
||||||
|
<p class="fas fa-download"></p>
|
||||||
|
{{ downRate }}
|
||||||
|
</span>
|
||||||
|
<span class="up monospace">
|
||||||
|
<p class="fas fa-upload"></p>
|
||||||
|
{{ upRate }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
</Generic>
|
</Generic>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import service from "@/mixins/service.js";
|
import service from "@/mixins/service.js";
|
||||||
|
|
||||||
|
const units = ["B", "KB", "MB", "GB"];
|
||||||
|
|
||||||
|
// Function to convert rate into a human-readable format
|
||||||
|
const displayRate = (rate) => {
|
||||||
|
let i = 0;
|
||||||
|
|
||||||
|
while (rate > 1000 && i < units.length) {
|
||||||
|
rate /= 1000;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
Intl.NumberFormat(undefined, { maximumFractionDigits: 2 }).format(
|
||||||
|
rate || 0,
|
||||||
|
) + ` ${units[i]}/s`
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "SABnzbd",
|
name: "SABnzbd",
|
||||||
mixins: [service],
|
mixins: [service],
|
||||||
|
@ -31,14 +64,22 @@ export default {
|
||||||
data: () => ({
|
data: () => ({
|
||||||
stats: null,
|
stats: null,
|
||||||
error: false,
|
error: false,
|
||||||
|
dlSpeed: null,
|
||||||
|
ulSpeed: null,
|
||||||
}),
|
}),
|
||||||
computed: {
|
computed: {
|
||||||
downloads: function () {
|
downloads() {
|
||||||
if (!this.stats) {
|
if (!this.stats) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return this.stats.noofslots;
|
return this.stats.noofslots;
|
||||||
},
|
},
|
||||||
|
downRate() {
|
||||||
|
return displayRate(this.dlSpeed);
|
||||||
|
},
|
||||||
|
upRate() {
|
||||||
|
return displayRate(this.ulSpeed);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
const downloadInterval = parseInt(this.item.downloadInterval, 10) || 0;
|
const downloadInterval = parseInt(this.item.downloadInterval, 10) || 0;
|
||||||
|
@ -52,10 +93,14 @@ export default {
|
||||||
fetchStatus: async function () {
|
fetchStatus: async function () {
|
||||||
try {
|
try {
|
||||||
const response = await this.fetch(
|
const response = await this.fetch(
|
||||||
`/api?output=json&apikey=${this.item.apikey}&mode=queue`,
|
`/api?output=json&apikey=${this.item.apikey}&mode=queue`
|
||||||
);
|
);
|
||||||
this.error = false;
|
this.error = false;
|
||||||
this.stats = response.queue;
|
this.stats = response.queue;
|
||||||
|
|
||||||
|
// Assuming the response provides download/upload speeds
|
||||||
|
this.dlSpeed = response.queue.dl_speed; // Adjust this based on your API response
|
||||||
|
this.ulSpeed = response.queue.up_speed; // Adjust this based on your API response
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.error = true;
|
this.error = true;
|
||||||
console.error(e);
|
console.error(e);
|
||||||
|
@ -92,4 +137,17 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
color: #e51111 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.down {
|
||||||
|
margin-right: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.monospace {
|
||||||
|
font-weight: 300;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue