mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 00:55:32 +00:00
+Github webhooks
This commit is contained in:
@@ -38,9 +38,11 @@ func GetAgents(kgpz *xmlmodels.Library) fiber.Handler {
|
||||
|
||||
// Build available letters list (same logic as AgentsView)
|
||||
av := make(map[string]bool)
|
||||
kgpz.Agents.Lock()
|
||||
for _, agent := range kgpz.Agents.Array {
|
||||
av[strings.ToUpper(agent.ID[:1])] = true
|
||||
}
|
||||
kgpz.Agents.Unlock()
|
||||
availableLetters := make([]string, 0, len(av))
|
||||
for letter := range av {
|
||||
availableLetters = append(availableLetters, letter)
|
||||
|
||||
@@ -69,6 +69,7 @@ func GetCategory(kgpz *xmlmodels.Library) fiber.Handler {
|
||||
func findFirstYearForCategory(categoryID string, kgpz *xmlmodels.Library) int {
|
||||
categoryYears := make([]int, 0)
|
||||
|
||||
kgpz.Pieces.Lock()
|
||||
for _, piece := range kgpz.Pieces.Array {
|
||||
matchesCategory := false
|
||||
|
||||
@@ -100,6 +101,7 @@ func findFirstYearForCategory(categoryID string, kgpz *xmlmodels.Library) int {
|
||||
}
|
||||
}
|
||||
}
|
||||
kgpz.Pieces.Unlock()
|
||||
|
||||
if len(categoryYears) == 0 {
|
||||
return 0 // No pieces found for this category
|
||||
|
||||
@@ -11,11 +11,10 @@ import (
|
||||
|
||||
const SIGNATURE_PREFIX = "sha256="
|
||||
|
||||
func PostWebhook(secret string) (fiber.Handler, chan bool) {
|
||||
devchan := make(chan bool)
|
||||
func PostWebhook(kgpz WebhookInterface) func(c *fiber.Ctx) error {
|
||||
return func(c *fiber.Ctx) error {
|
||||
body := c.Body()
|
||||
if !verifySignature256([]byte(secret), body, c.Get("X-Hub-Signature-256")) {
|
||||
if !verifySignature256([]byte(kgpz.GetWebHookSecret()), body, c.Get("X-Hub-Signature-256")) {
|
||||
return c.SendStatus(fiber.StatusUnauthorized)
|
||||
}
|
||||
|
||||
@@ -23,13 +22,17 @@ func PostWebhook(secret string) (fiber.Handler, chan bool) {
|
||||
return c.SendStatus(fiber.StatusBadRequest)
|
||||
}
|
||||
|
||||
go func() {
|
||||
devchan <- true
|
||||
}()
|
||||
// Respond with 200 immediately, then process asynchronously
|
||||
go kgpz.Pull()
|
||||
|
||||
c.SendStatus(fiber.StatusOK)
|
||||
return nil
|
||||
}, devchan
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
}
|
||||
|
||||
// KGPZInterface defines the interface needed by the webhook
|
||||
type WebhookInterface interface {
|
||||
GetWebHookSecret() string
|
||||
Pull()
|
||||
}
|
||||
|
||||
func sign256(secret, body []byte) []byte {
|
||||
|
||||
Reference in New Issue
Block a user