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
package="generated"
folderPath="handler/generated"
specPath="spec/openapi.yaml"
folderPath="webserver/handlers/generated"
specPath="openapi.yaml"
# validate scripts are installed
if ! command -v swagger-cli &> /dev/null
then
if ! command -v swagger-cli &>/dev/null; then
echo "Please install \`swagger-cli\` before running this script"
exit 1
fi
if ! command -v oapi-codegen &> /dev/null
then
if ! command -v oapi-codegen &>/dev/null; then
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
fi
# validate schema
swagger-cli validate $specPath
if [ $? -ne 0 ];
then
if [ $? -ne 0 ]; then
echo "Open API specification is not valid"
exit 1
fi

View file

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

View file

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

View file

@ -6,7 +6,7 @@ import (
ia "github.com/owncast/owncast/auth/indieauth"
"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.

View file

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

View file

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

View file

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

View file

@ -8,7 +8,7 @@ import (
"github.com/owncast/owncast/config"
"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.

View file

@ -11,8 +11,8 @@ import (
"github.com/owncast/owncast/core"
"github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/models"
"github.com/owncast/owncast/router/middleware"
"github.com/owncast/owncast/utils"
"github.com/owncast/owncast/webserver/router/middleware"
)
// 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/data"
"github.com/owncast/owncast/models"
"github.com/owncast/owncast/router/middleware"
"github.com/owncast/owncast/static"
"github.com/owncast/owncast/utils"
"github.com/owncast/owncast/webserver/router/middleware"
log "github.com/sirupsen/logrus"
)

View file

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

View file

@ -12,8 +12,8 @@ import (
"github.com/owncast/owncast/core"
"github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/metrics"
"github.com/owncast/owncast/router"
"github.com/owncast/owncast/utils"
"github.com/owncast/owncast/webserver/router"
)
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 (
"net/http"
"github.com/owncast/owncast/controllers"
"github.com/owncast/owncast/controllers/admin"
"github.com/owncast/owncast/handler/generated"
"github.com/owncast/owncast/router/middleware"
"github.com/owncast/owncast/webserver/handlers/generated"
"github.com/owncast/owncast/webserver/router/middleware"
)
func (*ServerInterfaceImpl) StatusAdmin(w http.ResponseWriter, r *http.Request) {

View file

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

View file

@ -1,10 +1,10 @@
package handler
package handlers
import (
"net/http"
"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) {

View file

@ -1,6 +1,6 @@
// 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
import (

View file

@ -1,6 +1,6 @@
// 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
import (
@ -4593,7 +4593,6 @@ func (siw *ServerInterfaceWrapper) RegisterFediverseOTPRequest(w http.ResponseWr
// ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return
@ -4643,7 +4642,6 @@ func (siw *ServerInterfaceWrapper) StartIndieAuthFlow(w http.ResponseWriter, r *
// ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return
@ -4678,7 +4676,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthRedirect(w http.ResponseWriter
// ------------- Required query parameter "state" -------------
if paramValue := r.URL.Query().Get("state"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "state"})
return
@ -4693,7 +4690,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthRedirect(w http.ResponseWriter
// ------------- Required query parameter "code" -------------
if paramValue := r.URL.Query().Get("code"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "code"})
return
@ -4730,7 +4726,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthEndpointGet(w http.ResponseWri
// ------------- Required query parameter "client_id" -------------
if paramValue := r.URL.Query().Get("client_id"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "client_id"})
return
@ -4745,7 +4740,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthEndpointGet(w http.ResponseWri
// ------------- Required query parameter "redirect_uri" -------------
if paramValue := r.URL.Query().Get("redirect_uri"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "redirect_uri"})
return
@ -4760,7 +4754,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthEndpointGet(w http.ResponseWri
// ------------- Required query parameter "code_challenge" -------------
if paramValue := r.URL.Query().Get("code_challenge"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "code_challenge"})
return
@ -4775,7 +4768,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthEndpointGet(w http.ResponseWri
// ------------- Required query parameter "state" -------------
if paramValue := r.URL.Query().Get("state"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "state"})
return
@ -4790,7 +4782,6 @@ func (siw *ServerInterfaceWrapper) HandleIndieAuthEndpointGet(w http.ResponseWri
// ------------- Required query parameter "code" -------------
if paramValue := r.URL.Query().Get("code"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "code"})
return
@ -4840,7 +4831,6 @@ func (siw *ServerInterfaceWrapper) GetChatMessages(w http.ResponseWriter, r *htt
// ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return
@ -4875,7 +4865,6 @@ func (siw *ServerInterfaceWrapper) UpdateMessageVisibility(w http.ResponseWriter
// ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return
@ -4966,7 +4955,6 @@ func (siw *ServerInterfaceWrapper) UpdateUserEnabled(w http.ResponseWriter, r *h
// ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return
@ -5401,7 +5389,6 @@ func (siw *ServerInterfaceWrapper) GetUserDetails(w http.ResponseWriter, r *http
// ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return
@ -5436,7 +5423,6 @@ func (siw *ServerInterfaceWrapper) RegisterForLiveNotifications(w http.ResponseW
// ------------- Required query parameter "accessToken" -------------
if paramValue := r.URL.Query().Get("accessToken"); paramValue != "" {
} else {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "accessToken"})
return

View file

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

View file

@ -1,4 +1,4 @@
package handler
package handlers
import (
"net/http"
@ -6,7 +6,7 @@ import (
"github.com/owncast/owncast/controllers"
"github.com/owncast/owncast/controllers/admin"
"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"
)

View file

@ -1,11 +1,11 @@
package handler
package handlers
import (
"net/http"
"github.com/owncast/owncast/controllers/moderation"
"github.com/owncast/owncast/handler/generated"
"github.com/owncast/owncast/router/middleware"
"github.com/owncast/owncast/webserver/handlers/generated"
"github.com/owncast/owncast/webserver/router/middleware"
)
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/core/chat"
"github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/handler"
"github.com/owncast/owncast/router/middleware"
"github.com/owncast/owncast/webserver/handlers"
"github.com/owncast/owncast/webserver/router/middleware"
)
// Start starts the router for the http, ws, and rtmp.
@ -59,7 +59,7 @@ func Start(enableVerboseLogging bool) error {
r.HandleFunc("/*", controllers.IndexHandler)
// mount the api
r.Mount("/api/", handler.New().Handler())
r.Mount("/api/", handlers.New().Handler())
// ActivityPub has its own router
activitypub.Start(data.GetDatastore())