Add support for same infohashes but different categories

This commit is contained in:
Mukhtar Akere
2025-02-22 00:14:13 +01:00
parent 108da305b3
commit 7af0de76cc
7 changed files with 113 additions and 66 deletions
+2 -1
View File
@@ -24,7 +24,8 @@ func (ui *Handler) Routes() http.Handler {
r.Post("/add", ui.handleAddContent)
r.Post("/repair", ui.handleRepairMedia)
r.Get("/torrents", ui.handleGetTorrents)
r.Delete("/torrents/{hash}", ui.handleDeleteTorrent)
r.Delete("/torrents/{category}/{hash}", ui.handleDeleteTorrent)
r.Delete("/torrents/", ui.handleDeleteTorrents)
r.Get("/config", ui.handleGetConfig)
r.Get("/version", ui.handleGetVersion)
})
+13 -1
View File
@@ -411,11 +411,23 @@ func (ui *Handler) handleGetTorrents(w http.ResponseWriter, r *http.Request) {
func (ui *Handler) handleDeleteTorrent(w http.ResponseWriter, r *http.Request) {
hash := chi.URLParam(r, "hash")
category := r.URL.Query().Get("category")
if hash == "" {
http.Error(w, "No hash provided", http.StatusBadRequest)
return
}
ui.qbit.Storage.Delete(hash)
ui.qbit.Storage.Delete(hash, category)
w.WriteHeader(http.StatusOK)
}
func (ui *Handler) handleDeleteTorrents(w http.ResponseWriter, r *http.Request) {
hashesStr := r.URL.Query().Get("hashes")
if hashesStr == "" {
http.Error(w, "No hashes provided", http.StatusBadRequest)
return
}
hashes := strings.Split(hashesStr, ",")
ui.qbit.Storage.DeleteMultiple(hashes)
w.WriteHeader(http.StatusOK)
}
+8 -7
View File
@@ -86,7 +86,7 @@
<td>${torrent.debrid || 'None'}</td>
<td><span class="badge ${getStateColor(torrent.state)}">${torrent.state}</span></td>
<td>
<button class="btn btn-sm btn-outline-danger" onclick="deleteTorrent('${torrent.hash}')">
<button class="btn btn-sm btn-outline-danger" onclick="deleteTorrent('${torrent.hash}', ${torrent.category})">
<i class="bi bi-trash"></i>
</button>
</td>
@@ -162,11 +162,11 @@
}
}
async function deleteTorrent(hash) {
async function deleteTorrent(hash, category) {
if (!confirm('Are you sure you want to delete this torrent?')) return;
try {
await fetch(`/internal/torrents/${hash}`, {
await fetch(`/internal/torrents/${category}/${hash}`, {
method: 'DELETE'
});
await loadTorrents();
@@ -181,10 +181,11 @@
if (!confirm(`Are you sure you want to delete ${state.selectedTorrents.size} selected torrents?`)) return;
try {
const deletePromises = Array.from(state.selectedTorrents).map(hash =>
fetch(`/internal/torrents/${hash}`, { method: 'DELETE' })
);
await Promise.all(deletePromises);
// COmma separated list of hashes
const hashes = Array.from(state.selectedTorrents).join(',');
await fetch(`/internal/torrents/?hashes=${encodeURIComponent(hashes)}`, {
method: 'DELETE'
});
await loadTorrents();
createToast('Selected torrents deleted successfully');
} catch (error) {