fixed api stuff
This commit is contained in:
@@ -220,6 +220,7 @@ func (con Connection) CreateServer(ctx *gin.Context) {
|
||||
VolumeId: volumeResponse.Name,
|
||||
DefaultPorts: request.DefaultPorts,
|
||||
DefaultCommand: request.DefaultCommand,
|
||||
Nickname: request.Nickname,
|
||||
})
|
||||
|
||||
ctx.JSON(200, volumeResponse.Name)
|
||||
@@ -297,8 +298,12 @@ func (con Connection) StartServer(ctx *gin.Context) {
|
||||
portMapping[nat.Port(fmt.Sprintf("%d/%s", portCouple.Source.Number, portCouple.Source.Protocol))] = []nat.PortBinding{{HostIP: "0.0.0.0", HostPort: fmt.Sprint(portCouple.Destination.Number)}}
|
||||
}
|
||||
}
|
||||
command := request.Command
|
||||
if command == "" {
|
||||
command = serverInfo.DefaultCommand
|
||||
}
|
||||
|
||||
words, err := shellwords.Split(request.Command)
|
||||
words, err := shellwords.Split(command)
|
||||
if err != nil {
|
||||
ctx.AbortWithError(500, err)
|
||||
return
|
||||
@@ -391,7 +396,7 @@ func (con Connection) GetServers(ctx *gin.Context) {
|
||||
if err != nil {
|
||||
ctx.AbortWithError(500, err)
|
||||
}
|
||||
var servers []models.ServerInfo
|
||||
var servers []models.ServerInfo = make([]models.ServerInfo, 0, len(volumes.Volumes))
|
||||
for _, volume := range volumes.Volumes {
|
||||
serverInfo, err := con.getServerInfo(*volume)
|
||||
if err != nil {
|
||||
@@ -435,8 +440,7 @@ func (con Connection) DeleteServer(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
for _, containerInstance := range containers {
|
||||
con.dockerClient.ContainerStop(context.TODO(), containerInstance.ID, container.StopOptions{})
|
||||
err := con.dockerClient.ContainerRemove(context.TODO(), containerInstance.ID, container.RemoveOptions{Force: true, RemoveLinks: true})
|
||||
err := con.dockerClient.ContainerRemove(context.TODO(), containerInstance.ID, container.RemoveOptions{Force: true})
|
||||
if err != nil {
|
||||
ctx.AbortWithError(500, err)
|
||||
return
|
||||
@@ -462,7 +466,7 @@ func (con Connection) RunCommand(ctx *gin.Context) {
|
||||
|
||||
serverId := ctx.Param("server_id")
|
||||
log.Print("Writing command \"", request.Command, "\"")
|
||||
containers, err := con.dockerClient.ContainerList(context.TODO(), container.ListOptions{Filters: filters.NewArgs(filters.Arg("label", "volume_id="+serverId))})
|
||||
containers, err := con.dockerClient.ContainerList(context.TODO(), container.ListOptions{Filters: filters.NewArgs(filters.Arg("label", "volume_id="+serverId), filters.Arg("label", "type=GAME"))})
|
||||
if err != nil {
|
||||
ctx.AbortWithError(500, err)
|
||||
return
|
||||
@@ -470,11 +474,11 @@ func (con Connection) RunCommand(ctx *gin.Context) {
|
||||
|
||||
for _, containerData := range containers {
|
||||
hijacked, err := con.dockerClient.ContainerAttach(context.TODO(), containerData.ID, container.AttachOptions{Stream: true, Stdin: true})
|
||||
defer func() { hijacked.Close(); hijacked.CloseWrite() }()
|
||||
if err != nil {
|
||||
ctx.AbortWithError(500, err)
|
||||
return
|
||||
}
|
||||
defer func() { hijacked.Close(); hijacked.CloseWrite() }()
|
||||
number, err := hijacked.Conn.Write([]byte(request.Command + "\n"))
|
||||
log.Print("Wrote ", number, " bytes")
|
||||
if err != nil {
|
||||
@@ -684,14 +688,14 @@ func (con Connection) BrowseServer(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
containers, err := con.dockerClient.ContainerList(context.TODO(), container.ListOptions{Filters: filters.NewArgs(filters.Arg("label", "type=FILE_BROWSER"), filters.Arg("label", "volume_id="+serverInfo.Id))})
|
||||
browserInfo, err := con.getBrowserInfoFromServerId(serverInfo.Id)
|
||||
if err != nil {
|
||||
ctx.AbortWithError(500, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(containers) > 0 {
|
||||
ctx.JSON(200, "OK")
|
||||
if browserInfo != nil {
|
||||
ctx.JSON(200, browserInfo.Url)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -725,7 +729,17 @@ func (con Connection) BrowseServer(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, "OK")
|
||||
browserInfo, err = con.getBrowserInfoFromServerId(serverInfo.Id)
|
||||
if err != nil {
|
||||
ctx.AbortWithError(500, err)
|
||||
return
|
||||
}
|
||||
|
||||
if browserInfo == nil {
|
||||
ctx.AbortWithError(500, fmt.Errorf("failed to open browser for server %s", serverInfo.Id))
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, browserInfo.Url)
|
||||
}
|
||||
|
||||
func (con Connection) serverAuthorized(permissions models.Permission) func(*gin.Context) bool {
|
||||
|
Reference in New Issue
Block a user