chore(api): reorganize web assets and codegen types+handlers

This commit is contained in:
Gabe Kangas 2024-07-01 20:12:08 -07:00
parent 2ccd3aad87
commit 5cb4850fce
29 changed files with 4352 additions and 6710 deletions

View file

@ -4,27 +4,24 @@
# setup # setup
package="generated" package="generated"
folderPath="handler/generated" folderPath="webserver/handlers/generated"
specPath="spec/openapi.yaml" specPath="openapi.yaml"
# validate scripts are installed # validate scripts are installed
if ! command -v swagger-cli &> /dev/null if ! command -v swagger-cli &>/dev/null; then
then
echo "Please install \`swagger-cli\` before running this script" echo "Please install \`swagger-cli\` before running this script"
exit 1 exit 1
fi fi
if ! command -v oapi-codegen &> /dev/null if ! command -v oapi-codegen &>/dev/null; then
then
echo "Please install \`oapi-codegen\` before running this script" echo "Please install \`oapi-codegen\` before running this script"
echo "Hint: run \`go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@latest\` to install" echo "Hint: run \`go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest\` to install"
exit 1 exit 1
fi fi
# validate schema # validate schema
swagger-cli validate $specPath swagger-cli validate $specPath
if [ $? -ne 0 ]; if [ $? -ne 0 ]; then
then
echo "Open API specification is not valid" echo "Open API specification is not valid"
exit 1 exit 1
fi fi

View file

@ -8,8 +8,8 @@ import (
"github.com/owncast/owncast/core/data" "github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/core/transcoder" "github.com/owncast/owncast/core/transcoder"
"github.com/owncast/owncast/models" "github.com/owncast/owncast/models"
"github.com/owncast/owncast/router/middleware"
"github.com/owncast/owncast/utils" "github.com/owncast/owncast/utils"
"github.com/owncast/owncast/webserver/router/middleware"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )

View file

@ -8,7 +8,7 @@ import (
"github.com/owncast/owncast/core/data" "github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/metrics" "github.com/owncast/owncast/metrics"
"github.com/owncast/owncast/models" "github.com/owncast/owncast/models"
"github.com/owncast/owncast/router/middleware" "github.com/owncast/owncast/webserver/router/middleware"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )

View file

@ -6,7 +6,7 @@ import (
ia "github.com/owncast/owncast/auth/indieauth" ia "github.com/owncast/owncast/auth/indieauth"
"github.com/owncast/owncast/controllers" "github.com/owncast/owncast/controllers"
"github.com/owncast/owncast/router/middleware" "github.com/owncast/owncast/webserver/router/middleware"
) )
// HandleAuthEndpoint will handle the IndieAuth auth endpoint. // HandleAuthEndpoint will handle the IndieAuth auth endpoint.

View file

@ -9,8 +9,8 @@ import (
"github.com/owncast/owncast/core/data" "github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/models" "github.com/owncast/owncast/models"
"github.com/owncast/owncast/persistence/userrepository" "github.com/owncast/owncast/persistence/userrepository"
"github.com/owncast/owncast/router/middleware"
"github.com/owncast/owncast/utils" "github.com/owncast/owncast/utils"
"github.com/owncast/owncast/webserver/router/middleware"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )

View file

@ -10,8 +10,8 @@ import (
"github.com/owncast/owncast/config" "github.com/owncast/owncast/config"
"github.com/owncast/owncast/core/data" "github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/models" "github.com/owncast/owncast/models"
"github.com/owncast/owncast/router/middleware"
"github.com/owncast/owncast/utils" "github.com/owncast/owncast/utils"
"github.com/owncast/owncast/webserver/router/middleware"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )

View file

@ -5,7 +5,7 @@ import (
"net/http" "net/http"
"github.com/owncast/owncast/models" "github.com/owncast/owncast/models"
"github.com/owncast/owncast/router/middleware" "github.com/owncast/owncast/webserver/router/middleware"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )

View file

