Skip to content

Commit 738740f

Browse files
committed
fix: refactor parameter handling in OutputsHandler; add URL decoding for output IDs in Delete and Start methods
1 parent a787f98 commit 738740f

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

internal/api/handler_outputs.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package api
22

33
import (
44
"log"
5+
"net/url"
56
"sort"
67
"sync"
78
"time"
@@ -91,8 +92,16 @@ func boolStr(v bool) string {
9192
return "no"
9293
}
9394

94-
func (h *OutputsHandler) Delete(c *fiber.Ctx) error {
95+
func (h *OutputsHandler) paramID(c *fiber.Ctx) string {
9596
id := c.Params("id")
97+
if decoded, err := url.PathUnescape(id); err == nil {
98+
return decoded
99+
}
100+
return id
101+
}
102+
103+
func (h *OutputsHandler) Delete(c *fiber.Ctx) error {
104+
id := h.paramID(c)
96105
h.controller.RemoveOutput(id)
97106
h.mu.Lock()
98107
delete(h.outputs, id)
@@ -103,7 +112,7 @@ func (h *OutputsHandler) Delete(c *fiber.Ctx) error {
103112
}
104113

105114
func (h *OutputsHandler) Start(c *fiber.Ctx) error {
106-
id := c.Params("id")
115+
id := h.paramID(c)
107116
var req StartOutputReq
108117
if err := c.BodyParser(&req); err != nil {
109118
log.Printf("[api] Output %s body parse warning: %v", id, err)
@@ -143,7 +152,7 @@ func (h *OutputsHandler) Start(c *fiber.Ctx) error {
143152
}
144153

145154
func (h *OutputsHandler) Stop(c *fiber.Ctx) error {
146-
id := c.Params("id")
155+
id := h.paramID(c)
147156
h.controller.RemoveOutput(id)
148157
log.Printf("[api] Output stopped: %s", id)
149158
return c.JSON(APIResponse{Ok: true})

0 commit comments

Comments
 (0)