nexus33rd commited on
Commit
d857ce3
·
verified ·
1 Parent(s): ea4fab5

Upload 20 files

Browse files
Files changed (2) hide show
  1. static/app.js +33 -2
  2. templates/index.html +31 -36
static/app.js CHANGED
@@ -466,7 +466,9 @@
466
  elements.summaryPaused.textContent = String(counts.paused);
467
  elements.summaryAllTimeDownload.textContent = String(stats.all_time_download ?? "0 B");
468
  elements.summaryAllTimeUpload.textContent = String(stats.all_time_upload ?? "0 B");
469
- elements.torrentCount.textContent = `${filteredTorrents().length} item`;
 
 
470
  }
471
 
472
  function updateConnection(isConnected, versionText) {
@@ -638,6 +640,31 @@
638
  }
639
  }
640
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
641
  async function triggerTorrentAction(action, hash, mode = null) {
642
  const method = action === "delete" ? "DELETE" : "POST";
643
  const query = mode ? `?mode=${encodeURIComponent(mode)}` : "";
@@ -695,6 +722,7 @@
695
  const submitButton = form.querySelector('button[type="submit"]');
696
  submitButton.disabled = true;
697
  submitButton.classList.add("opacity-70");
 
698
  try {
699
  const response = await fetch(form.action, {
700
  method: form.method || "POST",
@@ -712,7 +740,10 @@
712
  form.reset();
713
  closeAddModal();
714
  showToast(payload.message || successMessage);
715
- await refreshTorrents();
 
 
 
716
  } finally {
717
  submitButton.disabled = false;
718
  submitButton.classList.remove("opacity-70");
 
466
  elements.summaryPaused.textContent = String(counts.paused);
467
  elements.summaryAllTimeDownload.textContent = String(stats.all_time_download ?? "0 B");
468
  elements.summaryAllTimeUpload.textContent = String(stats.all_time_upload ?? "0 B");
469
+ if (elements.torrentCount) {
470
+ elements.torrentCount.textContent = `${filteredTorrents().length} item`;
471
+ }
472
  }
473
 
474
  function updateConnection(isConnected, versionText) {
 
640
  }
641
  }
642
 
643
+ function delay(ms) {
644
+ return new Promise((resolve) => window.setTimeout(resolve, ms));
645
+ }
646
+
647
+ async function waitForTorrentListMutation(previousHashes, attempts = 6, intervalMs = 1200) {
648
+ for (let attempt = 0; attempt < attempts; attempt += 1) {
649
+ await refreshTorrents();
650
+ const currentHashes = new Set((state.torrents || []).map((torrent) => torrent.hash));
651
+ let changed = currentHashes.size !== previousHashes.size;
652
+ if (!changed) {
653
+ for (const hash of currentHashes) {
654
+ if (!previousHashes.has(hash)) {
655
+ changed = true;
656
+ break;
657
+ }
658
+ }
659
+ }
660
+ if (changed) {
661
+ return true;
662
+ }
663
+ await delay(intervalMs);
664
+ }
665
+ return false;
666
+ }
667
+
668
  async function triggerTorrentAction(action, hash, mode = null) {
669
  const method = action === "delete" ? "DELETE" : "POST";
670
  const query = mode ? `?mode=${encodeURIComponent(mode)}` : "";
 
722
  const submitButton = form.querySelector('button[type="submit"]');
723
  submitButton.disabled = true;
724
  submitButton.classList.add("opacity-70");
725
+ const previousHashes = new Set((state.torrents || []).map((torrent) => torrent.hash));
726
  try {
727
  const response = await fetch(form.action, {
728
  method: form.method || "POST",
 
740
  form.reset();
741
  closeAddModal();
742
  showToast(payload.message || successMessage);
743
+ const appeared = await waitForTorrentListMutation(previousHashes);
744
+ if (!appeared) {
745
+ await refreshTorrents();
746
+ }
747
  } finally {
748
  submitButton.disabled = false;
749
  submitButton.classList.remove("opacity-70");
templates/index.html CHANGED
@@ -81,10 +81,6 @@
81
  </div>
82
  </div>
83
  </div>
84
- <button id="open-add-modal" type="button" class="inline-flex items-center gap-2 rounded-2xl border border-neon/30 bg-neon/12 px-4 py-3 text-sm font-semibold text-neon transition hover:bg-neon/20">
85
- <i class="fa-solid fa-plus"></i>
86
- Add
87
- </button>
88
  </div>
89
  </div>
90
 
@@ -103,42 +99,46 @@
103
  {% endfor %}
104
  </div>
105
 
106
- <section class="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
107
- <article class="rounded-[26px] border border-white/10 bg-[linear-gradient(180deg,rgba(16,18,28,0.95),rgba(9,11,18,0.92))] px-5 py-4 shadow-halo">
108
- <p class="text-[11px] uppercase tracking-[0.25em] text-stone-500">Total</p>
109
- <div class="mt-3 flex items-center justify-between">
110
- <p id="summary-total" class="text-3xl font-bold text-white">{{ stats.torrent_count }}</p>
111
- <div class="flex h-11 w-11 items-center justify-center rounded-2xl bg-white/[0.04] text-stone-300">
112
  <i class="fa-solid fa-hard-drive"></i>
113
  </div>
114
  </div>
 
 
115
  </article>
116
- <article class="rounded-[26px] border border-white/10 bg-[linear-gradient(180deg,rgba(16,18,28,0.95),rgba(9,11,18,0.92))] px-5 py-4 shadow-halo">
117
- <p class="text-[11px] uppercase tracking-[0.25em] text-stone-500">Leech</p>
118
- <div class="mt-3 flex items-center justify-between">
119
- <p id="summary-leech" class="text-3xl font-bold text-neon">{{ stats.total_leechs or 0 }}</p>
120
- <div class="flex h-11 w-11 items-center justify-center rounded-2xl bg-neon/10 text-neon">
121
  <i class="fa-solid fa-arrow-down"></i>
122
  </div>
123
  </div>
 
 
124
  </article>
125
- <article class="rounded-[26px] border border-white/10 bg-[linear-gradient(180deg,rgba(16,18,28,0.95),rgba(9,11,18,0.92))] px-5 py-4 shadow-halo">
126
- <p class="text-[11px] uppercase tracking-[0.25em] text-stone-500">Seed</p>
127
- <div class="mt-3 flex items-center justify-between">
128
- <p id="summary-seeding" class="text-3xl font-bold text-lime">{{ stats.total_seeds or 0 }}</p>
129
- <div class="flex h-11 w-11 items-center justify-center rounded-2xl bg-lime/10 text-lime">
130
  <i class="fa-solid fa-arrow-up"></i>
131
  </div>
132
  </div>
 
 
133
  </article>
134
- <article class="rounded-[26px] border border-white/10 bg-[linear-gradient(180deg,rgba(16,18,28,0.95),rgba(9,11,18,0.92))] px-5 py-4 shadow-halo">
135
- <p class="text-[11px] uppercase tracking-[0.25em] text-stone-500">Paused</p>
136
- <div class="mt-3 flex items-center justify-between">
137
- <p id="summary-paused" class="text-3xl font-bold text-stone-300">{{ torrents|selectattr("state_label", "equalto", "Paused")|list|length }}</p>
138
- <div class="flex h-11 w-11 items-center justify-center rounded-2xl bg-white/[0.04] text-stone-300">
139
  <i class="fa-solid fa-pause"></i>
140
  </div>
141
  </div>
 
 
142
  </article>
143
  </section>
144
 
@@ -153,12 +153,12 @@
153
  </article>
154
  </section>
155
 
156
- <section class="rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(15,18,28,0.94),rgba(9,11,18,0.92))] px-4 py-5 shadow-halo backdrop-blur-xl sm:px-5">
157
- <div class="text-center">
158
- <h2 class="text-lg font-semibold text-white sm:text-xl">Torrent Status</h2>
159
- <p class="mt-1 text-sm text-stone-500">Pilih status lalu telusuri torrent sebagai card terpisah.</p>
160
- </div>
161
- <div id="filter-tabs" class="mt-4 flex justify-start gap-2 overflow-x-auto pb-1 sm:justify-center [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
162
  <button type="button" class="filter-chip rounded-2xl border border-neon/30 bg-neon/12 px-4 py-2 text-sm font-medium text-neon transition hover:bg-neon/20" data-filter="all" data-active="true">All</button>
163
  <button type="button" class="filter-chip rounded-2xl border border-white/10 bg-white/[0.03] px-4 py-2 text-sm font-medium text-stone-300 transition hover:border-white/20 hover:text-white" data-filter="downloading" data-active="false">Downloading</button>
164
  <button type="button" class="filter-chip rounded-2xl border border-white/10 bg-white/[0.03] px-4 py-2 text-sm font-medium text-stone-300 transition hover:border-white/20 hover:text-white" data-filter="seeding" data-active="false">Seeding</button>
@@ -166,11 +166,6 @@
166
  <button type="button" class="filter-chip rounded-2xl border border-white/10 bg-white/[0.03] px-4 py-2 text-sm font-medium text-stone-300 transition hover:border-white/20 hover:text-white" data-filter="completed" data-active="false">Completed</button>
167
  <button type="button" class="filter-chip rounded-2xl border border-white/10 bg-white/[0.03] px-4 py-2 text-sm font-medium text-stone-300 transition hover:border-white/20 hover:text-white" data-filter="uploading" data-active="false">Uploading</button>
168
  </div>
169
- <div class="mt-4 flex justify-center">
170
- <span id="torrent-count" class="rounded-full border border-white/10 bg-white/[0.04] px-3 py-1 font-mono text-[11px] uppercase tracking-[0.25em] text-stone-400">
171
- {{ stats.torrent_count }} item
172
- </span>
173
- </div>
174
  </section>
175
 
176
  <section>
 
81
  </div>
82
  </div>
83
  </div>
 
 
 
 
84
  </div>
85
  </div>
86
 
 
99
  {% endfor %}
100
  </div>
101
 
102
+ <section class="grid grid-cols-2 gap-3 lg:grid-cols-4">
103
+ <article class="rounded-[26px] border border-white/10 bg-[linear-gradient(180deg,rgba(16,18,28,0.95),rgba(9,11,18,0.92))] px-4 py-4 shadow-halo sm:px-5">
104
+ <div class="flex items-center justify-between">
105
+ <p class="text-[11px] uppercase tracking-[0.25em] text-stone-500">Total</p>
106
+ <div class="flex h-10 w-10 items-center justify-center rounded-2xl bg-white/[0.04] text-stone-300">
 
107
  <i class="fa-solid fa-hard-drive"></i>
108
  </div>
109
  </div>
110
+ <div class="mt-3 h-px bg-gradient-to-r from-transparent via-white/12 to-transparent"></div>
111
+ <p id="summary-total" class="mt-3 text-2xl font-bold text-white sm:text-3xl">{{ stats.torrent_count }}</p>
112
  </article>
113
+ <article class="rounded-[26px] border border-white/10 bg-[linear-gradient(180deg,rgba(16,18,28,0.95),rgba(9,11,18,0.92))] px-4 py-4 shadow-halo sm:px-5">
114
+ <div class="flex items-center justify-between">
115
+ <p class="text-[11px] uppercase tracking-[0.25em] text-stone-500">Leech</p>
116
+ <div class="flex h-10 w-10 items-center justify-center rounded-2xl bg-neon/10 text-neon">
 
117
  <i class="fa-solid fa-arrow-down"></i>
118
  </div>
119
  </div>
120
+ <div class="mt-3 h-px bg-gradient-to-r from-transparent via-neon/30 to-transparent"></div>
121
+ <p id="summary-leech" class="mt-3 text-2xl font-bold text-neon sm:text-3xl">{{ stats.total_leechs or 0 }}</p>
122
  </article>
123
+ <article class="rounded-[26px] border border-white/10 bg-[linear-gradient(180deg,rgba(16,18,28,0.95),rgba(9,11,18,0.92))] px-4 py-4 shadow-halo sm:px-5">
124
+ <div class="flex items-center justify-between">
125
+ <p class="text-[11px] uppercase tracking-[0.25em] text-stone-500">Seed</p>
126
+ <div class="flex h-10 w-10 items-center justify-center rounded-2xl bg-lime/10 text-lime">
 
127
  <i class="fa-solid fa-arrow-up"></i>
128
  </div>
129
  </div>
130
+ <div class="mt-3 h-px bg-gradient-to-r from-transparent via-lime/30 to-transparent"></div>
131
+ <p id="summary-seeding" class="mt-3 text-2xl font-bold text-lime sm:text-3xl">{{ stats.total_seeds or 0 }}</p>
132
  </article>
133
+ <article class="rounded-[26px] border border-white/10 bg-[linear-gradient(180deg,rgba(16,18,28,0.95),rgba(9,11,18,0.92))] px-4 py-4 shadow-halo sm:px-5">
134
+ <div class="flex items-center justify-between">
135
+ <p class="text-[11px] uppercase tracking-[0.25em] text-stone-500">Paused</p>
136
+ <div class="flex h-10 w-10 items-center justify-center rounded-2xl bg-white/[0.04] text-stone-300">
 
137
  <i class="fa-solid fa-pause"></i>
138
  </div>
139
  </div>
140
+ <div class="mt-3 h-px bg-gradient-to-r from-transparent via-white/12 to-transparent"></div>
141
+ <p id="summary-paused" class="mt-3 text-2xl font-bold text-stone-300 sm:text-3xl">{{ torrents|selectattr("state_label", "equalto", "Paused")|list|length }}</p>
142
  </article>
143
  </section>
144
 
 
153
  </article>
154
  </section>
155
 
156
+ <section class="rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(15,18,28,0.94),rgba(9,11,18,0.92))] px-4 py-4 shadow-halo backdrop-blur-xl sm:px-5">
157
+ <div id="filter-tabs" class="flex justify-start gap-2 overflow-x-auto pb-1 sm:justify-center [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
158
+ <button id="open-add-modal" type="button" class="shrink-0 inline-flex items-center gap-2 rounded-2xl border border-neon/30 bg-neon/12 px-4 py-2 text-sm font-semibold text-neon transition hover:bg-neon/20">
159
+ <i class="fa-solid fa-plus"></i>
160
+ Add Torrent
161
+ </button>
162
  <button type="button" class="filter-chip rounded-2xl border border-neon/30 bg-neon/12 px-4 py-2 text-sm font-medium text-neon transition hover:bg-neon/20" data-filter="all" data-active="true">All</button>
163
  <button type="button" class="filter-chip rounded-2xl border border-white/10 bg-white/[0.03] px-4 py-2 text-sm font-medium text-stone-300 transition hover:border-white/20 hover:text-white" data-filter="downloading" data-active="false">Downloading</button>
164
  <button type="button" class="filter-chip rounded-2xl border border-white/10 bg-white/[0.03] px-4 py-2 text-sm font-medium text-stone-300 transition hover:border-white/20 hover:text-white" data-filter="seeding" data-active="false">Seeding</button>
 
166
  <button type="button" class="filter-chip rounded-2xl border border-white/10 bg-white/[0.03] px-4 py-2 text-sm font-medium text-stone-300 transition hover:border-white/20 hover:text-white" data-filter="completed" data-active="false">Completed</button>
167
  <button type="button" class="filter-chip rounded-2xl border border-white/10 bg-white/[0.03] px-4 py-2 text-sm font-medium text-stone-300 transition hover:border-white/20 hover:text-white" data-filter="uploading" data-active="false">Uploading</button>
168
  </div>
 
 
 
 
 
169
  </section>
170
 
171
  <section>