- Speed up repairs when checking links \n

- Remove run on start for repairs since it causes issues \n
- Add support for arr-specific debrid
- Support for queuing system
- Support for no-op when sending torrents to debrid
This commit is contained in:
Mukhtar Akere
2025-06-14 16:09:28 +01:00
parent 3efda45304
commit a539aa53bd
28 changed files with 428 additions and 355 deletions

View File

@@ -87,7 +87,7 @@ func (q *QBit) authContext(next http.Handler) http.Handler {
a := arrs.Get(category)
if a == nil {
downloadUncached := false
a = arr.New(category, "", "", false, false, &downloadUncached)
a = arr.New(category, "", "", false, false, &downloadUncached, "")
}
if err == nil {
host = strings.TrimSpace(host)

View File

@@ -88,12 +88,15 @@ func (q *QBit) handleTorrentsAdd(w http.ResponseWriter, r *http.Request) {
return
}
isSymlink := strings.ToLower(r.FormValue("sequentialDownload")) != "true"
action := "symlink"
if strings.ToLower(r.FormValue("sequentialDownload")) != "true" {
action = "download"
}
debridName := r.FormValue("debrid")
category := r.FormValue("category")
_arr := getArr(ctx)
if _arr == nil {
_arr = arr.New(category, "", "", false, false, nil)
_arr = arr.New(category, "", "", false, false, nil, "")
}
atleastOne := false
@@ -104,7 +107,7 @@ func (q *QBit) handleTorrentsAdd(w http.ResponseWriter, r *http.Request) {
urlList = append(urlList, strings.TrimSpace(u))
}
for _, url := range urlList {
if err := q.addMagnet(ctx, url, _arr, debridName, isSymlink); err != nil {
if err := q.addMagnet(ctx, url, _arr, debridName, action); err != nil {
q.logger.Error().Err(err).Msgf("Error adding magnet")
http.Error(w, err.Error(), http.StatusBadRequest)
return
@@ -117,7 +120,7 @@ func (q *QBit) handleTorrentsAdd(w http.ResponseWriter, r *http.Request) {
if r.MultipartForm != nil && r.MultipartForm.File != nil {
if files := r.MultipartForm.File["torrents"]; len(files) > 0 {
for _, fileHeader := range files {
if err := q.addTorrent(ctx, fileHeader, _arr, debridName, isSymlink); err != nil {
if err := q.addTorrent(ctx, fileHeader, _arr, debridName, action); err != nil {
q.logger.Error().Err(err).Msgf("Error adding torrent")
http.Error(w, err.Error(), http.StatusBadRequest)
return
@@ -241,8 +244,7 @@ func (q *QBit) handleTorrentFiles(w http.ResponseWriter, r *http.Request) {
if torrent == nil {
return
}
files := q.getTorrentFiles(torrent)
request.JSONResponse(w, files, http.StatusOK)
request.JSONResponse(w, torrent.Files, http.StatusOK)
}
func (q *QBit) handleSetCategory(w http.ResponseWriter, r *http.Request) {

View File

@@ -13,14 +13,14 @@ import (
)
// All torrent-related helpers goes here
func (q *QBit) addMagnet(ctx context.Context, url string, arr *arr.Arr, debrid string, isSymlink bool) error {
func (q *QBit) addMagnet(ctx context.Context, url string, arr *arr.Arr, debrid string, action string) error {
magnet, err := utils.GetMagnetFromUrl(url)
if err != nil {
return fmt.Errorf("error parsing magnet link: %w", err)
}
_store := store.Get()
importReq := store.NewImportRequest(debrid, q.DownloadFolder, magnet, arr, isSymlink, false, "", store.ImportTypeQBitTorrent)
importReq := store.NewImportRequest(debrid, q.DownloadFolder, magnet, arr, action, false, "", store.ImportTypeQBitTorrent)
err = _store.AddTorrent(ctx, importReq)
if err != nil {
@@ -29,7 +29,7 @@ func (q *QBit) addMagnet(ctx context.Context, url string, arr *arr.Arr, debrid s
return nil
}
func (q *QBit) addTorrent(ctx context.Context, fileHeader *multipart.FileHeader, arr *arr.Arr, debrid string, isSymlink bool) error {
func (q *QBit) addTorrent(ctx context.Context, fileHeader *multipart.FileHeader, arr *arr.Arr, debrid string, action string) error {
file, _ := fileHeader.Open()
defer file.Close()
var reader io.Reader = file
@@ -38,7 +38,7 @@ func (q *QBit) addTorrent(ctx context.Context, fileHeader *multipart.FileHeader,
return fmt.Errorf("error reading file: %s \n %w", fileHeader.Filename, err)
}
_store := store.Get()
importReq := store.NewImportRequest(debrid, q.DownloadFolder, magnet, arr, isSymlink, false, "", store.ImportTypeQBitTorrent)
importReq := store.NewImportRequest(debrid, q.DownloadFolder, magnet, arr, action, false, "", store.ImportTypeQBitTorrent)
err = _store.AddTorrent(ctx, importReq)
if err != nil {
return fmt.Errorf("failed to process torrent: %w", err)
@@ -83,20 +83,6 @@ func (q *QBit) GetTorrentProperties(t *store.Torrent) *TorrentProperties {
}
}
func (q *QBit) getTorrentFiles(t *store.Torrent) []*TorrentFile {
files := make([]*TorrentFile, 0)
if t.DebridTorrent == nil {
return files
}
for _, file := range t.DebridTorrent.GetFiles() {
files = append(files, &TorrentFile{
Name: file.Path,
Size: file.Size,
})
}
return files
}
func (q *QBit) setTorrentTags(t *store.Torrent, tags []string) bool {
torrentTags := strings.Split(t.Tags, ",")
for _, tag := range tags {

View File

@@ -202,17 +202,6 @@ type TorrentProperties struct {
UpSpeedAvg int `json:"up_speed_avg,omitempty"`
}
type TorrentFile struct {
Index int `json:"index,omitempty"`
Name string `json:"name,omitempty"`
Size int64 `json:"size,omitempty"`
Progress int `json:"progress,omitempty"`
Priority int `json:"priority,omitempty"`
IsSeed bool `json:"is_seed,omitempty"`
PieceRange []int `json:"piece_range,omitempty"`
Availability float64 `json:"availability,omitempty"`
}
func getAppPreferences() *AppPreferences {
preferences := &AppPreferences{
AddTrackers: "",