Files
decypharr/pkg/qbit/utils.go
Mukhtar Akere 329e4c60f5 Changelog 0.2.2
2024-09-15 03:33:28 +01:00

42 lines
864 B
Go

package qbit
import (
"encoding/json"
"goBlack/common"
"goBlack/pkg/debrid"
"net/http"
"path/filepath"
"sync"
"time"
)
//func generateSID() (string, error) {
// bytes := make([]byte, sidLength)
// if _, err := rand.Read(bytes); err != nil {
// return "", err
// }
// return hex.EncodeToString(bytes), nil
//}
func JSONResponse(w http.ResponseWriter, data interface{}, code int) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
json.NewEncoder(w).Encode(data)
}
func checkFileLoop(wg *sync.WaitGroup, dir string, file debrid.TorrentFile, ready chan<- debrid.TorrentFile) {
defer wg.Done()
ticker := time.NewTicker(1 * time.Second) // Check every second
defer ticker.Stop()
path := filepath.Join(dir, file.Path)
for {
select {
case <-ticker.C:
if common.FileReady(path) {
ready <- file
return
}
}
}
}