fixed browsers always being created

This commit is contained in:
ACoolName 2024-05-18 12:20:56 +03:00
parent 9834ab88c8
commit f2f0e18e6c

View File

@ -684,6 +684,17 @@ func (con Connection) BrowseServer(ctx *gin.Context) {
return 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))})
if err != nil {
ctx.AbortWithError(500, err)
return
}
if len(containers) > 0 {
ctx.JSON(200, "OK")
return
}
ContainerResponse, err := con.dockerClient.ContainerCreate( ContainerResponse, err := con.dockerClient.ContainerCreate(
context.TODO(), context.TODO(),
&container.Config{ &container.Config{
@ -692,9 +703,8 @@ func (con Connection) BrowseServer(ctx *gin.Context) {
Labels: browserLabels, Labels: browserLabels,
}, },
&container.HostConfig{ &container.HostConfig{
Mounts: []mount.Mount{{Source: serverInfo.Id, Target: "/tmp/data", Type: "volume"}}, Mounts: []mount.Mount{{Source: serverInfo.Id, Target: "/tmp/data", Type: "volume"}},
PublishAllPorts: true, AutoRemove: true,
AutoRemove: true,
}, },
&network.NetworkingConfig{ &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{"test": { EndpointsConfig: map[string]*network.EndpointSettings{"test": {