Files
torsearch/assets/components/status-checker-span.js
Brock H Caldwell c4b3fb215c
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after -1m38s
feat: status indicators in header for tmdb & torrentio
2026-03-07 11:11:33 -06:00

41 lines
1004 B
JavaScript

export default class PreviewContentDialog extends HTMLSpanElement {
#url;
#service;
#status;
#statusTexts = {
200: 'up',
204: 'up'
}
#statusColors = {
200: 'bg-green-500',
204: 'bg-green-500'
}
constructor() {
super();
this.#url = this.getAttribute('url');
this.#service = this.getAttribute('service');
(async () => await this.checkStatus())();
setInterval(async () => await this.checkStatus(), 1000 * 60 * 10);
}
async checkStatus() {
const response = await fetch(this.#url);
this.#status = response.status;
this.setAttribute('title', this.getTitle());
this.classList.remove('bg-red-500', 'bg-green-500');
this.classList.add(this.getColor());
}
getTitle() {
return `${this.#service} is ${this.#statusTexts[this.#status] ?? 'down'}`
}
getColor() {
return this.#statusColors[this.#status] ?? 'bg-red-500';
}
}