Use a proper client for fetch byte

This commit is contained in:
Ben Sarmiento
2023-11-24 21:35:22 +01:00
parent 1e8c50a350
commit 595040ad7e
6 changed files with 97 additions and 116 deletions

View File

@@ -1,17 +1,15 @@
package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/debridmediamanager.com/zurg/internal/config"
"github.com/debridmediamanager.com/zurg/internal/net"
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/debridmediamanager.com/zurg/internal/universal"
"github.com/debridmediamanager.com/zurg/internal/version"
"github.com/panjf2000/ants/v2"
@@ -44,7 +42,8 @@ func main() {
cache := expirable.NewLRU[string, string](1e4, nil, time.Hour)
client := zurghttp.NewHTTPClient(config.GetToken(), 3, nil)
client := zurghttp.NewHTTPClient(config.GetToken(), 5, nil)
rd := realdebrid.NewRealDebrid(config.GetToken(), client, logutil.NewLogger().Named("realdebrid"))
p, err := ants.NewPool(config.GetNumOfWorkers())
@@ -56,58 +55,17 @@ func main() {
torrentMgr := torrent.NewTorrentManager(config, rd, p)
getfile := universal.NewGetFile(client)
mux := http.NewServeMux()
net.Router(mux, config, torrentMgr, cache)
net.Router(mux, getfile, config, torrentMgr, cache)
addr := fmt.Sprintf("%s:%s", config.GetHost(), config.GetPort())
server := &http.Server{Addr: addr, Handler: mux}
shutdown := make(chan os.Signal, 1)
signal.Notify(shutdown, os.Interrupt, syscall.SIGTERM)
go func() {
log.Infof("Starting server on %s", addr)
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Errorf("Failed to start server: %v", err)
os.Exit(1)
}
}()
// log.Debugf("Initializing chunk manager, cores: %d", runtime.NumCPU())
// client := zurghttp.NewHTTPClient(config.GetToken(), 3, config)
// chunkMgr, err := chunk.NewManager(
// "", // in-memory chunks
// 10485760, // 10MB chunk size
// max(runtime.NumCPU()/2, 1), // 8 cores/2 = 4 chunks to load ahead
// max(runtime.NumCPU()/2, 1), // 4 check threads
// max(runtime.NumCPU()-1, 1), // number of chunks that should be read ahead
// runtime.NumCPU()*2, // total chunks kept in memory
// torrentMgr,
// client)
// if nil != err {
// log.Panicf("Failed to initialize chunk manager: %v", err)
// }
// fs := zfs.NewZurgFS(torrentMgr, config, chunkMgr, logutil.NewLogger().Named("zfs"))
// host := fuse.NewFileSystemHost(fs)
// go func() {
// log.Infof("Mounting on %s", config.GetMountPoint())
// if err := zfs.Mount(host, config); err != nil {
// log.Panicf("Failed to mount: %v", err)
// }
// }()
<-shutdown
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
log.Errorf("Server shutdown error: %v\n", err)
log.Infof("Starting server on %s", addr)
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Errorf("Failed to start server: %v", err)
os.Exit(1)
}
// if err := zfs.Unmount(host); err != nil {
// log.Errorf("Unmount error: %v\n", err)
// }
log.Info("BYE")
}