Changelog 0.6.0

This commit is contained in:
Mukhtar Akere
2025-04-16 17:31:50 +01:00
parent ea79e2a6fb
commit af067cace9
39 changed files with 1079 additions and 727 deletions
+16 -7
View File
@@ -226,26 +226,34 @@ func (q *QBit) preCacheFile(name string, filePaths []string) error {
}
for _, filePath := range filePaths {
func(f string) {
err := func(f string) error {
file, err := os.Open(f)
if err != nil {
return
return err
}
defer file.Close()
// Pre-cache the file header (first 256KB) using 16KB chunks.
q.readSmallChunks(file, 0, 256*1024, 16*1024)
q.readSmallChunks(file, 1024*1024, 64*1024, 16*1024)
if err := q.readSmallChunks(file, 0, 256*1024, 16*1024); err != nil {
return err
}
if err := q.readSmallChunks(file, 1024*1024, 64*1024, 16*1024); err != nil {
return err
}
return nil
}(filePath)
if err != nil {
return err
}
}
return nil
}
func (q *QBit) readSmallChunks(file *os.File, startPos int64, totalToRead int, chunkSize int) {
func (q *QBit) readSmallChunks(file *os.File, startPos int64, totalToRead int, chunkSize int) error {
_, err := file.Seek(startPos, 0)
if err != nil {
return
return err
}
buf := make([]byte, chunkSize)
@@ -262,9 +270,10 @@ func (q *QBit) readSmallChunks(file *os.File, startPos int64, totalToRead int, c
if err == io.EOF {
break
}
return
return err
}
bytesRemaining -= n
}
return nil
}
+1 -1
View File
@@ -231,7 +231,7 @@ func (q *QBit) handleTorrentsDelete(w http.ResponseWriter, r *http.Request) {
}
category := ctx.Value("category").(string)
for _, hash := range hashes {
q.Storage.Delete(hash, category)
q.Storage.Delete(hash, category, false)
}
w.WriteHeader(http.StatusOK)
+1 -1
View File
@@ -73,7 +73,7 @@ func (i *ImportRequest) Process(q *QBit) (err error) {
debridTorrent, err := debrid.ProcessTorrent(svc.Debrid, i.Magnet, i.Arr, i.IsSymlink, i.DownloadUncached)
if err != nil || debridTorrent == nil {
if debridTorrent != nil {
dbClient := service.GetDebrid().GetByName(debridTorrent.Debrid)
dbClient := service.GetDebrid().GetClient(debridTorrent.Debrid)
go func() {
_ = dbClient.DeleteTorrent(debridTorrent.Id)
}()
+1 -2
View File
@@ -1,14 +1,13 @@
package qbit
import (
"github.com/google/uuid"
"github.com/sirrobot01/decypharr/internal/utils"
"strings"
)
func createTorrentFromMagnet(magnet *utils.Magnet, category, source string) *Torrent {
torrent := &Torrent{
ID: uuid.NewString(),
ID: "",
Hash: strings.ToLower(magnet.InfoHash),
Name: magnet.Name,
Size: magnet.Size,
+44 -3
View File
@@ -3,6 +3,7 @@ package qbit
import (
"fmt"
"github.com/goccy/go-json"
"github.com/sirrobot01/decypharr/pkg/service"
"os"
"sort"
"sync"
@@ -166,7 +167,7 @@ func (ts *TorrentStorage) Update(torrent *Torrent) {
}()
}
func (ts *TorrentStorage) Delete(hash, category string) {
func (ts *TorrentStorage) Delete(hash, category string, removeFromDebrid bool) {
ts.mu.Lock()
defer ts.mu.Unlock()
key := keyPair(hash, category)
@@ -181,10 +182,22 @@ func (ts *TorrentStorage) Delete(hash, category string) {
}
}
}
delete(ts.torrents, key)
if torrent == nil {
return
}
if removeFromDebrid && torrent.ID != "" && torrent.Debrid != "" {
dbClient := service.GetDebrid().GetClient(torrent.Debrid)
if dbClient != nil {
err := dbClient.DeleteTorrent(torrent.ID)
if err != nil {
fmt.Println(err)
}
}
}
delete(ts.torrents, key)
// Delete the torrent folder
if torrent.ContentPath != "" {
err := os.RemoveAll(torrent.ContentPath)
@@ -200,13 +213,27 @@ func (ts *TorrentStorage) Delete(hash, category string) {
}()
}
func (ts *TorrentStorage) DeleteMultiple(hashes []string) {
func (ts *TorrentStorage) DeleteMultiple(hashes []string, removeFromDebrid bool) {
ts.mu.Lock()
defer ts.mu.Unlock()
toDelete := make(map[string]string)
for _, hash := range hashes {
for key, torrent := range ts.torrents {
if torrent == nil {
continue
}
if torrent.Hash == hash {
if removeFromDebrid && torrent.ID != "" && torrent.Debrid != "" {
toDelete[torrent.ID] = torrent.Debrid
}
delete(ts.torrents, key)
if torrent.ContentPath != "" {
err := os.RemoveAll(torrent.ContentPath)
if err != nil {
return
}
}
}
}
}
@@ -216,6 +243,20 @@ func (ts *TorrentStorage) DeleteMultiple(hashes []string) {
fmt.Println(err)
}
}()
go func() {
for id, debrid := range toDelete {
dbClient := service.GetDebrid().GetClient(debrid)
if dbClient == nil {
continue
}
fmt.Println("Deleting torrent from debrid:", id)
err := dbClient.DeleteTorrent(id)
if err != nil {
fmt.Println(err)
}
}
}()
}
func (ts *TorrentStorage) Save() error {
+3 -3
View File
@@ -59,7 +59,7 @@ func (q *QBit) Process(ctx context.Context, magnet *utils.Magnet, category strin
debridTorrent, err := db.ProcessTorrent(svc.Debrid, magnet, a, isSymlink, false)
if err != nil || debridTorrent == nil {
if debridTorrent != nil {
dbClient := service.GetDebrid().GetByName(debridTorrent.Debrid)
dbClient := service.GetDebrid().GetClient(debridTorrent.Debrid)
go func() {
_ = dbClient.DeleteTorrent(debridTorrent.Id)
}()
@@ -77,7 +77,7 @@ func (q *QBit) Process(ctx context.Context, magnet *utils.Magnet, category strin
func (q *QBit) ProcessFiles(torrent *Torrent, debridTorrent *debrid.Torrent, arr *arr.Arr, isSymlink bool) {
svc := service.GetService()
client := svc.Debrid.GetByName(debridTorrent.Debrid)
client := svc.Debrid.GetClient(debridTorrent.Debrid)
for debridTorrent.Status != "downloaded" {
q.logger.Debug().Msgf("%s <- (%s) Download Progress: %.2f%%", debridTorrent.Debrid, debridTorrent.Name, debridTorrent.Progress)
dbT, err := client.CheckStatus(debridTorrent, isSymlink)
@@ -216,7 +216,7 @@ func (q *QBit) UpdateTorrent(t *Torrent, debridTorrent *debrid.Torrent) *Torrent
if debridTorrent == nil {
return t
}
_db := service.GetDebrid().GetByName(debridTorrent.Debrid)
_db := service.GetDebrid().GetClient(debridTorrent.Debrid)
if debridTorrent.Status != "downloaded" {
_ = _db.UpdateTorrent(debridTorrent)
}