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

View File

@@ -213,8 +213,9 @@ func (q *QBit) handleTorrentsDelete(w http.ResponseWriter, r *http.Request) {
http.Error(w, "No hashes provided", http.StatusBadRequest)
return
}
category := ctx.Value("category").(string)
for _, hash := range hashes {
q.Storage.Delete(hash)
q.Storage.Delete(hash, category)
}
w.WriteHeader(http.StatusOK)
@@ -223,8 +224,9 @@ func (q *QBit) handleTorrentsDelete(w http.ResponseWriter, r *http.Request) {
func (q *QBit) handleTorrentsPause(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
hashes, _ := ctx.Value("hashes").([]string)
category := ctx.Value("category").(string)
for _, hash := range hashes {
torrent := q.Storage.Get(hash)
torrent := q.Storage.Get(hash, category)
if torrent == nil {
continue
}
@@ -237,8 +239,9 @@ func (q *QBit) handleTorrentsPause(w http.ResponseWriter, r *http.Request) {
func (q *QBit) handleTorrentsResume(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
hashes, _ := ctx.Value("hashes").([]string)
category := ctx.Value("category").(string)
for _, hash := range hashes {
torrent := q.Storage.Get(hash)
torrent := q.Storage.Get(hash, category)
if torrent == nil {
continue
}
@@ -251,8 +254,9 @@ func (q *QBit) handleTorrentsResume(w http.ResponseWriter, r *http.Request) {
func (q *QBit) handleTorrentRecheck(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
hashes, _ := ctx.Value("hashes").([]string)
category := ctx.Value("category").(string)
for _, hash := range hashes {
torrent := q.Storage.Get(hash)
torrent := q.Storage.Get(hash, category)
if torrent == nil {
continue
}
@@ -293,15 +297,18 @@ func (q *QBit) handleCreateCategory(w http.ResponseWriter, r *http.Request) {
}
func (q *QBit) handleTorrentProperties(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
hash := r.URL.Query().Get("hash")
torrent := q.Storage.Get(hash)
torrent := q.Storage.Get(hash, ctx.Value("category").(string))
properties := q.GetTorrentProperties(torrent)
request.JSONResponse(w, properties, http.StatusOK)
}
func (q *QBit) handleTorrentFiles(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
hash := r.URL.Query().Get("hash")
torrent := q.Storage.Get(hash)
torrent := q.Storage.Get(hash, ctx.Value("category").(string))
if torrent == nil {
return
}