read token from config
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
type ConfigInterface interface {
|
||||
GetVersion() string
|
||||
GetToken() string
|
||||
GetDirectories() []string
|
||||
MeetsConditions(directory, fileID, fileName string) bool
|
||||
}
|
||||
|
||||
@@ -2,4 +2,5 @@ package config
|
||||
|
||||
type ZurgConfig struct {
|
||||
Version string `yaml:"zurg"`
|
||||
Token string `yaml:"token"`
|
||||
}
|
||||
|
||||
@@ -20,6 +20,10 @@ func (z *ZurgConfigV1) GetVersion() string {
|
||||
return "v1"
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) GetToken() string {
|
||||
return z.Token
|
||||
}
|
||||
|
||||
func (z *ZurgConfigV1) GetDirectories() []string {
|
||||
var rootDirectories []string
|
||||
for directory := range z.Directories {
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
@@ -87,7 +86,7 @@ func Setup(app *aero.Application, c config.ConfigInterface, t *torrent.TorrentMa
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -16,7 +16,7 @@ func Router(mux *http.ServeMux, c config.ConfigInterface, t *torrent.TorrentMana
|
||||
HandlePropfindRequest(w, r, t, c)
|
||||
|
||||
case http.MethodGet:
|
||||
HandleGetRequest(w, r, t)
|
||||
HandleGetRequest(w, r, t, c)
|
||||
|
||||
case http.MethodOptions:
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
@@ -45,9 +45,9 @@ func (handler *TorrentManager) refreshTorrents() {
|
||||
// NewTorrentManager creates a new torrent manager
|
||||
// it will fetch all torrents and their info in the background
|
||||
// and store them in-memory
|
||||
func NewTorrentManager(token string, config config.ConfigInterface) *TorrentManager {
|
||||
func NewTorrentManager(config config.ConfigInterface) *TorrentManager {
|
||||
handler := &TorrentManager{
|
||||
token: token,
|
||||
token: config.GetToken(),
|
||||
workerPool: make(chan bool, 10),
|
||||
config: config,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user