fix: harden handler context and rate limit isolation

This commit is contained in:
Your Name
2026-05-28 20:30:24 +08:00
parent e46567678f
commit caad1aba0c
6 changed files with 311 additions and 37 deletions

View File

@@ -40,8 +40,11 @@ func (h *WebhookHandler) CreateWebhook(c *gin.Context) {
return
}
userID, _ := c.Get("user_id")
creatorID, _ := userID.(int64)
creatorID, ok := getUserIDFromContext(c)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"code": 401, "message": "unauthorized"})
return
}
webhook, err := h.webhookService.CreateWebhook(c.Request.Context(), &req, creatorID)
if err != nil {
@@ -76,8 +79,11 @@ func (h *WebhookHandler) ListWebhooks(c *gin.Context) {
}
offset := (page - 1) * pageSize
userID, _ := c.Get("user_id")
creatorID, _ := userID.(int64)
creatorID, ok := getUserIDFromContext(c)
if !ok {
c.JSON(http.StatusUnauthorized, gin.H{"code": 401, "message": "unauthorized"})
return
}
webhooks, total, err := h.webhookService.ListWebhooksPaginated(c.Request.Context(), creatorID, offset, pageSize)
if err != nil {