nexus33rd commited on
Commit
9f5cd2f
·
verified ·
1 Parent(s): 1048be8

Upload 25 files

Browse files
Files changed (3) hide show
  1. app.py +13 -9
  2. static/app.js +160 -39
  3. templates/index.html +9 -8
app.py CHANGED
@@ -469,13 +469,17 @@ def serialize_torrent(torrent, state_entry: dict | None = None) -> dict:
469
  progress_label = "Archiving"
470
  else:
471
  progress_label = f"{upload_provider} Upload" if gofile_uploading else "Progress"
472
- gofile_speed = state_entry.get("gofile_speed", "")
473
- if gofile_uploading:
474
- eta_text = human_eta(gofile_eta_seconds)
475
- elif torrent_progress >= 1:
476
- eta_text = "-"
477
- else:
478
- eta_text = human_eta(eta_value)
 
 
 
 
479
  display_speed = gofile_speed if gofile_uploading else format_speed(torrent_dlspeed)
480
  if gofile_uploading and upload_provider == "Archiving":
481
  display_speed = state_entry.get("gofile_status", "") or "Archiving..."
@@ -505,8 +509,8 @@ def serialize_torrent(torrent, state_entry: dict | None = None) -> dict:
505
  "downloaded": format_size(torrent_downloaded),
506
  "uploaded": format_size(torrent_uploaded),
507
  "ratio": f"{float(getattr(torrent, 'ratio', 0) or 0):.2f}",
508
- "dlspeed": format_speed(torrent_dlspeed),
509
- "upspeed": format_speed(torrent_upspeed),
510
  "display_speed": display_speed,
511
  "display_speed_label": display_speed_label,
512
  "display_speed_meta": display_speed_meta,
 
469
  progress_label = "Archiving"
470
  else:
471
  progress_label = f"{upload_provider} Upload" if gofile_uploading else "Progress"
472
+ gofile_speed = state_entry.get("gofile_speed", "")
473
+ badge_download_speed = format_speed(torrent_dlspeed)
474
+ badge_upload_speed = format_speed(torrent_upspeed)
475
+ if gofile_uploading:
476
+ eta_text = human_eta(gofile_eta_seconds)
477
+ badge_download_speed = "0 B/s"
478
+ badge_upload_speed = gofile_speed or "0 B/s"
479
+ elif torrent_progress >= 1:
480
+ eta_text = "-"
481
+ else:
482
+ eta_text = human_eta(eta_value)
483
  display_speed = gofile_speed if gofile_uploading else format_speed(torrent_dlspeed)
484
  if gofile_uploading and upload_provider == "Archiving":
485
  display_speed = state_entry.get("gofile_status", "") or "Archiving..."
 
509
  "downloaded": format_size(torrent_downloaded),
510
  "uploaded": format_size(torrent_uploaded),
511
  "ratio": f"{float(getattr(torrent, 'ratio', 0) or 0):.2f}",
512
+ "dlspeed": badge_download_speed,
513
+ "upspeed": badge_upload_speed,
514
  "display_speed": display_speed,
515
  "display_speed_label": display_speed_label,
516
  "display_speed_meta": display_speed_meta,
static/app.js CHANGED
@@ -2,20 +2,24 @@
2
  const initialDataElement = document.getElementById("initial-dashboard-data");
3
  const initialData = initialDataElement ? JSON.parse(initialDataElement.textContent || "{}") : {};
4
 
5
- const state = {
6
- torrents: Array.isArray(initialData.torrents) ? initialData.torrents : [],
7
- stats: initialData.stats || {},
8
- events: Array.isArray(initialData.events) ? initialData.events : [],
9
- system: initialData.system || {},
10
- activeFilter: "all",
11
- searchTerm: "",
12
- };
 
 
 
13
 
