This commit is contained in:
Mukhtar Akere
2025-04-25 12:48:04 +01:00
parent 07f1d0f28d
commit ae5e237379
3 changed files with 23 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
package main package main
import ( import (
"cmp"
"context" "context"
"encoding/json" "encoding/json"
"flag" "flag"
@@ -8,6 +9,7 @@ import (
"github.com/sirrobot01/decypharr/internal/config" "github.com/sirrobot01/decypharr/internal/config"
"net/http" "net/http"
"os" "os"
"strings"
"time" "time"
) )
@@ -46,19 +48,24 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
baseUrl := cmp.Or(cfg.URLBase, "/")
if !strings.HasPrefix(baseUrl, "/") {
baseUrl = "/" + baseUrl
}
// Check qBittorrent API // Check qBittorrent API
if checkQbitAPI(ctx, port) { if checkQbitAPI(ctx, baseUrl, port) {
status.QbitAPI = true status.QbitAPI = true
} }
// Check Web UI // Check Web UI
if checkWebUI(ctx, port) { if checkWebUI(ctx, baseUrl, port) {
status.WebUI = true status.WebUI = true
} }
// Check WebDAV if enabled // Check WebDAV if enabled
if webdavPath != "" { if webdavPath != "" {
if checkWebDAV(ctx, port, webdavPath) { if checkWebDAV(ctx, baseUrl, port, webdavPath) {
status.WebDAVService = true status.WebDAVService = true
} }
} else { } else {
@@ -94,8 +101,9 @@ func getEnvOrDefault(key, defaultValue string) string {
return defaultValue return defaultValue
} }
func checkQbitAPI(ctx context.Context, port string) bool { func checkQbitAPI(ctx context.Context, baseUrl, port string) bool {
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("http://localhost:%s/api/v2/app/version", port), nil) url := fmt.Sprintf("http://localhost:%s%sapi/v2/app/version", port, baseUrl)
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
if err != nil { if err != nil {
return false return false
} }
@@ -109,8 +117,8 @@ func checkQbitAPI(ctx context.Context, port string) bool {
return resp.StatusCode == http.StatusOK return resp.StatusCode == http.StatusOK
} }
func checkWebUI(ctx context.Context, port string) bool { func checkWebUI(ctx context.Context, baseUrl, port string) bool {
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("http://localhost:%s/", port), nil) req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("http://localhost:%s%s", port, baseUrl), nil)
if err != nil { if err != nil {
return false return false
} }
@@ -124,8 +132,8 @@ func checkWebUI(ctx context.Context, port string) bool {
return resp.StatusCode == http.StatusOK return resp.StatusCode == http.StatusOK
} }
func checkWebDAV(ctx context.Context, port, path string) bool { func checkWebDAV(ctx context.Context, baseUrl, port, path string) bool {
url := fmt.Sprintf("http://localhost:%s/webdav/%s", port, path) url := fmt.Sprintf("http://localhost:%s%swebdav/%s", port, baseUrl, path)
req, err := http.NewRequestWithContext(ctx, "PROPFIND", url, nil) req, err := http.NewRequestWithContext(ctx, "PROPFIND", url, nil)
if err != nil { if err != nil {
return false return false

View File

@@ -130,7 +130,7 @@ func (c *Config) loadConfig() error {
return fmt.Errorf("error unmarshaling config: %w", err) return fmt.Errorf("error unmarshaling config: %w", err)
} }
} }
return nil return c.Save()
} }
func validateDebrids(debrids []Debrid) error { func validateDebrids(debrids []Debrid) error {
@@ -359,7 +359,7 @@ func (c *Config) createConfig(path string) error {
Categories: []string{"sonarr", "radarr"}, Categories: []string{"sonarr", "radarr"},
RefreshInterval: 15, RefreshInterval: 15,
} }
return c.Save() return nil
} }
// Reload forces a reload of the configuration from disk // Reload forces a reload of the configuration from disk

View File

@@ -1,12 +1,14 @@
package web package web
import ( import (
"cmp"
"embed" "embed"
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
"github.com/rs/zerolog" "github.com/rs/zerolog"
"github.com/sirrobot01/decypharr/internal/logger" "github.com/sirrobot01/decypharr/internal/logger"
"github.com/sirrobot01/decypharr/pkg/qbit" "github.com/sirrobot01/decypharr/pkg/qbit"
"html/template" "html/template"
"os"
) )
var restartFunc func() var restartFunc func()
@@ -61,7 +63,8 @@ func New(qbit *qbit.QBit) *Handler {
} }
var ( var (
store = sessions.NewCookieStore([]byte("your-secret-key")) secretKey = cmp.Or(os.Getenv("DECYPHARR_SECRET_KEY"), "\"wqj(v%lj*!-+kf@4&i95rhh_!5_px5qnuwqbr%cjrvrozz_r*(\"")
store = sessions.NewCookieStore([]byte(secretKey))
templates *template.Template templates *template.Template
) )