@ -8,7 +8,7 @@ import (
"github.com/owncast/owncast/config" "github.com/owncast/owncast/config"
"github.com/owncast/owncast/core/data" "github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/router/middleware" "github.com/owncast/owncast/webserver/router/middleware"
) )
// GetCustomEmojiList returns a list of emoji via the API. // GetCustomEmojiList returns a list of emoji via the API.

View file

@ -11,8 +11,8 @@ import (
"github.com/owncast/owncast/core" "github.com/owncast/owncast/core"
"github.com/owncast/owncast/core/data" "github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/models" "github.com/owncast/owncast/models"
"github.com/owncast/owncast/router/middleware"
"github.com/owncast/owncast/utils" "github.com/owncast/owncast/utils"
"github.com/owncast/owncast/webserver/router/middleware"
) )
// HandleHLSRequest will manage all requests to HLS content. // HandleHLSRequest will manage all requests to HLS content.

View file

@ -15,9 +15,9 @@ import (
"github.com/owncast/owncast/core/cache" "github.com/owncast/owncast/core/cache"
"github.com/owncast/owncast/core/data" "github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/models" "github.com/owncast/owncast/models"
"github.com/owncast/owncast/router/middleware"
"github.com/owncast/owncast/static" "github.com/owncast/owncast/static"
"github.com/owncast/owncast/utils" "github.com/owncast/owncast/utils"
"github.com/owncast/owncast/webserver/router/middleware"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )

View file

@ -7,8 +7,8 @@ import (
"github.com/owncast/owncast/core" "github.com/owncast/owncast/core"
"github.com/owncast/owncast/core/data" "github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/router/middleware"
"github.com/owncast/owncast/utils" "github.com/owncast/owncast/utils"
"github.com/owncast/owncast/webserver/router/middleware"
) )
// GetStatus gets the status of the server. // GetStatus gets the status of the server.

View file