14
  const elements = {
15
  toastContainer: document.getElementById("toast-container"),
16
- eventList: document.getElementById("event-list"),
17
- torrentList: document.getElementById("torrent-list"),
18
- torrentCount: document.getElementById("torrent-count"),
 
19
  versionValue: document.getElementById("version-value"),
20
  connectionStatus: document.getElementById("connection-status"),
21
  savePath: document.getElementById("save-path"),
@@ -384,9 +388,90 @@
384
  return haystack.includes(state.searchTerm);
385
  }
386
 
387
- function filteredTorrents() {
388
- return state.torrents.filter((torrent) => matchesFilter(torrent) && matchesSearch(torrent));
389
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
 
391
  function renderEvents(events) {
392
  if (!elements.eventList) {
@@ -632,23 +717,26 @@
632
  `;
633
  }
634
 
635
- function renderEmptyState() {
636
  const hasSearch = !!state.searchTerm || state.activeFilter !== "all";
637
  const title = hasSearch ? "Tidak ada hasil yang cocok" : "Belum ada torrent aktif";
638
  const subtitle = hasSearch
639
  ? "Coba ubah keyword pencarian atau filter status yang sedang aktif."
640
  : "Gunakan tombol Add untuk menambahkan magnet link atau file torrent, lalu queue akan muncul di sini.";
641
 
642
- elements.torrentList.innerHTML = `
643
- <div class="rounded-[26px] border border-dashed border-white/10 bg-black/20 px-6 py-14 text-center">
644
  <div class="mx-auto flex h-16 w-16 items-center justify-center rounded-3xl bg-white/[0.04] text-2xl text-neon">
645
  <i class="fa-solid fa-wave-square"></i>
646
  </div>
647
  <h3 class="font-display mt-5 text-lg font-semibold text-white">${title}</h3>
648
  <p class="mx-auto mt-2 max-w-md text-sm text-stone-500">${subtitle}</p>
649
- </div>
650
- `;
651
- }
 
 
 
652
 
653
  function updateSummary(stats, torrents) {
654
  const counts = getTorrentCounts(torrents);
@@ -708,14 +796,18 @@
708
  });
709
  }
710
 
711
- function renderTorrents() {
712
- const torrents = filteredTorrents();
713
- if (!torrents.length) {
714
- renderEmptyState();
715
- return;
716
- }
717
- elements.torrentList.innerHTML = torrents.map(renderTorrent).join("");
718
- }
 
 
 
 
719
 
720
  function renderDashboard() {
721
  renderEvents(state.events);
@@ -981,22 +1073,51 @@
981
  }
982
  }
983
 
984
- elements.searchInput?.addEventListener("input", (event) => {
985
- state.searchTerm = String(event.target.value || "").trim().toLowerCase();
986
- updateSummary(state.stats, state.torrents);
987
- renderTorrents();
988
- });
 
989
 
990
  elements.filterTabs?.addEventListener("click", (event) => {
991
  const button = event.target.closest("[data-filter]");
992
  if (!button) {
993
  return;
994
- }
995
- state.activeFilter = button.dataset.filter || "all";
996
- renderFilterTabs();
997
- updateSummary(state.stats, state.torrents);
998
- renderTorrents();
999
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1000
 
1001
  elements.torrentList?.addEventListener("click", async (event) => {
1002
  const button = event.target.closest("[data-action]");
 
2
  const initialDataElement = document.getElementById("initial-dashboard-data");
3
  const initialData = initialDataElement ? JSON.parse(initialDataElement.textContent || "{}") : {};
4
 
5
+ const state = {
6
+ torrents: Array.isArray(initialData.torrents) ? initialData.torrents : [],
7
+ stats: initialData.stats || {},
8
+ events: Array.isArray(initialData.events) ? initialData.events : [],
9
+ system: initialData.system || {},
10
+ activeFilter: "all",
11
+ searchTerm: "",
12
+ currentPage: 1,
13
+ };
14
+
15
+ const TORRENTS_PER_PAGE = 5;
16
 
17
  const elements = {
18
  toastContainer: document.getElementById("toast-container"),
19
+ eventList: document.getElementById("event-list"),
20
+ torrentList: document.getElementById("torrent-list"),
21
+ torrentPagination: document.getElementById("torrent-pagination"),
22
+ torrentCount: document.getElementById("torrent-count"),
23
  versionValue: document.getElementById("version-value"),
24
  connectionStatus: document.getElementById("connection-status"),
25
  savePath: document.getElementById("save-path"),
 
388
  return haystack.includes(state.searchTerm);
389
  }
390
 
391
+ function filteredTorrents() {
392
+ return state.torrents.filter((torrent) => matchesFilter(torrent) && matchesSearch(torrent));
393
+ }
394
+
395
+ function getTotalPages(totalItems) {
396
+ return Math.max(1, Math.ceil(totalItems / TORRENTS_PER_PAGE));
397
+ }
398
+
399
+ function clampCurrentPage(totalItems) {
400
+ const totalPages = getTotalPages(totalItems);
401
+ state.currentPage = Math.min(Math.max(state.currentPage, 1), totalPages);
402
+ return totalPages;
403
+ }
404
+
405
+ function getVisiblePageNumbers(totalPages) {
406
+ if (totalPages <= 5) {
407
+ return Array.from({ length: totalPages }, (_, index) => index + 1);
408
+ }
409
+
410
+ if (state.currentPage <= 3) {
411
+ return [1, 2, 3, 4, totalPages];
412
+ }
413
+
414
+ if (state.currentPage >= totalPages - 2) {
415
+ return [1, totalPages - 3, totalPages - 2, totalPages - 1, totalPages];
416
+ }
417
+
418
+ return [1, state.currentPage - 1, state.currentPage, state.currentPage + 1, totalPages];
419
+ }
420
+
421
+ function renderPagination(totalItems) {
422
+ if (!elements.torrentPagination) {
423
+ return;
424
+ }
425
+
426
+ const totalPages = clampCurrentPage(totalItems);
427
+ if (totalItems <= TORRENTS_PER_PAGE) {
428
+ elements.torrentPagination.innerHTML = "";
429
+ return;
430
+ }
431
+
432
+ const visiblePages = getVisiblePageNumbers(totalPages);
433
+ const seen = new Set();
434
+ const pageButtons = visiblePages.filter((page) => {
435
+ if (seen.has(page)) {
436
+ return false;
437
+ }
438
+ seen.add(page);
439
+ return true;
440
+ }).map((page) => {
441
+ const active = page === state.currentPage;
442
+ const className = active
443
+ ? "border-neon/30 bg-neon/12 text-neon"
444
+ : "border-white/10 bg-white/[0.03] text-stone-300 hover:border-white/20 hover:text-white";
445
+ return `
446
+ <button type="button" data-page="${page}" class="font-display min-w-10 rounded-2xl border px-3 py-2 text-sm font-semibold transition ${className}">
447
+ ${page}
448
+ </button>
449
+ `;
450
+ }).join("");
451
+
452
+ const firstDisabledClass = state.currentPage === 1 ? "opacity-40 cursor-not-allowed" : "";
453
+ const lastDisabledClass = state.currentPage === totalPages ? "opacity-40 cursor-not-allowed" : "";
454
+ const firstDisabledAttr = state.currentPage === 1 ? "disabled" : "";
455
+ const lastDisabledAttr = state.currentPage === totalPages ? "disabled" : "";
456
+
457
+ elements.torrentPagination.innerHTML = `
458
+ <div class="flex flex-wrap items-center justify-center gap-2">
459
+ <button type="button" data-page-nav="first" ${firstDisabledAttr} class="font-display rounded-2xl border border-white/10 bg-white/[0.03] px-3 py-2 text-sm font-semibold text-stone-300 transition hover:border-white/20 hover:text-white ${firstDisabledClass}">
460
+ &laquo;
461
+ </button>
462
+ <button type="button" data-page-nav="prev" ${firstDisabledAttr} class="font-display rounded-2xl border border-white/10 bg-white/[0.03] px-3 py-2 text-sm font-semibold text-stone-300 transition hover:border-white/20 hover:text-white ${firstDisabledClass}">
463
+ Prev
464
+ </button>
465
+ ${pageButtons}
466
+ <button type="button" data-page-nav="next" ${lastDisabledAttr} class="font-display rounded-2xl border border-white/10 bg-white/[0.03] px-3 py-2 text-sm font-semibold text-stone-300 transition hover:border-white/20 hover:text-white ${lastDisabledClass}">
467
+ Next
468
+ </button>
469
+ <button type="button" data-page-nav="last" ${lastDisabledAttr} class="font-display rounded-2xl border border-white/10 bg-white/[0.03] px-3 py-2 text-sm font-semibold text-stone-300 transition hover:border-white/20 hover:text-white ${lastDisabledClass}">
470
+ &raquo;
471
+ </button>
472
+ </div>
473
+ `;
474
+ }
475
 
476
  function renderEvents(events) {
477
  if (!elements.eventList) {
 
717
  `;
718
  }
719
 
720
+ function renderEmptyState() {
721
  const hasSearch = !!state.searchTerm || state.activeFilter !== "all";
722
  const title = hasSearch ? "Tidak ada hasil yang cocok" : "Belum ada torrent aktif";
723
  const subtitle = hasSearch
724
  ? "Coba ubah keyword pencarian atau filter status yang sedang aktif."
725
  : "Gunakan tombol Add untuk menambahkan magnet link atau file torrent, lalu queue akan muncul di sini.";
726
 
727
+ elements.torrentList.innerHTML = `
728
+ <div class="rounded-[26px] border border-dashed border-white/10 bg-black/20 px-6 py-14 text-center">
729
  <div class="mx-auto flex h-16 w-16 items-center justify-center rounded-3xl bg-white/[0.04] text-2xl text-neon">
730
  <i class="fa-solid fa-wave-square"></i>
731
  </div>
732
  <h3 class="font-display mt-5 text-lg font-semibold text-white">${title}</h3>
733
  <p class="mx-auto mt-2 max-w-md text-sm text-stone-500">${subtitle}</p>
734
+ </div>
735
+ `;
736
+ if (elements.torrentPagination) {
737
+ elements.torrentPagination.innerHTML = "";
738
+ }
739
+ }
740
 
741
  function updateSummary(stats, torrents) {
742
  const counts = getTorrentCounts(torrents);
 
796
  });
797
  }
