95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
package api
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/tradarr/backend/internal/api/handlers"
|
|
"github.com/tradarr/backend/internal/auth"
|
|
)
|
|
|
|
func SetupRouter(h *handlers.Handler, jwtSecret string) *gin.Engine {
|
|
r := gin.New()
|
|
r.Use(gin.Recovery())
|
|
r.Use(gin.LoggerWithConfig(gin.LoggerConfig{
|
|
SkipPaths: []string{"/api/summaries/status"},
|
|
}))
|
|
|
|
r.Use(func(c *gin.Context) {
|
|
c.Header("Access-Control-Allow-Origin", "*")
|
|
c.Header("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS")
|
|
c.Header("Access-Control-Allow-Headers", "Authorization,Content-Type")
|
|
if c.Request.Method == "OPTIONS" {
|
|
c.AbortWithStatus(204)
|
|
return
|
|
}
|
|
c.Next()
|
|
})
|
|
|
|
api := r.Group("/api")
|
|
|
|
// Auth public
|
|
api.POST("/auth/login", h.Login)
|
|
api.POST("/auth/register", h.Register)
|
|
|
|
// Routes authentifiées
|
|
authed := api.Group("/")
|
|
authed.Use(auth.Middleware(jwtSecret))
|
|
|
|
authed.GET("/me", h.GetMe)
|
|
authed.GET("/me/assets", h.GetMyAssets)
|
|
authed.POST("/me/assets", h.AddMyAsset)
|
|
authed.DELETE("/me/assets/:symbol", h.RemoveMyAsset)
|
|
|
|
authed.GET("/articles", h.ListArticles)
|
|
authed.GET("/articles/:id", h.GetArticle)
|
|
|
|
authed.GET("/summaries", h.ListSummaries)
|
|
authed.GET("/summaries/status", h.GetGeneratingStatus)
|
|
authed.POST("/summaries/generate", h.GenerateSummary)
|
|
|
|
authed.GET("/reports", h.ListReports)
|
|
authed.POST("/reports", h.CreateReport)
|
|
authed.DELETE("/reports/:id", h.DeleteReport)
|
|
|
|
// Admin
|
|
admin := authed.Group("/admin")
|
|
admin.Use(auth.AdminOnly())
|
|
|
|
admin.GET("/credentials", h.GetCredentials)
|
|
admin.PUT("/credentials", h.UpsertCredentials)
|
|
|
|
admin.GET("/ai-providers", h.ListAIProviders)
|
|
admin.POST("/ai-providers", h.CreateAIProvider)
|
|
admin.PUT("/ai-providers/:id", h.UpdateAIProvider)
|
|
admin.POST("/ai-providers/:id/activate", h.SetActiveAIProvider)
|
|
admin.DELETE("/ai-providers/:id", h.DeleteAIProvider)
|
|
admin.GET("/ai-providers/:id/models", h.ListAIModels)
|
|
|
|
admin.GET("/sources", h.ListSources)
|
|
admin.PUT("/sources/:id", h.UpdateSource)
|
|
|
|
admin.GET("/scrape-jobs", h.ListScrapeJobs)
|
|
admin.POST("/scrape-jobs/trigger", h.TriggerScrapeJob)
|
|
|
|
admin.GET("/settings", h.ListSettings)
|
|
admin.PUT("/settings", h.UpdateSettings)
|
|
admin.GET("/settings/default-prompt", h.GetDefaultSystemPrompt)
|
|
|
|
admin.GET("/schedule", h.GetSchedule)
|
|
admin.PUT("/schedule", h.UpdateSchedule)
|
|
|
|
admin.GET("/users", h.ListUsers)
|
|
admin.PUT("/users/:id", h.UpdateAdminUser)
|
|
admin.DELETE("/users/:id", h.DeleteAdminUser)
|
|
|
|
// AI roles (per-task model assignment)
|
|
admin.GET("/ai-roles", h.GetAIRoles)
|
|
admin.PUT("/ai-roles/:role", h.UpdateAIRole)
|
|
|
|
// Ollama model management
|
|
admin.GET("/ollama/models", h.ListOllamaModels)
|
|
admin.POST("/ollama/pull", h.PullOllamaModel)
|
|
admin.DELETE("/ollama/models/:name", h.DeleteOllamaModel)
|
|
|
|
return r
|
|
}
|