diff --git a/pkg/gordio/server/calls.go b/pkg/gordio/ingestors/http.go similarity index 93% rename from pkg/gordio/server/calls.go rename to pkg/gordio/ingestors/http.go index 68b0bea..bce8f3c 100644 --- a/pkg/gordio/server/calls.go +++ b/pkg/gordio/ingestors/http.go @@ -1,4 +1,4 @@ -package server +package ingestors import ( "fmt" @@ -11,10 +11,22 @@ import ( "dynatron.me/x/stillbox/internal/common" "dynatron.me/x/stillbox/pkg/gordio/database" + "github.com/go-chi/chi/v5" "github.com/google/uuid" "github.com/rs/zerolog/log" ) +type HTTPIngestor struct { +} + +func NewHTTPIngestor() *HTTPIngestor { + return new(HTTPIngestor) +} + +func (h *HTTPIngestor) InstallRoutes(r chi.Router) { + r.Post("/api/call-upload", h.routeCallUpload) +} + type callUploadRequest struct { Audio []byte `form:"audio"` AudioName string @@ -53,7 +65,7 @@ func (car *callUploadRequest) ToAddCallParams(submitter int) database.AddCallPar } } -func (s *Server) routeCallUpload(w http.ResponseWriter, r *http.Request) { +func (h *HTTPIngestor) routeCallUpload(w http.ResponseWriter, r *http.Request) { err := r.ParseMultipartForm(1024 * 1024 * 2) // 2MB if err != nil { http.Error(w, "cannot parse form "+err.Error(), http.StatusBadRequest) diff --git a/pkg/gordio/server/routes.go b/pkg/gordio/server/routes.go index 1148652..7423ba6 100644 --- a/pkg/gordio/server/routes.go +++ b/pkg/gordio/server/routes.go @@ -27,7 +27,7 @@ func (s *Server) setupRoutes() { r.Use(render.SetContentType(render.ContentTypeJSON)) // public routes r.Post("/auth", s.routeAuth) - r.Post("/api/call-upload", s.routeCallUpload) + s.hi.InstallRoutes(r) }) r.Group(func(r chi.Router) { diff --git a/pkg/gordio/server/server.go b/pkg/gordio/server/server.go index 952914a..91c98c6 100644 --- a/pkg/gordio/server/server.go +++ b/pkg/gordio/server/server.go @@ -5,6 +5,7 @@ import ( "dynatron.me/x/stillbox/pkg/gordio/config" "dynatron.me/x/stillbox/pkg/gordio/database" + "dynatron.me/x/stillbox/pkg/gordio/ingestors" "github.com/go-chi/chi/middleware" "github.com/go-chi/chi/v5" "github.com/go-chi/jwtauth/v5" @@ -15,6 +16,7 @@ type Server struct { db *database.DB r *chi.Mux jwt *jwtauth.JWTAuth + hi *ingestors.HTTPIngestor } func New(cfg *config.Config) (*Server, error) { @@ -29,6 +31,7 @@ func New(cfg *config.Config) (*Server, error) { db: db, r: r, jwt: jwtauth.New("HS256", []byte(cfg.JWTSecret), nil), + hi: ingestors.NewHTTPIngestor(), } r.Use(middleware.RequestID) r.Use(middleware.RealIP)