mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 07:41:08 +00:00
trigger endpoint and retry suggestions
This commit is contained in:
@@ -21,6 +21,7 @@ func NewRecommendationsController(mux *http.ServeMux, cfg *configs.Config, rec *
|
||||
c := &RecommendationsController{cfg: cfg, rec: rec}
|
||||
mux.HandleFunc("GET /recommendations", c.handleList)
|
||||
mux.HandleFunc("POST /recommendations/search", c.handleSearch)
|
||||
mux.HandleFunc("POST /recommendations/trigger", c.handleTrigger)
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -53,6 +54,21 @@ func (c *RecommendationsController) handleList(w http.ResponseWriter, r *http.Re
|
||||
httputil.WriteJSON(w, http.StatusOK, recs)
|
||||
}
|
||||
|
||||
// handleTrigger runs the same pipeline as the cron job: recommend + auto-request if Radarr is enabled.
|
||||
func (c *RecommendationsController) handleTrigger(w http.ResponseWriter, r *http.Request) {
|
||||
log.Info().Msg("Trigger: running recommendation pipeline")
|
||||
recs, err := c.rec.Run()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Trigger: pipeline failed")
|
||||
httputil.WriteError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
if c.cfg.RadarrEnabled {
|
||||
c.rec.AutoRequest(recs)
|
||||
}
|
||||
httputil.WriteJSON(w, http.StatusOK, recs)
|
||||
}
|
||||
|
||||
// handleSearch performs a natural-language LLM search and resolves results via TMDb.
|
||||
// Body: {"query": "sci-fi movies like Blade Runner but more recent"}
|
||||
func (c *RecommendationsController) handleSearch(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user