Spaces:
Paused
Paused
Upload 20 files
Browse files- static/app.js +132 -62
static/app.js
CHANGED
|
@@ -53,10 +53,11 @@
|
|
| 53 |
speedtestButton: document.getElementById("speedtest-button"),
|
| 54 |
};
|
| 55 |
|
| 56 |
-
let pendingDelete = null;
|
| 57 |
-
let pendingFolderUpload = null;
|
| 58 |
-
let selectedFolderUploadMode = "zip";
|
| 59 |
-
const dismissedStatusMessages = new Set();
|
|
|
|
| 60 |
|
| 61 |
function escapeHtml(value) {
|
| 62 |
return String(value ?? "").replace(/[&<>"']/g, (char) => ({
|
|
@@ -175,7 +176,7 @@
|
|
| 175 |
return escapeHtml(value || "-");
|
| 176 |
}
|
| 177 |
|
| 178 |
-
function metricBadge({ icon, label, value, tone = "default", span = "normal" }) {
|
| 179 |
const toneConfig = {
|
| 180 |
default: {
|
| 181 |
className: "text-stone-200",
|
|
@@ -187,16 +188,6 @@
|
|
| 187 |
labelClassName: "text-stone-400",
|
| 188 |
style: "background-color: rgba(10, 14, 22, 0.62); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);",
|
| 189 |
},
|
| 190 |
-
down: {
|
| 191 |
-
className: "text-neon",
|
| 192 |
-
labelClassName: "text-neon/80",
|
| 193 |
-
style: "background-color: rgba(32, 230, 192, 0.18); box-shadow: inset 0 0 0 1px rgba(32, 230, 192, 0.24);",
|
| 194 |
-
},
|
| 195 |
-
up: {
|
| 196 |
-
className: "text-lime",
|
| 197 |
-
labelClassName: "text-lime/80",
|
| 198 |
-
style: "background-color: rgba(156, 247, 166, 0.18); box-shadow: inset 0 0 0 1px rgba(156, 247, 166, 0.24);",
|
| 199 |
-
},
|
| 200 |
};
|
| 201 |
const config = toneConfig[tone] || toneConfig.default;
|
| 202 |
const spanClass = span === "full" ? "col-span-2" : "";
|
|
@@ -204,15 +195,38 @@
|
|
| 204 |
<div class="min-w-0 rounded-full px-3 py-2.5 text-xs ${config.className} ${spanClass}" style="${config.style}">
|
| 205 |
<div class="flex items-center justify-between gap-2">
|
| 206 |
<span class="inline-flex min-w-0 items-center gap-2">
|
| 207 |
-
<i class="fa-solid ${icon} shrink-0 text-[11px]"></i>
|
| 208 |
<span class="truncate ${config.labelClassName || "text-stone-400"}">${escapeHtml(label)}</span>
|
| 209 |
</span>
|
| 210 |
-
<span class="min-w-0 shrink-0 truncate text-right font-mono font-medium">${escapeHtml(value)}</span>
|
| 211 |
</div>
|
| 212 |
</div>
|
| 213 |
`;
|
| 214 |
}
|
| 215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
function applyOptimisticTorrentAction(action, hash) {
|
| 217 |
const torrent = (state.torrents || []).find((item) => item.hash === hash);
|
| 218 |
if (!torrent) {
|
|
@@ -228,6 +242,7 @@
|
|
| 228 |
torrent.can_resume = true;
|
| 229 |
torrent.dlspeed = "0 B/s";
|
| 230 |
torrent.upspeed = "0 B/s";
|
|
|
|
| 231 |
if (torrent.display_speed_label === "Seed Upload") {
|
| 232 |
torrent.display_speed = "0 B/s";
|
| 233 |
}
|
|
@@ -238,11 +253,52 @@
|
|
| 238 |
torrent.state_label = isComplete ? "Seeding" : "Downloading";
|
| 239 |
torrent.can_pause = !torrent.gofile_uploading;
|
| 240 |
torrent.can_resume = false;
|
|
|
|
| 241 |
}
|
| 242 |
|
| 243 |
updateSummary(state.stats, state.torrents);
|
| 244 |
renderTorrents();
|
| 245 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
function getTorrentCounts(torrents) {
|
| 248 |
const counts = {
|
|
@@ -378,26 +434,33 @@
|
|
| 378 |
setTimeout(closeToast, 3200);
|
| 379 |
}
|
| 380 |
|
| 381 |
-
function actionButtons(torrent) {
|
| 382 |
-
const buttons = [];
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
<
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
</button>
|
| 402 |
`);
|
| 403 |
|
|
@@ -474,9 +537,9 @@
|
|
| 474 |
const endpointMeta = torrent.gofile_endpoint
|
| 475 |
? `<span class="rounded-full border border-white/10 bg-white/[0.04] px-2 py-1 font-mono text-[10px] uppercase tracking-[0.2em] text-stone-400">${escapeHtml(torrent.gofile_endpoint)}</span>`
|
| 476 |
: "";
|
| 477 |
-
const activeSpeed = torrent.display_speed && torrent.display_speed !== "-"
|
| 478 |
-
? `<span class="text-sm font-semibold ${tone.text}">${escapeHtml(torrent.display_speed)}</span>`
|
| 479 |
-
: "";
|
| 480 |
const statusIconName = torrent.gofile_uploading
|
| 481 |
? "fa-cloud-arrow-up"
|
| 482 |
: isSeeding
|
|
@@ -495,8 +558,8 @@
|
|
| 495 |
metricBadge({ icon: "fa-box-archive", label: "Size", value: torrent.total_size || "-", tone: "muted" }),
|
| 496 |
metricBadge({ icon: "fa-download", label: "Downloaded", value: torrent.downloaded || "-", tone: "muted" }),
|
| 497 |
metricBadge({ icon: "fa-upload", label: "Uploaded", value: torrent.uploaded || "-", tone: "muted" }),
|
| 498 |
-
metricBadge({ icon: "fa-arrow-down", label: "Down", value: torrent.dlspeed || "-", tone: "
|
| 499 |
-
metricBadge({ icon: "fa-arrow-up", label: "Up", value: torrent.upspeed || "-", tone: "
|
| 500 |
metricBadge({ icon: "fa-chart-simple", label: "Ratio", value: torrent.ratio || "-", tone: "muted" }),
|
| 501 |
].join("");
|
| 502 |
const peerBadges = [
|
|
@@ -515,11 +578,11 @@
|
|
| 515 |
<div class="min-w-0">
|
| 516 |
<h3 class="break-words text-[15px] font-semibold leading-6 text-white">${escapeHtml(torrent.name)}</h3>
|
| 517 |
<div class="mt-2 flex flex-wrap items-center gap-x-3 gap-y-2">
|
| 518 |
-
<span class="inline-flex min-h-[2.25rem] items-center justify-center gap-2 rounded-full px-3 py-1.5 text-xs font-medium ${tone.pillClass}" style="
|
| 519 |
<span class="h-2 w-2 shrink-0 rounded-full ${tone.dotClass || ""}" style="${tone.dotStyle || ""}"></span>
|
| 520 |
<span class="leading-none">${escapeHtml(tone.label)}</span>
|
| 521 |
</span>
|
| 522 |
-
${activeSpeed ? `<span class="inline-flex min-h-[2.25rem] items-center justify-center rounded-full px-3 py-1.5 text-xs ${tone.pillClass}" style="
|
| 523 |
${endpointMeta}
|
| 524 |
</div>
|
| 525 |
</div>
|
|
@@ -752,11 +815,12 @@
|
|
| 752 |
});
|
| 753 |
if (!response.ok) {
|
| 754 |
throw new Error("Request failed");
|
| 755 |
-
}
|
| 756 |
-
const data = await response.json();
|
| 757 |
-
state.torrents = Array.isArray(data.torrents) ? data.torrents : [];
|
| 758 |
-
state.
|
| 759 |
-
state.
|
|
|
|
| 760 |
updateConnection(true, state.stats.version || "-");
|
| 761 |
renderEvents(state.events);
|
| 762 |
updateSummary(state.stats, state.torrents);
|
|
@@ -793,7 +857,7 @@
|
|
| 793 |
return false;
|
| 794 |
}
|
| 795 |
|
| 796 |
-
async function triggerTorrentAction(action, hash, mode = null) {
|
| 797 |
const method = action === "delete" ? "DELETE" : "POST";
|
| 798 |
const query = mode ? `?mode=${encodeURIComponent(mode)}` : "";
|
| 799 |
const target = action === "delete"
|
|
@@ -806,15 +870,24 @@
|
|
| 806 |
? `/api/torrents/${hash}/cancel-gofile`
|
| 807 |
: `/api/torrents/${hash}/${action}`;
|
| 808 |
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
}
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 818 |
|
| 819 |
if (action === "delete") {
|
| 820 |
closeDeleteModal();
|
|
@@ -829,9 +902,6 @@
|
|
| 829 |
showToast(payload.message || "Aksi berhasil diproses.");
|
| 830 |
}
|
| 831 |
|
| 832 |
-
if (action === "pause" || action === "resume") {
|
| 833 |
-
applyOptimisticTorrentAction(action, hash);
|
| 834 |
-
}
|
| 835 |
await refreshTorrents();
|
| 836 |
}
|
| 837 |
|
|
|
|
| 53 |
speedtestButton: document.getElementById("speedtest-button"),
|
| 54 |
};
|
| 55 |
|
| 56 |
+
let pendingDelete = null;
|
| 57 |
+
let pendingFolderUpload = null;
|
| 58 |
+
let selectedFolderUploadMode = "zip";
|
| 59 |
+
const dismissedStatusMessages = new Set();
|
| 60 |
+
const pendingTorrentActions = new Map();
|
| 61 |
|
| 62 |
function escapeHtml(value) {
|
| 63 |
return String(value ?? "").replace(/[&<>"']/g, (char) => ({
|
|
|
|
| 176 |
return escapeHtml(value || "-");
|
| 177 |
}
|
| 178 |
|
| 179 |
+
function metricBadge({ icon, label, value, tone = "default", span = "normal", accentClass = "" }) {
|
| 180 |
const toneConfig = {
|
| 181 |
default: {
|
| 182 |
className: "text-stone-200",
|
|
|
|
| 188 |
labelClassName: "text-stone-400",
|
| 189 |
style: "background-color: rgba(10, 14, 22, 0.62); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);",
|
| 190 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
};
|
| 192 |
const config = toneConfig[tone] || toneConfig.default;
|
| 193 |
const spanClass = span === "full" ? "col-span-2" : "";
|
|
|
|
| 195 |
<div class="min-w-0 rounded-full px-3 py-2.5 text-xs ${config.className} ${spanClass}" style="${config.style}">
|
| 196 |
<div class="flex items-center justify-between gap-2">
|
| 197 |
<span class="inline-flex min-w-0 items-center gap-2">
|
| 198 |
+
<i class="fa-solid ${icon} shrink-0 text-[11px] ${accentClass}"></i>
|
| 199 |
<span class="truncate ${config.labelClassName || "text-stone-400"}">${escapeHtml(label)}</span>
|
| 200 |
</span>
|
| 201 |
+
<span class="min-w-0 shrink-0 truncate text-right font-mono font-medium ${accentClass}">${escapeHtml(value)}</span>
|
| 202 |
</div>
|
| 203 |
</div>
|
| 204 |
`;
|
| 205 |
}
|
| 206 |
|
| 207 |
+
function getPendingTorrentAction(hash) {
|
| 208 |
+
const pending = pendingTorrentActions.get(hash);
|
| 209 |
+
if (!pending) {
|
| 210 |
+
return null;
|
| 211 |
+
}
|
| 212 |
+
if (Date.now() > pending.expiresAt) {
|
| 213 |
+
pendingTorrentActions.delete(hash);
|
| 214 |
+
return null;
|
| 215 |
+
}
|
| 216 |
+
return pending;
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
function setPendingTorrentAction(hash, action, ttlMs = 4000) {
|
| 220 |
+
pendingTorrentActions.set(hash, {
|
| 221 |
+
action,
|
| 222 |
+
expiresAt: Date.now() + ttlMs,
|
| 223 |
+
});
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
function clearPendingTorrentAction(hash) {
|
| 227 |
+
pendingTorrentActions.delete(hash);
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
function applyOptimisticTorrentAction(action, hash) {
|
| 231 |
const torrent = (state.torrents || []).find((item) => item.hash === hash);
|
| 232 |
if (!torrent) {
|
|
|
|
| 242 |
torrent.can_resume = true;
|
| 243 |
torrent.dlspeed = "0 B/s";
|
| 244 |
torrent.upspeed = "0 B/s";
|
| 245 |
+
torrent.status_message = "";
|
| 246 |
if (torrent.display_speed_label === "Seed Upload") {
|
| 247 |
torrent.display_speed = "0 B/s";
|
| 248 |
}
|
|
|
|
| 253 |
torrent.state_label = isComplete ? "Seeding" : "Downloading";
|
| 254 |
torrent.can_pause = !torrent.gofile_uploading;
|
| 255 |
torrent.can_resume = false;
|
| 256 |
+
torrent.status_message = "";
|
| 257 |
}
|
| 258 |
|
| 259 |
updateSummary(state.stats, state.torrents);
|
| 260 |
renderTorrents();
|
| 261 |
}
|
| 262 |
+
|
| 263 |
+
function reconcilePendingTorrentState(nextTorrents) {
|
| 264 |
+
nextTorrents.forEach((torrent) => {
|
| 265 |
+
const pending = getPendingTorrentAction(torrent.hash);
|
| 266 |
+
if (!pending) {
|
| 267 |
+
return;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
const rawState = String(torrent.state || "");
|
| 271 |
+
if (pending.action === "pause") {
|
| 272 |
+
const serverPaused = ["pausedDL", "pausedUP"].includes(rawState);
|
| 273 |
+
if (serverPaused) {
|
| 274 |
+
clearPendingTorrentAction(torrent.hash);
|
| 275 |
+
return;
|
| 276 |
+
}
|
| 277 |
+
torrent.state = Number(torrent.progress || 0) >= 100 ? "pausedUP" : "pausedDL";
|
| 278 |
+
torrent.state_label = "Paused";
|
| 279 |
+
torrent.can_pause = false;
|
| 280 |
+
torrent.can_resume = true;
|
| 281 |
+
torrent.dlspeed = "0 B/s";
|
| 282 |
+
torrent.upspeed = "0 B/s";
|
| 283 |
+
if (torrent.display_speed_label === "Seed Upload") {
|
| 284 |
+
torrent.display_speed = "0 B/s";
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
if (pending.action === "resume") {
|
| 289 |
+
const serverResumed = !["pausedDL", "pausedUP"].includes(rawState);
|
| 290 |
+
if (serverResumed) {
|
| 291 |
+
clearPendingTorrentAction(torrent.hash);
|
| 292 |
+
return;
|
| 293 |
+
}
|
| 294 |
+
const isComplete = Number(torrent.progress || 0) >= 100;
|
| 295 |
+
torrent.state = isComplete ? "uploading" : "downloading";
|
| 296 |
+
torrent.state_label = isComplete ? "Seeding" : "Downloading";
|
| 297 |
+
torrent.can_pause = !torrent.gofile_uploading;
|
| 298 |
+
torrent.can_resume = false;
|
| 299 |
+
}
|
| 300 |
+
});
|
| 301 |
+
}
|
| 302 |
|
| 303 |
function getTorrentCounts(torrents) {
|
| 304 |
const counts = {
|
|
|
|
| 434 |
setTimeout(closeToast, 3200);
|
| 435 |
}
|
| 436 |
|
| 437 |
+
function actionButtons(torrent) {
|
| 438 |
+
const buttons = [];
|
| 439 |
+
const pending = getPendingTorrentAction(torrent.hash);
|
| 440 |
+
|
| 441 |
+
if (pending && (pending.action === "pause" || pending.action === "resume")) {
|
| 442 |
+
const isPause = pending.action === "pause";
|
| 443 |
+
buttons.push(`
|
| 444 |
+
<button type="button" disabled class="font-display rounded-xl border border-white/10 bg-white/[0.04] px-3 py-2 text-xs font-medium text-white/75 opacity-60 transition">
|
| 445 |
+
<i class="fa-solid fa-spinner mr-2 text-[11px] animate-spin"></i>${isPause ? "Pausing..." : "Resuming..."}
|
| 446 |
+
</button>
|
| 447 |
+
`);
|
| 448 |
+
} else if (torrent.can_pause) {
|
| 449 |
+
buttons.push(`
|
| 450 |
+
<button type="button" data-action="pause" data-hash="${escapeHtml(torrent.hash)}" class="font-display rounded-xl border border-white/10 bg-white/[0.04] px-3 py-2 text-xs font-medium text-white transition hover:bg-white/[0.08]">
|
| 451 |
+
<i class="fa-solid fa-pause mr-2 text-[11px]"></i>Pause
|
| 452 |
+
</button>
|
| 453 |
+
`);
|
| 454 |
+
} else if (torrent.can_resume) {
|
| 455 |
+
buttons.push(`
|
| 456 |
+
<button type="button" data-action="resume" data-hash="${escapeHtml(torrent.hash)}" class="font-display rounded-xl border border-lime/20 bg-lime/10 px-3 py-2 text-xs font-medium text-lime transition hover:bg-lime/15">
|
| 457 |
+
<i class="fa-solid fa-play mr-2 text-[11px]"></i>Resume
|
| 458 |
+
</button>
|
| 459 |
+
`);
|
| 460 |
+
}
|
| 461 |
+
buttons.push(`
|
| 462 |
+
<button type="button" data-action="delete" data-hash="${escapeHtml(torrent.hash)}" data-name="${escapeHtml(torrent.name)}" class="font-display rounded-xl border border-rose/20 bg-rose/10 px-3 py-2 text-xs font-medium text-rose-100 transition hover:bg-rose/15">
|
| 463 |
+
<i class="fa-solid fa-trash mr-2 text-[11px]"></i>Delete
|
| 464 |
</button>
|
| 465 |
`);
|
| 466 |
|
|
|
|
| 537 |
const endpointMeta = torrent.gofile_endpoint
|
| 538 |
? `<span class="rounded-full border border-white/10 bg-white/[0.04] px-2 py-1 font-mono text-[10px] uppercase tracking-[0.2em] text-stone-400">${escapeHtml(torrent.gofile_endpoint)}</span>`
|
| 539 |
: "";
|
| 540 |
+
const activeSpeed = torrent.display_speed && torrent.display_speed !== "-"
|
| 541 |
+
? `<span class="text-sm font-semibold ${tone.text}">${escapeHtml(torrent.display_speed)}</span>`
|
| 542 |
+
: "";
|
| 543 |
const statusIconName = torrent.gofile_uploading
|
| 544 |
? "fa-cloud-arrow-up"
|
| 545 |
: isSeeding
|
|
|
|
| 558 |
metricBadge({ icon: "fa-box-archive", label: "Size", value: torrent.total_size || "-", tone: "muted" }),
|
| 559 |
metricBadge({ icon: "fa-download", label: "Downloaded", value: torrent.downloaded || "-", tone: "muted" }),
|
| 560 |
metricBadge({ icon: "fa-upload", label: "Uploaded", value: torrent.uploaded || "-", tone: "muted" }),
|
| 561 |
+
metricBadge({ icon: "fa-arrow-down", label: "Down", value: torrent.dlspeed || "-", tone: "muted", accentClass: "text-neon" }),
|
| 562 |
+
metricBadge({ icon: "fa-arrow-up", label: "Up", value: torrent.upspeed || "-", tone: "muted", accentClass: "text-lime" }),
|
| 563 |
metricBadge({ icon: "fa-chart-simple", label: "Ratio", value: torrent.ratio || "-", tone: "muted" }),
|
| 564 |
].join("");
|
| 565 |
const peerBadges = [
|
|
|
|
| 578 |
<div class="min-w-0">
|
| 579 |
<h3 class="break-words text-[15px] font-semibold leading-6 text-white">${escapeHtml(torrent.name)}</h3>
|
| 580 |
<div class="mt-2 flex flex-wrap items-center gap-x-3 gap-y-2">
|
| 581 |
+
<span class="inline-flex min-h-[2.25rem] items-center justify-center gap-2 rounded-full px-3 py-1.5 text-xs font-medium ${tone.pillClass}" style="background-color: rgba(10, 14, 22, 0.62); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);">
|
| 582 |
<span class="h-2 w-2 shrink-0 rounded-full ${tone.dotClass || ""}" style="${tone.dotStyle || ""}"></span>
|
| 583 |
<span class="leading-none">${escapeHtml(tone.label)}</span>
|
| 584 |
</span>
|
| 585 |
+
${activeSpeed ? `<span class="inline-flex min-h-[2.25rem] items-center justify-center rounded-full px-3 py-1.5 text-xs ${tone.pillClass}" style="background-color: rgba(10, 14, 22, 0.62); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);">${activeSpeed}</span>` : ""}
|
| 586 |
${endpointMeta}
|
| 587 |
</div>
|
| 588 |
</div>
|
|
|
|
| 815 |
});
|
| 816 |
if (!response.ok) {
|
| 817 |
throw new Error("Request failed");
|
| 818 |
+
}
|
| 819 |
+
const data = await response.json();
|
| 820 |
+
state.torrents = Array.isArray(data.torrents) ? data.torrents : [];
|
| 821 |
+
reconcilePendingTorrentState(state.torrents);
|
| 822 |
+
state.stats = data.stats || {};
|
| 823 |
+
state.events = Array.isArray(data.events) ? data.events : [];
|
| 824 |
updateConnection(true, state.stats.version || "-");
|
| 825 |
renderEvents(state.events);
|
| 826 |
updateSummary(state.stats, state.torrents);
|
|
|
|
| 857 |
return false;
|
| 858 |
}
|
| 859 |
|
| 860 |
+
async function triggerTorrentAction(action, hash, mode = null) {
|
| 861 |
const method = action === "delete" ? "DELETE" : "POST";
|
| 862 |
const query = mode ? `?mode=${encodeURIComponent(mode)}` : "";
|
| 863 |
const target = action === "delete"
|
|
|
|
| 870 |
? `/api/torrents/${hash}/cancel-gofile`
|
| 871 |
: `/api/torrents/${hash}/${action}`;
|
| 872 |
|
| 873 |
+
if (action === "pause" || action === "resume") {
|
| 874 |
+
setPendingTorrentAction(hash, action);
|
| 875 |
+
applyOptimisticTorrentAction(action, hash);
|
| 876 |
+
}
|
| 877 |
+
|
| 878 |
+
const response = await fetch(target, {
|
| 879 |
+
method,
|
| 880 |
+
headers: { Accept: "application/json" },
|
| 881 |
+
});
|
| 882 |
+
const payload = await response.json();
|
| 883 |
+
if (!response.ok || !payload.success) {
|
| 884 |
+
if (action === "pause" || action === "resume") {
|
| 885 |
+
clearPendingTorrentAction(hash);
|
| 886 |
+
await refreshTorrents();
|
| 887 |
+
}
|
| 888 |
+
showToast(payload.message || "Aksi torrent gagal.", "error");
|
| 889 |
+
return;
|
| 890 |
+
}
|
| 891 |
|
| 892 |
if (action === "delete") {
|
| 893 |
closeDeleteModal();
|
|
|
|
| 902 |
showToast(payload.message || "Aksi berhasil diproses.");
|
| 903 |
}
|
| 904 |
|
|
|
|
|
|
|
|
|
|
| 905 |
await refreshTorrents();
|
| 906 |
}
|
| 907 |
|