fixed api stuff
This commit is contained in:
@@ -2,10 +2,12 @@ package servers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"acooldomain.co/backend/auth"
|
||||
"acooldomain.co/backend/models"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/image"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -13,9 +15,10 @@ import (
|
||||
)
|
||||
|
||||
type ImageData struct {
|
||||
Id string
|
||||
Name string
|
||||
Version string
|
||||
Id string
|
||||
Name string
|
||||
Version string
|
||||
DisplayName string
|
||||
}
|
||||
|
||||
func convertImageToImageData(imageSummary image.Summary) ImageData {
|
||||
@@ -23,13 +26,14 @@ func convertImageToImageData(imageSummary image.Summary) ImageData {
|
||||
splitImageId := strings.Split(imageId, ":")
|
||||
imageName, imageVersion := splitImageId[0], splitImageId[1]
|
||||
return ImageData{
|
||||
Id: imageId,
|
||||
Name: imageName,
|
||||
Version: imageVersion,
|
||||
Id: imageId,
|
||||
Name: imageName,
|
||||
Version: imageVersion,
|
||||
DisplayName: fmt.Sprintf("%s %s", imageName, imageVersion),
|
||||
}
|
||||
}
|
||||
func (con Connection) GetImages(c *gin.Context) {
|
||||
images, err := con.dockerClient.ImageList(context.TODO(), image.ListOptions{Filters: filters.NewArgs(filters.NewArg("label", "type=GAME"))})
|
||||
images, err := con.dockerClient.ImageList(context.TODO(), image.ListOptions{Filters: filters.NewArgs(filters.Arg("label", "type=GAME"))})
|
||||
if err != nil {
|
||||
c.AbortWithError(500, err)
|
||||
return
|
||||
@@ -50,5 +54,5 @@ func LoadeImagesGroup(group *gin.RouterGroup, mongo_client *mongo.Client, config
|
||||
defer apiClient.Close()
|
||||
|
||||
connection := Connection{databaseConnection: mongo_client, dockerClient: apiClient}
|
||||
group.GET("/", auth.AuthorizedTo(0), connection.GetBrowsers)
|
||||
group.GET("/", auth.AuthorizedTo(0), connection.GetImages)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user