798
 
799
+ function renderTorrents() {
800
+ const torrents = filteredTorrents();
801
+ if (!torrents.length) {
802
+ renderEmptyState();
803
+ return;
804
+ }
805
+ const totalPages = clampCurrentPage(torrents.length);
806
+ const startIndex = (state.currentPage - 1) * TORRENTS_PER_PAGE;
807
+ const pageItems = torrents.slice(startIndex, startIndex + TORRENTS_PER_PAGE);
808
+ elements.torrentList.innerHTML = pageItems.map(renderTorrent).join("");
809
+ renderPagination(torrents.length, totalPages);
810
+ }
811
 
812
  function renderDashboard() {
813
  renderEvents(state.events);
 
1073
  }
1074
  }
1075
 
1076
+ elements.searchInput?.addEventListener("input", (event) => {
1077
+ state.searchTerm = String(event.target.value || "").trim().toLowerCase();
1078
+ state.currentPage = 1;
1079
+ updateSummary(state.stats, state.torrents);
1080
+ renderTorrents();
1081
+ });
1082
 
1083
  elements.filterTabs?.addEventListener("click", (event) => {
1084
  const button = event.target.closest("[data-filter]");
1085
  if (!button) {
1086
  return;
1087
+ }
1088
+ state.activeFilter = button.dataset.filter || "all";
1089
+ state.currentPage = 1;
1090
+ renderFilterTabs();
1091
+ updateSummary(state.stats, state.torrents);
1092
+ renderTorrents();
1093
+ });
1094
+
1095
+ elements.torrentPagination?.addEventListener("click", (event) => {
1096
+ const pageButton = event.target.closest("[data-page]");
1097
+ if (pageButton) {
1098
+ state.currentPage = Number(pageButton.dataset.page || 1);
1099
+ renderTorrents();
1100
+ return;
1101
+ }
1102
+
1103
+ const navButton = event.target.closest("[data-page-nav]");
1104
+ if (!navButton || navButton.disabled) {
1105
+ return;
1106
+ }
1107
+
1108
+ const totalPages = getTotalPages(filteredTorrents().length);
1109
+ const action = navButton.dataset.pageNav;
1110
+ if (action === "first") {
1111
+ state.currentPage = 1;
1112
+ } else if (action === "prev") {
1113
+ state.currentPage = Math.max(1, state.currentPage - 1);
1114
+ } else if (action === "next") {
1115
+ state.currentPage = Math.min(totalPages, state.currentPage + 1);
1116
+ } else if (action === "last") {
1117
+ state.currentPage = totalPages;
1118
+ }
1119
+ renderTorrents();
1120
+ });
1121
 
