owl-blogs/web/media_handler.go

25 lines
446 B
Go
Raw Normal View History

2023-06-25 19:32:36 +00:00
package web
import (
"owl-blogs/app"
"github.com/gofiber/fiber/v2"
)
type MediaHandler struct {
2023-07-08 12:32:20 +00:00
binaryService *app.BinaryService
2023-06-25 19:32:36 +00:00
}
2023-07-08 12:32:20 +00:00
func NewMediaHandler(binaryService *app.BinaryService) *MediaHandler {
return &MediaHandler{binaryService: binaryService}
2023-06-25 19:32:36 +00:00
}
func (h *MediaHandler) Handle(c *fiber.Ctx) error {
2023-07-08 12:32:20 +00:00
id := c.Params("id")
binary, err := h.binaryService.FindById(id)
if err != nil {
return err
}
return c.Send(binary.Data)
2023-06-25 19:32:36 +00:00
}