| package api |
| |
| import ( |
| "fmt" |
| "net/http" |
| |
| "github.com/gin-gonic/gin" |
| ) |
| |
| func (apiObj *API) initProposal() { |
| apiObj.Proposal = apiObj.APIRoot.Group("/proposal") |
| apiObj.Proposal.POST("/approve", proposalApprovalHandler) |
| } |
| |
| func proposalApprovalHandler(c *gin.Context) { |
| app, err := getApp(c) |
| if err != nil { |
| responseFormat(c, http.StatusInternalServerError, err.Error()) |
| return |
| } |
| |
| // Read the raw body for signature validation |
| body, err := c.GetRawData() |
| if err != nil { |
| responseFormat(c, http.StatusBadRequest, "Failed to read request body") |
| return |
| } |
| |
| // Get the signature from headers |
| signature := c.GetHeader("X-Hub-Signature-256") |
| if signature == "" { |
| // Fallback to the older signature header |
| signature = c.GetHeader("X-Hub-Signature") |
| } |
| |
| err = app.ProposalApproval(body, signature) |
| if err != nil { |
| responseFormat(c, http.StatusBadRequest, fmt.Sprintf("Failed to process webhook: %v", err)) |
| return |
| } |
| |
| responseFormat(c, http.StatusOK, "Proposal approved successfully") |
| } |