This commit is contained in:
2026-04-22 18:23:19 +02:00
commit e3e85e4a44
19 changed files with 1273 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
package configs
import (
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
)
type Config struct {
JellyfinURL string `envconfig:"JELLYFIN_URL" required:"true"`
JellyfinAPIKey string `envconfig:"JELLYFIN_API_KEY" required:"true"`
JellyfinUserID string `envconfig:"JELLYFIN_USER_ID" required:"true"`
TMDbAPIKey string `envconfig:"TMDB_API_KEY" required:"true"`
LLMEnabled bool `envconfig:"LLM_ENABLED" default:"false"`
LLMBaseURL string `envconfig:"LLM_BASE_URL" default:"http://localhost:11434/v1"`
LLMAPIKey string `envconfig:"LLM_API_KEY" default:""`
LLMModel string `envconfig:"LLM_MODEL" default:"llama3"`
RadarrEnabled bool `envconfig:"RADARR_ENABLED" default:"false"`
RadarrURL string `envconfig:"RADARR_URL"`
RadarrAPIKey string `envconfig:"RADARR_API_KEY"`
RadarrQualityProfile int `envconfig:"RADARR_QUALITY_PROFILE_ID" default:"1"`
RadarrRootFolder string `envconfig:"RADARR_ROOT_FOLDER" default:"/movies"`
CronEnabled bool `envconfig:"CRON_ENABLED" default:"false"`
CronSchedule string `envconfig:"CRON_SCHEDULE" default:"0 3 * * *"`
APIEnabled bool `envconfig:"API_ENABLED" default:"true"`
APIPort int `envconfig:"API_PORT" default:"8080"`
RecommendCount int `envconfig:"RECOMMEND_COUNT" default:"10"`
MinRatedMovies int `envconfig:"MIN_RATED_MOVIES" default:"5"`
}
// Load reads .env (best-effort) then processes environment variables into a Config.
func Load() (*Config, error) {
_ = godotenv.Load()
var cfg Config
if err := envconfig.Process("", &cfg); err != nil {
return nil, err
}
return &cfg, nil
}

View File

@@ -0,0 +1,16 @@
package httputil
import (
"encoding/json"
"net/http"
)
func WriteJSON(w http.ResponseWriter, status int, v any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(v)
}
func WriteError(w http.ResponseWriter, status int, msg string) {
WriteJSON(w, status, map[string]string{"error": msg})
}

View File

@@ -0,0 +1,21 @@
package server
import (
"fmt"
"net/http"
"github.com/fjurmanovic/sugarr/internal/api"
"github.com/fjurmanovic/sugarr/internal/service"
"github.com/fjurmanovic/sugarr/internal/utl/configs"
"github.com/rs/zerolog/log"
)
// Start registers all routes and begins listening. Blocks until the server exits.
func Start(cfg *configs.Config, rec *service.Recommender) error {
mux := http.NewServeMux()
api.Init(mux, cfg, rec)
addr := fmt.Sprintf(":%d", cfg.APIPort)
log.Info().Msgf("HTTP API listening on %s", addr)
return http.ListenAndServe(addr, mux)
}