Changelog 0.2.0 (#1)

* Changelog 0.2.0
This commit is contained in:
Mukhtar Akere
2024-09-12 06:01:10 +01:00
committed by GitHub
parent 60c6cb32d3
commit 9511f3e99e
25 changed files with 1494 additions and 274 deletions

48
pkg/qbit/utils.go Normal file
View File

@@ -0,0 +1,48 @@
package qbit
import (
"crypto/rand"
"encoding/hex"
"encoding/json"
"goBlack/pkg/debrid"
"net/http"
"os"
"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 fileReady(path string) bool {
_, err := os.Stat(path)
return !os.IsNotExist(err) // Returns true if the file exists
}
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 fileReady(path) {
ready <- file
return
}
}
}
}