1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

fix: 解决在线文本编辑器打开 GBK 编码文件乱码问题 (#5096)

Refs #3804
This commit is contained in:
ssongliu 2024-05-22 18:32:47 +08:00 committed by GitHub
parent ede664be18
commit 5cd59c7f39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 34 additions and 10 deletions

View File

@ -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
}
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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)
}

View File

@ -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
}