diff --git a/backend/app/service/container.go b/backend/app/service/container.go index 24299824d..96e58f522 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -29,6 +29,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/registry" @@ -870,8 +871,8 @@ func calculateNetwork(network map[string]types.NetworkStats) (float64, float64) return rx, tx } -func checkImageExist(client *client.Client, image string) bool { - images, err := client.ImageList(context.Background(), types.ImageListOptions{}) +func checkImageExist(client *client.Client, imageItem string) bool { + images, err := client.ImageList(context.Background(), image.ListOptions{}) if err != nil { fmt.Println(err) return false @@ -879,7 +880,7 @@ func checkImageExist(client *client.Client, image string) bool { for _, img := range images { for _, tag := range img.RepoTags { - if tag == image || tag == image+":latest" { + if tag == imageItem || tag == imageItem+":latest" { return true } } diff --git a/backend/app/service/file.go b/backend/app/service/file.go index 3fa701579..256f3a3c1 100644 --- a/backend/app/service/file.go +++ b/backend/app/service/file.go @@ -2,6 +2,7 @@ package service import ( "fmt" + "io" "io/fs" "os" "os/exec" @@ -14,6 +15,9 @@ import ( "github.com/1Panel-dev/1Panel/backend/app/dto/response" "github.com/1Panel-dev/1Panel/backend/buserr" "github.com/1Panel-dev/1Panel/backend/constant" + "golang.org/x/net/html/charset" + "golang.org/x/text/encoding/simplifiedchinese" + "golang.org/x/text/transform" "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/common" @@ -227,6 +231,23 @@ func (f *FileService) GetContent(op request.FileContentReq) (response.FileInfo, Path: op.Path, Expand: true, }) + + content := []byte(info.Content) + var decodeName string + if len(content) > 1024 { + _, decodeName, _ = charset.DetermineEncoding(content[:1024], "") + } else { + _, decodeName, _ = charset.DetermineEncoding(content, "") + } + if decodeName == "windows-1252" { + reader := strings.NewReader(info.Content) + item := transform.NewReader(reader, simplifiedchinese.GBK.NewDecoder()) + contents, err := io.ReadAll(item) + if err != nil { + return response.FileInfo{}, err + } + info.Content = string(contents) + } if err != nil { return response.FileInfo{}, err } diff --git a/backend/utils/docker/docker.go b/backend/utils/docker/docker.go index 0e5e116cb..142de4260 100644 --- a/backend/utils/docker/docker.go +++ b/backend/utils/docker/docker.go @@ -4,6 +4,7 @@ import ( "context" "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/image" "github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/global" @@ -85,7 +86,7 @@ func (c Client) CreateNetwork(name string) error { } func (c Client) DeleteImage(imageID string) error { - if _, err := c.cli.ImageRemove(context.Background(), imageID, types.ImageRemoveOptions{Force: true}); err != nil { + if _, err := c.cli.ImageRemove(context.Background(), imageID, image.RemoveOptions{Force: true}); err != nil { return err } return nil @@ -105,7 +106,7 @@ func (c Client) PullImage(imageName string, force bool) error { return nil } } - if _, err := c.cli.ImagePull(context.Background(), imageName, types.ImagePullOptions{}); err != nil { + if _, err := c.cli.ImagePull(context.Background(), imageName, image.PullOptions{}); err != nil { return err } return nil @@ -114,7 +115,7 @@ func (c Client) PullImage(imageName string, force bool) error { func (c Client) GetImageIDByName(imageName string) (string, error) { filter := filters.NewArgs() filter.Add("reference", imageName) - list, err := c.cli.ImageList(context.Background(), types.ImageListOptions{ + list, err := c.cli.ImageList(context.Background(), image.ListOptions{ Filters: filter, }) if err != nil { @@ -129,7 +130,7 @@ func (c Client) GetImageIDByName(imageName string) (string, error) { func (c Client) CheckImageExist(imageName string) (bool, error) { filter := filters.NewArgs() filter.Add("reference", imageName) - list, err := c.cli.ImageList(context.Background(), types.ImageListOptions{ + list, err := c.cli.ImageList(context.Background(), image.ListOptions{ Filters: filter, }) if err != nil { diff --git a/backend/utils/mysql/client/remote.go b/backend/utils/mysql/client/remote.go index fe2a20d20..9a9b62e73 100644 --- a/backend/utils/mysql/client/remote.go +++ b/backend/utils/mysql/client/remote.go @@ -17,7 +17,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/files" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "github.com/docker/docker/client" ) @@ -417,7 +417,7 @@ func loadImage(dbType, version string) (string, error) { if err != nil { fmt.Println(err) } - images, err := cli.ImageList(context.Background(), types.ImageListOptions{}) + images, err := cli.ImageList(context.Background(), image.ListOptions{}) if err != nil { fmt.Println(err) } diff --git a/backend/utils/postgresql/client/remote.go b/backend/utils/postgresql/client/remote.go index c7e2db37a..8b5722378 100644 --- a/backend/utils/postgresql/client/remote.go +++ b/backend/utils/postgresql/client/remote.go @@ -14,6 +14,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/app/model" "github.com/1Panel-dev/1Panel/backend/global" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/image" "github.com/pkg/errors" "github.com/1Panel-dev/1Panel/backend/buserr" @@ -270,7 +271,7 @@ func loadImageTag() (string, error) { return "", err } defer client.Close() - images, err := client.ImageList(context.Background(), types.ImageListOptions{}) + images, err := client.ImageList(context.Background(), image.ListOptions{}) if err != nil { return "", err }