@ -12,8 +12,8 @@ import (
"github.com/owncast/owncast/core" "github.com/owncast/owncast/core"
"github.com/owncast/owncast/core/data" "github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/metrics" "github.com/owncast/owncast/metrics"
"github.com/owncast/owncast/router"
"github.com/owncast/owncast/utils" "github.com/owncast/owncast/utils"
"github.com/owncast/owncast/webserver/router"
) )
var ( var (

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,12 @@
package handler package handlers
import ( import (
"net/http" "net/http"
"github.com/owncast/owncast/controllers" "github.com/owncast/owncast/controllers"
"github.com/owncast/owncast/controllers/admin" "github.com/owncast/owncast/controllers/admin"
"github.com/owncast/owncast/handler/generated" "github.com/owncast/owncast/webserver/handlers/generated"
"github.com/owncast/owncast/router/middleware" "github.com/owncast/owncast/webserver/router/middleware"
) )
func (*ServerInterfaceImpl) StatusAdmin(w http.ResponseWriter, r *http.Request) { func (*ServerInterfaceImpl) StatusAdmin(w http.ResponseWriter, r *http.Request) {

View file

@ -1,12 +1,12 @@
package handler package handlers
import ( import (
"net/http" "net/http"
"github.com/owncast/owncast/controllers/auth/fediverse" "github.com/owncast/owncast/controllers/auth/fediverse"
"github.com/owncast/owncast/controllers/auth/indieauth" "github.com/owncast/owncast/controllers/auth/indieauth"
"github.com/owncast/owncast/handler/generated" "github.com/owncast/owncast/webserver/handlers/generated"
"github.com/owncast/owncast/router/middleware" "github.com/owncast/owncast/webserver/router/middleware"
) )
func (*ServerInterfaceImpl) StartIndieAuthFlow(w http.ResponseWriter, r *http.Request, params generated.StartIndieAuthFlowParams) { func (*ServerInterfaceImpl) StartIndieAuthFlow(w http.ResponseWriter, r *http.Request, params generated.StartIndieAuthFlowParams) {

View file

@ -1,10 +1,10 @@
package handler package handlers
import ( import (
"net/http" "net/http"
"github.com/owncast/owncast/controllers/admin" "github.com/owncast/owncast/controllers/admin"
"github.com/owncast/owncast/router/middleware" "github.com/owncast/owncast/webserver/router/middleware"
) )
func (*ServerInterfaceImpl) SetAdminPassword(w http.ResponseWriter, r *http.Request) { func (*ServerInterfaceImpl) SetAdminPassword(w http.ResponseWriter, r *http.Request) {

View file

@ -1,6 +1,6 @@
// Package generated provides primitives to interact with the openapi HTTP API. // Package generated provides primitives to interact with the openapi HTTP API.
// //
// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.1.0 DO NOT EDIT. // Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.3.0 DO NOT EDIT.
package generated package generated
import ( import (

View file

@ -1,6 +1,6 @@
// Package generated provides primitives to interact with the openapi HTTP API. // Package generated provides primitives to interact with the openapi HTTP API.
// //
// Code generated by github.com/deepmap/oapi-codegen/v2 version v2.1.0 DO NOT EDIT. // Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.3.0 DO NOT EDIT.
package generated package generated
import ( import (
@ -4593,7 +4593,6 @@ func (siw *ServerInterfaceWrapper) RegisterFediverseOTPRequest(w http.ResponseWr
// ------------- Required query parameter "accessToken" ------------- // ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" { if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return return
@ -4643,7 +4642,6 @@ func (siw *ServerInterfaceWrapper) StartIndieAuthFlow(w http.ResponseWriter, r *
// ------------- Required query parameter "accessToken" ------------- // ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" { if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return return
@ -4678,7 +4676,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthRedirect(w http.ResponseWriter
// ------------- Required query parameter "state" ------------- // ------------- Required query parameter "state" -------------
if paramValue := r.URL.Query().Get("state"); paramValue != "" { if paramValue := r.URL.Query().Get("state"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "state"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "state"})
return return
@ -4693,7 +4690,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthRedirect(w http.ResponseWriter
// ------------- Required query parameter "code" ------------- // ------------- Required query parameter "code" -------------
if paramValue := r.URL.Query().Get("code"); paramValue != "" { if paramValue := r.URL.Query().Get("code"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "code"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "code"})
return return
@ -4730,7 +4726,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthEndpointGet(w http.ResponseWri
// ------------- Required query parameter "client_id" ------------- // ------------- Required query parameter "client_id" -------------
if paramValue := r.URL.Query().Get("client_id"); paramValue != "" { if paramValue := r.URL.Query().Get("client_id"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "client_id"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "client_id"})
return return
@ -4745,7 +4740,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthEndpointGet(w http.ResponseWri
// ------------- Required query parameter "redirect_uri" ------------- // ------------- Required query parameter "redirect_uri" -------------
if paramValue := r.URL.Query().Get("redirect_uri"); paramValue != "" { if paramValue := r.URL.Query().Get("redirect_uri"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "redirect_uri"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "redirect_uri"})
return return
@ -4760,7 +4754,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthEndpointGet(w http.ResponseWri
// ------------- Required query parameter "code_challenge" ------------- // ------------- Required query parameter "code_challenge" -------------
if paramValue := r.URL.Query().Get("code_challenge"); paramValue != "" { if paramValue := r.URL.Query().Get("code_challenge"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "code_challenge"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "code_challenge"})
return return
@ -4775,7 +4768,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthEndpointGet(w http.ResponseWri
// ------------- Required query parameter "state" ------------- // ------------- Required query parameter "state" -------------
if paramValue := r.URL.Query().Get("state"); paramValue != "" { if paramValue := r.URL.Query().Get("state"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "state"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "state"})
return return
@ -4790,7 +4782,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthEndpointGet(w http.ResponseWri
// ------------- Required query parameter "code" ------------- // ------------- Required query parameter "code" -------------
if paramValue := r.URL.Query().Get("code"); paramValue != "" { if paramValue := r.URL.Query().Get("code"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "code"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "code"})
return return
@ -4840,7 +4831,6 @@ func (siw *ServerInterfaceWrapper) GetChatMessages(w http.ResponseWriter, r *htt
// ------------- Required query parameter "accessToken" ------------- // ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" { if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return return
@ -4875,7 +4865,6 @@ func (siw *ServerInterfaceWrapper) UpdateMessageVisibility(w http.ResponseWriter
// ------------- Required query parameter "accessToken" ------------- // ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" { if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return return
@ -4966,7 +4955,6 @@ func (siw *ServerInterfaceWrapper) UpdateUserEnabled(w http.ResponseWriter, r *h
// ------------- Required query parameter "accessToken" ------------- // ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" { if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return return
@ -5401,7 +5389,6 @@ func (siw *ServerInterfaceWrapper) GetUserDetails(w http.ResponseWriter, r *http
// ------------- Required query parameter "accessToken" ------------- // ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" { if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return return
@ -5436,7 +5423,6 @@ func (siw *ServerInterfaceWrapper) RegisterForLiveNotifications(w http.ResponseW
// ------------- Required query parameter "accessToken" ------------- // ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" { if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else { } else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"}) siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return return

View file

@ -1,12 +1,13 @@
package handler package handlers
import ( import (
"net/http" "net/http"
"github.com/owncast/owncast/controllers" "github.com/owncast/owncast/controllers"
"github.com/owncast/owncast/controllers/admin" "github.com/owncast/owncast/controllers/admin"
"github.com/owncast/owncast/handler/generated" "github.com/owncast/owncast/webserver/handlers/generated"
"github.com/owncast/owncast/router/middleware" "github.com/owncast/owncast/webserver/router/middleware"
"github.com/owncast/owncast/yp" "github.com/owncast/owncast/yp"
) )

View file

@ -1,4 +1,4 @@
package handler package handlers
import ( import (
"net/http" "net/http"
@ -6,7 +6,7 @@ import (
"github.com/owncast/owncast/controllers" "github.com/owncast/owncast/controllers"
"github.com/owncast/owncast/controllers/admin" "github.com/owncast/owncast/controllers/admin"
"github.com/owncast/owncast/models" "github.com/owncast/owncast/models"
"github.com/owncast/owncast/router/middleware" "github.com/owncast/owncast/webserver/router/middleware"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
) )

View file

@ -1,11 +1,11 @@
package handler package handlers
import ( import (
"net/http" "net/http"
"github.com/owncast/owncast/controllers/moderation" "github.com/owncast/owncast/controllers/moderation"
"github.com/owncast/owncast/handler/generated" "github.com/owncast/owncast/webserver/handlers/generated"
"github.com/owncast/owncast/router/middleware" "github.com/owncast/owncast/webserver/router/middleware"
) )
func (*ServerInterfaceImpl) GetUserDetails(w http.ResponseWriter, r *http.Request, userId string, params generated.GetUserDetailsParams) { func (*ServerInterfaceImpl) GetUserDetails(w http.ResponseWriter, r *http.Request, userId string, params generated.GetUserDetailsParams) {

View file

@ -19,8 +19,8 @@ import (
"github.com/owncast/owncast/controllers" "github.com/owncast/owncast/controllers"
"github.com/owncast/owncast/core/chat" "github.com/owncast/owncast/core/chat"
"github.com/owncast/owncast/core/data" "github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/handler" "github.com/owncast/owncast/webserver/handlers"
"github.com/owncast/owncast/router/middleware" "github.com/owncast/owncast/webserver/router/middleware"
) )
// Start starts the router for the http, ws, and rtmp. // Start starts the router for the http, ws, and rtmp.
@ -59,7 +59,7 @@ func Start(enableVerboseLogging bool) error {
r.HandleFunc("/*", controllers.IndexHandler) r.HandleFunc("/*", controllers.IndexHandler)
// mount the api // mount the api
r.Mount("/api/", handler.New().Handler()) r.Mount("/api/", handlers.New().Handler())
// ActivityPub has its own router // ActivityPub has its own router
activitypub.Start(data.GetDatastore()) activitypub.Start(data.GetDatastore())