Fix timeout in grab; remove pprof
This commit is contained in:
14
main.go
14
main.go
@@ -5,10 +5,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"github.com/sirrobot01/decypharr/cmd/decypharr"
|
"github.com/sirrobot01/decypharr/cmd/decypharr"
|
||||||
"github.com/sirrobot01/decypharr/internal/config"
|
"github.com/sirrobot01/decypharr/internal/config"
|
||||||
"github.com/sirrobot01/decypharr/pkg/version"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
|
||||||
_ "net/http/pprof" // registers pprof handlers
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
@@ -22,22 +19,13 @@ func main() {
|
|||||||
debug.PrintStack()
|
debug.PrintStack()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if version.GetInfo().Channel == "dev" {
|
|
||||||
log.Println("Running in dev mode")
|
|
||||||
go func() {
|
|
||||||
if err := http.ListenAndServe(":6060", nil); err != nil {
|
|
||||||
log.Fatalf("pprof server failed: %v", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
var configPath string
|
var configPath string
|
||||||
flag.StringVar(&configPath, "config", "/data", "path to the data folder")
|
flag.StringVar(&configPath, "config", "/data", "path to the data folder")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
config.SetConfigPath(configPath)
|
config.SetConfigPath(configPath)
|
||||||
config.Get()
|
config.Get()
|
||||||
|
|
||||||
// Create a context that's cancelled on SIGINT/SIGTERM
|
// Create a context canceled on SIGINT/SIGTERM
|
||||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||||
defer stop()
|
defer stop()
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package qbit
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cavaliergopher/grab/v3"
|
"github.com/cavaliergopher/grab/v3"
|
||||||
"github.com/sirrobot01/decypharr/internal/request"
|
|
||||||
"github.com/sirrobot01/decypharr/internal/utils"
|
"github.com/sirrobot01/decypharr/internal/utils"
|
||||||
debridTypes "github.com/sirrobot01/decypharr/pkg/debrid/types"
|
debridTypes "github.com/sirrobot01/decypharr/pkg/debrid/types"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -20,7 +20,7 @@ func Download(client *grab.Client, url, filename string, progressCallback func(i
|
|||||||
}
|
}
|
||||||
resp := client.Do(req)
|
resp := client.Do(req)
|
||||||
|
|
||||||
t := time.NewTicker(time.Second)
|
t := time.NewTicker(time.Second * 2)
|
||||||
defer t.Stop()
|
defer t.Stop()
|
||||||
|
|
||||||
var lastReported int64
|
var lastReported int64
|
||||||
@@ -93,8 +93,13 @@ func (q *QBit) downloadFiles(torrent *Torrent, parent string) {
|
|||||||
}
|
}
|
||||||
client := &grab.Client{
|
client := &grab.Client{
|
||||||
UserAgent: "Decypharr[QBitTorrent]",
|
UserAgent: "Decypharr[QBitTorrent]",
|
||||||
HTTPClient: request.New(request.WithTimeout(0)),
|
HTTPClient: &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
Proxy: http.ProxyFromEnvironment,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
errChan := make(chan error, len(debridTorrent.Files))
|
||||||
for _, file := range debridTorrent.Files {
|
for _, file := range debridTorrent.Files {
|
||||||
if file.DownloadLink == nil {
|
if file.DownloadLink == nil {
|
||||||
q.logger.Info().Msgf("No download link found for %s", file.Name)
|
q.logger.Info().Msgf("No download link found for %s", file.Name)
|
||||||
@@ -116,12 +121,25 @@ func (q *QBit) downloadFiles(torrent *Torrent, parent string) {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
q.logger.Error().Msgf("Failed to download %s: %v", filename, err)
|
q.logger.Error().Msgf("Failed to download %s: %v", filename, err)
|
||||||
|
errChan <- err
|
||||||
} else {
|
} else {
|
||||||
q.logger.Info().Msgf("Downloaded %s", filename)
|
q.logger.Info().Msgf("Downloaded %s", filename)
|
||||||
}
|
}
|
||||||
}(file)
|
}(file)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
|
close(errChan)
|
||||||
|
var errors []error
|
||||||
|
for err := range errChan {
|
||||||
|
if err != nil {
|
||||||
|
errors = append(errors, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(errors) > 0 {
|
||||||
|
q.logger.Error().Msgf("Errors occurred during download: %v", errors)
|
||||||
|
return
|
||||||
|
}
|
||||||
q.logger.Info().Msgf("Downloaded all files for %s", debridTorrent.Name)
|
q.logger.Info().Msgf("Downloaded all files for %s", debridTorrent.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ func (ui *Handler) handleGetTorrents(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func (ui *Handler) handleDeleteTorrent(w http.ResponseWriter, r *http.Request) {
|
func (ui *Handler) handleDeleteTorrent(w http.ResponseWriter, r *http.Request) {
|
||||||
hash := chi.URLParam(r, "hash")
|
hash := chi.URLParam(r, "hash")
|
||||||
category := r.URL.Query().Get("category")
|
category := chi.URLParam(r, "category")
|
||||||
removeFromDebrid := r.URL.Query().Get("removeFromDebrid") == "true"
|
removeFromDebrid := r.URL.Query().Get("removeFromDebrid") == "true"
|
||||||
if hash == "" {
|
if hash == "" {
|
||||||
http.Error(w, "No hash provided", http.StatusBadRequest)
|
http.Error(w, "No hash provided", http.StatusBadRequest)
|
||||||
|
|||||||
@@ -200,8 +200,15 @@
|
|||||||
|
|
||||||
window.urlBase = "{{.URLBase}}";
|
window.urlBase = "{{.URLBase}}";
|
||||||
|
|
||||||
function joinURL(...segments) {
|
function joinURL(base, path) {
|
||||||
return segments.join('/').replace(/[/]+/g, '/').replace(/^(.+):\//, '$1://').replace(/^file:/, 'file:/').replace(/\/(?=[?&#])/g, '').replace(/\?/g, '&');
|
if (!base.endsWith('/')) {
|
||||||
|
base += '/';
|
||||||
|
}
|
||||||
|
if (path.startsWith('/')) {
|
||||||
|
path = path.substring(1);
|
||||||
|
}
|
||||||
|
return base + path;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetcher(endpoint, options = {}) {
|
function fetcher(endpoint, options = {}) {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package webdav
|
package webdav
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-chi/chi/v5"
|
|
||||||
"github.com/sirrobot01/decypharr/internal/utils"
|
|
||||||
"github.com/stanNthe5/stringbuf"
|
"github.com/stanNthe5/stringbuf"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -146,19 +144,3 @@ func writeXml(w http.ResponseWriter, status int, buf stringbuf.StringBuf) {
|
|||||||
w.WriteHeader(status)
|
w.WriteHeader(status)
|
||||||
_, _ = w.Write(buf.Bytes())
|
_, _ = w.Write(buf.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func getParam(r *http.Request, key string) string {
|
|
||||||
if r.URL == nil || r.URL.Query() == nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
if v := chi.URLParam(r, key); v != "" {
|
|
||||||
return utils.PathUnescape(v)
|
|
||||||
}
|
|
||||||
if v := r.URL.Query().Get(key); v != "" {
|
|
||||||
return utils.PathUnescape(v)
|
|
||||||
}
|
|
||||||
if v := r.FormValue(key); v != "" {
|
|
||||||
return utils.PathUnescape(v)
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user