Move ingestor to own package
This commit is contained in:
parent
f05a717e2f
commit
51bd6d8433
3 changed files with 18 additions and 3 deletions
|
@ -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)
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue