Remove all of the remaining API logic and port it all to the remote.Client type
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/remote"
|
||||
"github.com/pterodactyl/wings/server"
|
||||
"github.com/pterodactyl/wings/server/filesystem"
|
||||
)
|
||||
@@ -168,6 +169,15 @@ func AttachServerManager(m *server.Manager) gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// AttachApiClient attaches the application API client which allows routes to
|
||||
// access server resources from the Panel easily.
|
||||
func AttachApiClient(client remote.Client) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Set("api_client", client)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// CaptureAndAbort aborts the request and attaches the provided error to the gin
|
||||
// context so it can be reported properly. If the error is missing a stacktrace
|
||||
// at the time it is called the stack will be attached.
|
||||
@@ -327,6 +337,14 @@ func ExtractServer(c *gin.Context) *server.Server {
|
||||
return v.(*server.Server)
|
||||
}
|
||||
|
||||
// ExtractApiClient returns the API client defined for the routes.
|
||||
func ExtractApiClient(c *gin.Context) remote.Client {
|
||||
if v, ok := c.Get("api_client"); ok {
|
||||
return v.(remote.Client)
|
||||
}
|
||||
panic("middleware/middlware: cannot extract api clinet: not present in context")
|
||||
}
|
||||
|
||||
// ExtractManager returns the server manager instance set on the request context.
|
||||
func ExtractManager(c *gin.Context) *server.Manager {
|
||||
if v, ok := c.Get("manager"); ok {
|
||||
|
||||
Reference in New Issue
Block a user