1122
  elements.torrentList?.addEventListener("click", async (event) => {
1123
  const button = event.target.closest("[data-action]");
templates/index.html CHANGED
@@ -154,19 +154,20 @@
154
  <input id="search-input" type="search" placeholder="Search torrents..." class="w-full rounded-2xl border border-white/10 bg-[#0c1119]/95 py-3 pl-11 pr-4 text-sm text-white outline-none transition placeholder:text-stone-500 focus:border-neon/40 focus:bg-[#0a0f17]" />
155
  </label>
156
 
157
- <section>
158
- <div id="torrent-list" class="space-y-4">
159
- {% if not torrents %}
160
- <div class="rounded-[26px] border border-dashed border-white/10 bg-black/20 px-6 py-14 text-center">
161
  <div class="mx-auto flex h-16 w-16 items-center justify-center rounded-3xl bg-white/[0.04] text-2xl text-neon">
162
  <i class="fa-solid fa-wave-square"></i>
163
  </div>
164
  <h3 class="font-display mt-5 text-lg font-semibold text-white">Belum ada torrent aktif</h3>
165
  <p class="mx-auto mt-2 max-w-md text-sm text-stone-500">Gunakan tombol Add untuk menambahkan magnet link atau file torrent, lalu queue akan muncul di sini.</p>
166
- </div>
167
- {% endif %}
168
- </div>
169
- </section>
 
170
 
171
  <section class="grid gap-5 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]">
172
  <section class="rounded-[30px] border border-white/10 bg-[#0c1119]/95 p-5 shadow-halo backdrop-blur-xl">
 
154
  <input id="search-input" type="search" placeholder="Search torrents..." class="w-full rounded-2xl border border-white/10 bg-[#0c1119]/95 py-3 pl-11 pr-4 text-sm text-white outline-none transition placeholder:text-stone-500 focus:border-neon/40 focus:bg-[#0a0f17]" />
155
  </label>
156
 
157
+ <section>
158
+ <div id="torrent-list" class="space-y-4">
159
+ {% if not torrents %}
160
+ <div class="rounded-[26px] border border-dashed border-white/10 bg-black/20 px-6 py-14 text-center">
161
  <div class="mx-auto flex h-16 w-16 items-center justify-center rounded-3xl bg-white/[0.04] text-2xl text-neon">
162
  <i class="fa-solid fa-wave-square"></i>
163
  </div>
164
  <h3 class="font-display mt-5 text-lg font-semibold text-white">Belum ada torrent aktif</h3>
165
  <p class="mx-auto mt-2 max-w-md text-sm text-stone-500">Gunakan tombol Add untuk menambahkan magnet link atau file torrent, lalu queue akan muncul di sini.</p>
166
+ </div>
167
+ {% endif %}
168
+ </div>
169
+ <div id="torrent-pagination" class="mt-5"></div>
170
+ </section>
171
 
172
  <section class="grid gap-5 lg:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]">
173
  <section class="rounded-[30px] border border-white/10 bg-[#0c1119]/95 p-5 shadow-halo backdrop-blur-xl">