read token from config

This commit is contained in:
Ben Sarmiento
2023-10-20 01:49:06 +02:00
parent 464f522fea
commit 0e442fc9be
9 changed files with 23 additions and 22 deletions

View File

@@ -4,18 +4,18 @@ import (
"fmt"
"log"
"net/http"
"os"
"path"
"path/filepath"
"strings"
"github.com/debridmediamanager.com/zurg/internal/config"
"github.com/debridmediamanager.com/zurg/internal/torrent"
"github.com/debridmediamanager.com/zurg/pkg/davextra"
"github.com/debridmediamanager.com/zurg/pkg/realdebrid"
)
// HandleGetRequest handles a GET request to a file
func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager) {
func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.TorrentManager, c config.ConfigInterface) {
requestPath := path.Clean(r.URL.Path)
segments := strings.Split(requestPath, "/")
@@ -48,13 +48,15 @@ func HandleGetRequest(w http.ResponseWriter, r *http.Request, t *torrent.Torrent
}
unrestrictFn := func() (*realdebrid.UnrestrictResponse, error) {
return realdebrid.UnrestrictLink(os.Getenv("RD_TOKEN"), link)
return realdebrid.UnrestrictLink(c.GetToken(), link)
}
resp := realdebrid.RetryUntilOk(unrestrictFn)
if resp == nil {
// TODO: Readd the file
// when unrestricting fails, it means the file is not available anymore, but still in their database
// if it's the only file, tough luck
// if it's the only file, try to readd it
// delete the old one, add a new one
log.Println("Cannot unrestrict link", link, filenameV2)
http.Error(w, "Cannot find file", http.StatusNotFound)
return