Download pause/resume özelliği eklendi.

This commit is contained in:
2025-10-28 22:38:06 +03:00
parent ef8f211e8a
commit 0057392662
2 changed files with 427 additions and 25 deletions

View File

@@ -4,6 +4,7 @@
let torrents = [];
let ws;
let isAllPaused = false;
// Modal / player state
let showModal = false;
@@ -26,7 +27,11 @@
ws = new WebSocket(url);
ws.onmessage = (e) => {
const d = JSON.parse(e.data);
if (d.type === "progress") torrents = d.torrents || [];
if (d.type === "progress") {
torrents = d.torrents || [];
// Tüm torrentlerin pause durumunu kontrol et
updateAllPausedState();
}
};
}
@@ -34,6 +39,7 @@
const r = await apiFetch("/api/torrents"); // ✅ fetch yerine apiFetch
if (!r.ok) return;
torrents = await r.json();
updateAllPausedState();
}
async function upload(e) {
@@ -67,6 +73,79 @@
await list();
}
async function removeAllTorrents() {
if (!confirm("Tüm torrent listesini silmek istediğinizden emin misiniz?")) return;
// Tüm torrentleri API üzerinden sil
for (const torrent of torrents) {
await apiFetch(`/api/torrents/${torrent.infoHash}`, { method: "DELETE" });
}
// Listeyi güncelle
await list();
}
async function toggleAllTorrents() {
const action = isAllPaused ? "resume" : "pause";
try {
const r = await apiFetch("/api/torrents/toggle-all", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action })
});
if (!r.ok) return;
const result = await r.json();
console.log(`${action} işlemi: ${result.updatedCount}/${result.totalCount} torrent güncellendi`);
// Durumu güncelle
isAllPaused = !isAllPaused;
// Listeyi yenile
await list();
} catch (err) {
console.error("Toggle all torrents error:", err);
}
}
function updateAllPausedState() {
if (torrents.length === 0) {
isAllPaused = false;
return;
}
// Eğer tüm torrentler paused ise, global durumu paused yap
const allPaused = torrents.every(t => t.paused === true);
isAllPaused = allPaused;
}
async function toggleSingleTorrent(hash) {
const torrent = torrents.find(t => t.infoHash === hash);
if (!torrent) return;
const action = torrent.paused ? "resume" : "pause";
try {
const r = await apiFetch(`/api/torrents/${hash}/toggle`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action })
});
if (!r.ok) return;
const result = await r.json();
console.log(`Single torrent ${action}:`, result);
// Listeyi güncelle
await list();
} catch (err) {
console.error("Toggle single torrent error:", err);
}
}
function streamURL(hash, index = 0) {
const token = localStorage.getItem("token");
return `${API}/stream/${hash}?index=${index}&token=${token}`;
@@ -303,19 +382,41 @@
<section class="files">
<h2>Transfers</h2>
<div style="display:flex; gap:10px; margin-bottom:10px;">
<label class="btn-primary" style="cursor:pointer;">
<i class="fa-solid fa-plus btn-icon"></i> NEW TRANSFER
<input
type="file"
accept=".torrent"
on:change={upload}
style="display:none;"
/>
</label>
<label class="btn-primary" on:click={addMagnet}>
<i class="fa-solid fa-magnet btn-icon"></i> MAGNET
</label>
<div style="display:flex; gap:10px; margin-bottom:10px; justify-content: space-between;">
<div style="display:flex; gap:10px;">
<label class="btn-primary" style="cursor:pointer;">
<i class="fa-solid fa-plus btn-icon"></i> NEW TRANSFER
<input
type="file"
accept=".torrent"
on:change={upload}
style="display:none;"
/>
</label>
<label class="btn-primary" on:click={addMagnet}>
<i class="fa-solid fa-magnet btn-icon"></i> MAGNET
</label>
</div>
<div style="display:flex; gap:10px;">
<button
class="btn-toggle-all"
on:click={toggleAllTorrents}
title={isAllPaused ? "Resume All Torrents" : "Pause All Torrents"}
>
{#if isAllPaused}
<i class="fa-solid fa-play"></i>
{:else}
<i class="fa-solid fa-pause"></i>
{/if}
</button>
<button
class="btn-remove-all"
on:click={removeAllTorrents}
title="Remove All Torrent List"
>
<i class="fa-solid fa-trash"></i>
</button>
</div>
</div>
{#if torrents.length === 0}
@@ -358,11 +459,24 @@
<div class="torrent-info">
<div class="torrent-header">
<div class="torrent-name">{t.name}</div>
<button
class="remove-btn"
on:click|stopPropagation={() => removeTorrent(t.infoHash)}
title="Sil"></button
>
<div style="display:flex; gap:5px;">
<button
class="toggle-btn"
on:click|stopPropagation={() => toggleSingleTorrent(t.infoHash)}
title={t.paused ? "Devam Ettir" : "Durdur"}
>
{#if t.paused}
<i class="fa-solid fa-play"></i>
{:else}
<i class="fa-solid fa-pause"></i>
{/if}
</button>
<button
class="remove-btn"
on:click|stopPropagation={() => removeTorrent(t.infoHash)}
title="Sil"></button
>
</div>
</div>
<div class="torrent-hash">
@@ -583,6 +697,22 @@
word-break: break-word;
}
.toggle-btn {
background: transparent;
border: none;
font-size: 18px;
cursor: pointer;
transition: transform 0.15s;
color: #4caf50;
padding: 2px;
border-radius: 4px;
}
.toggle-btn:hover {
transform: scale(1.2);
background: rgba(76, 175, 80, 0.1);
}
.remove-btn {
background: transparent;
border: none;
@@ -800,4 +930,79 @@
font-size: 10px;
}
}
/* --- Toggle All Torrents Button --- */
.btn-toggle-all {
background: transparent;
border: 1px solid #ddd;
color: #666;
padding: 10px 14px;
border-radius: 6px;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
height: 36px;
width: 36px;
transition: all 0.2s ease;
font-size: 14px;
}
.btn-toggle-all:hover {
background: var(--yellow);
border-color: var(--yellow-dark);
color: #222;
transform: scale(1.05);
}
.btn-toggle-all:active {
transform: scale(0.95);
}
/* --- Remove All Torrent List Button --- */
.btn-remove-all {
background: transparent;
border: 1px solid #ddd;
color: #666;
padding: 10px 14px;
border-radius: 6px;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
height: 36px;
width: 36px;
transition: all 0.2s ease;
font-size: 14px;
}
.btn-remove-all:hover {
background: #ff4444;
border-color: #cc0000;
color: white;
transform: scale(1.05);
}
.btn-remove-all:active {
transform: scale(0.95);
}
/* Responsive adjustments for toggle and remove buttons */
@media (max-width: 768px) {
.btn-toggle-all,
.btn-remove-all {
height: 36px;
width: 36px;
padding: 8px;
}
}
@media (max-width: 480px) {
.btn-toggle-all,
.btn-remove-all {
height: 34px;
width: 34px;
font-size: 12px;
}
}
</style>