48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
|
package handlers_build
|
||
|
|
||
|
import (
|
||
|
handlers_packages "brunel/handlers/packages"
|
||
|
"fmt"
|
||
|
"os/exec"
|
||
|
|
||
|
"github.com/gofiber/fiber/v2"
|
||
|
)
|
||
|
|
||
|
type FreezeRequest struct {
|
||
|
Name string `json:"name"`
|
||
|
Version string `json:"version"`
|
||
|
}
|
||
|
|
||
|
func TriggerFreeze(c *fiber.Ctx) error {
|
||
|
var req FreezeRequest
|
||
|
if err := c.BodyParser(&req); err != nil {
|
||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||
|
"error": "Invalid request body",
|
||
|
})
|
||
|
}
|
||
|
|
||
|
if req.Name == "" || req.Version == "" {
|
||
|
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
|
||
|
"error": "Name and version are required",
|
||
|
})
|
||
|
}
|
||
|
|
||
|
cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("aptly repo copy pika-canary pika-nest '%s (%s)'", req.Name, req.Version))
|
||
|
|
||
|
output, err := cmd.CombinedOutput()
|
||
|
if err != nil {
|
||
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
||
|
"error": fmt.Sprintf("Command execution failed: %v", err),
|
||
|
"output": string(output),
|
||
|
})
|
||
|
}
|
||
|
|
||
|
// Remove the item from the freeze cache
|
||
|
handlers_packages.RemoveFromFreezeCache(req.Name, req.Version)
|
||
|
|
||
|
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||
|
"message": "Freeze triggered successfully",
|
||
|
"output": string(output),
|
||
|
})
|
||
|
}
|