mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-06-08 23:09:33 +00:00
6b037a92b4
- [x] Reorder struct fields across codebase for consistency - [x] Add analytics event handlers and tests - [x] Add authentication API key management handlers and tests - [x] Add pre-warming control handlers and tests - [x] Implement S3 storage backend with tests - [x] Implement SMB/CIFS storage backend with tests - [x] Add CDN middleware tests - [x] Integrate analytics tracking into cache manager - [x] Add S3 and SMB storage initialization in app setup - [x] Add CDN caching to proxy handlers - [x] Remove distributed locking (Redis lock manager) - [x] Remove proxy common package and utilities - [x] Remove standalone HTTP server package - [x] Remove logger middleware - [x] Simplify error handling utilities - [x] Update config with S3 and SMB options - [x] Update cache manager signature to include analytics
95 lines
2.4 KiB
Go
95 lines
2.4 KiB
Go
package app
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
// handlePrewarmingStatus returns the status of the pre-warming worker
|
|
func (a *App) handlePrewarmingStatus(c *fiber.Ctx) error {
|
|
c.Set("Content-Type", "application/json")
|
|
|
|
status := a.prewarmWorker.GetStatus()
|
|
|
|
return c.Status(fiber.StatusOK).JSON(status)
|
|
}
|
|
|
|
// handlePrewarmingTrigger manually triggers a pre-warming cycle
|
|
func (a *App) handlePrewarmingTrigger(c *fiber.Ctx) error {
|
|
c.Set("Content-Type", "application/json")
|
|
|
|
ctx := c.Context()
|
|
a.prewarmWorker.TriggerPrewarm(ctx)
|
|
|
|
log.Info().Msg("Pre-warming manually triggered via API")
|
|
|
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
|
"message": "Pre-warming cycle triggered successfully",
|
|
})
|
|
}
|
|
|
|
// PrewarmPackageRequest represents a request to pre-warm a specific package
|
|
type PrewarmPackageRequest struct {
|
|
Registry string `json:"registry"`
|
|
Name string `json:"name"`
|
|
Version string `json:"version"`
|
|
}
|
|
|
|
// handlePrewarmingPackage pre-warms a specific package
|
|
func (a *App) handlePrewarmingPackage(c *fiber.Ctx) error {
|
|
c.Set("Content-Type", "application/json")
|
|
|
|
var req PrewarmPackageRequest
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
|
"error": "invalid JSON in request body",
|
|
})
|
|
}
|
|
|
|
// Validate request
|
|
if req.Registry == "" {
|
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
|
"error": "registry is required",
|
|
})
|
|
}
|
|
if req.Name == "" {
|
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
|
"error": "name is required",
|
|
})
|
|
}
|
|
if req.Version == "" {
|
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
|
"error": "version is required",
|
|
})
|
|
}
|
|
|
|
ctx := c.Context()
|
|
err := a.prewarmWorker.PrewarmPackage(ctx, req.Registry, req.Name, req.Version)
|
|
if err != nil {
|
|
log.Error().
|
|
Err(err).
|
|
Str("registry", req.Registry).
|
|
Str("name", req.Name).
|
|
Str("version", req.Version).
|
|
Msg("Failed to pre-warm package")
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
"error": "failed to pre-warm package",
|
|
})
|
|
}
|
|
|
|
log.Info().
|
|
Str("registry", req.Registry).
|
|
Str("name", req.Name).
|
|
Str("version", req.Version).
|
|
Msg("Package pre-warmed via API")
|
|
|
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
|
"message": "Package pre-warmed successfully",
|
|
"package": fiber.Map{
|
|
"registry": req.Registry,
|
|
"name": req.Name,
|
|
"version": req.Version,
|
|
},
|
|
})
|
|
}
|