REVERT: I'm not proud

This is slow af
Definitely needs more work
This commit is contained in:
2025-10-09 15:42:31 +02:00
parent b2f155c0b4
commit 53ae5495aa
6 changed files with 245 additions and 99 deletions

View File

@@ -1,6 +1,6 @@
"use strict";
class trdom_torrentcontrol {
class trdom_torrentcontrol extends EventTarget {
#logcb;
#log(loglevel, msg) {
if (this.#logcb !== null) {
@@ -16,8 +16,74 @@ class trdom_torrentcontrol {
#hash;
#server;
//TODO: remove
#getKnownTorrents;
#updateDOM(data) {
let control_element = this.#element;
let status = control_element.element_status;
control_element.classList.remove(
'trweb_status_asdf',
'trweb_status_offline',
'trweb_status_nonexistent',
'trweb_status_paused',
'trweb_status_verifqueued',
'trweb_status_verifying',
'trweb_status_downloading',
'trweb_status_seeding'
);
nukeChildren(status);
let statustext = 'Nothing to see here';
let statusclass = 'trweb_status_asdf'
let barwidth = 50;
if (!this.#server.isOnline()) {
statustext = "Server offline";
statusclass = 'trweb_status_offline';
barwidth = 0;
}
else {
let server_status = data;
if (server_status == undefined || server_status.deleted) {
statustext = "Not available";
statusclass = 'trweb_status_nonexistent';
barwidth = 0;
}
else {
statustext = `${server_status.status}`;
barwidth = server_status.percentDone;
switch (server_status.status) {
case 0:
statustext = 'Paused';
statusclass = 'trweb_status_paused';
break;
case 1:
statustext = 'Queued for verification';
statusclass = 'trweb_status_verifqueued';
break;
case 2:
statustext = 'Verifying';
statusclass = 'trweb_status_verifying';
break;
case 3:
statustext = 'Queued';
break;
case 4:
statustext = 'Downloading';
statusclass = 'trweb_status_downloading';
break;
case 6:
statustext = 'Seeding';
statusclass = 'trweb_status_seeding';
break;
}
statustext = `[${this.#server.name}]: ${statustext} - ${server_status.percentDone}%`;
}
}
control_element.element_statusbar.style.width = `${barwidth}%`;
control_element.classList.add(statusclass);
status.appendChild(document.createTextNode(statustext));
}
handleEvent(e) {
switch (e.type) {
@@ -33,7 +99,7 @@ class trdom_torrentcontrol {
e.stopPropagation();
break;
case 'magnet':
let magneturl;
/*let magneturl;
for (const [srv, data] of Object.entries(this.#getKnownTorrents()[this.#hash].servers)) {
if (data.magnetLink != null) {
magneturl = data.magnetLink;
@@ -45,8 +111,9 @@ class trdom_torrentcontrol {
}
else {
this.#log(3, `Couldn't find magnet link! ${JSON.stringify(this.#getKnownTorrents()[this.#hash].servers)}`);
}
}*/
e.stopPropagation();
window.alert('not implemented');
break;
case 'download':
e.stopPropagation();
@@ -54,14 +121,20 @@ class trdom_torrentcontrol {
break;
}
}
break;
case 'torrent-update':
if (e.detail.torrentHash == this.#hash) {
this.#updateDOM(e.detail.torrentInfo);
}
break;
}
}
constructor(hash, server, logcb, getKnownTorrents) {
constructor(hash, server, initdata = null, logcb = null) {
super();
this.#hash = hash;
this.#server = server;
this.#logcb = logcb;
this.#getKnownTorrents = getKnownTorrents;
let srv = server.name;
@@ -130,6 +203,12 @@ class trdom_torrentcontrol {
this.#element.element_pause = element_pause;
this.#element.element_magnet = element_magnet;
this.#element.element_download = element_download;
if (initdata != null) {
this.#updateDOM(initdata);
}
server.addEventListener('torrent-update', this);
}
}