fix: 解决部分情况下打开文件中文乱码的问题 (#5425)

Refs https://github.com/1Panel-dev/1Panel/issues/5374
This commit is contained in:
zhengkunwang
2024-06-24 14:37:43 +08:00
committed by wanghe-fit2cloud
parent d33b836d3e
commit 794ebfab2b
4 changed files with 16 additions and 14 deletions
+12 -11
View File
@@ -10,6 +10,7 @@ import (
"path/filepath"
"strings"
"time"
"unicode/utf8"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
@@ -236,20 +237,20 @@ func (f *FileService) GetContent(op request.FileContentReq) (response.FileInfo,
}
content := []byte(info.Content)
var decodeName string
if len(content) > 1024 {
_, decodeName, _ = charset.DetermineEncoding(content[:1024], "")
} else {
_, decodeName, _ = charset.DetermineEncoding(content, "")
content = content[:1024]
}
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
if !utf8.Valid(content) {
_, 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)
}
info.Content = string(contents)
}
return response.FileInfo{FileInfo: *info}, nil
}
+2 -1
View File
@@ -1729,7 +1729,8 @@ const message = {
takeDown: 'TakeDown',
allReadyInstalled: 'Installed',
installHelper: 'Configuring image acceleration can solve the problem of image pull failure',
upgradeHelper: 'The abnormal application needs to be synchronized to the normal state first',
upgradeHelper:
'Abnormal applications need to be synchronized to normal status first. If the upgrade fails, please check the failure reason in the log audit-system log',
installWarn:
'Currently, if the port external access is not checked, it will not be able to access through the external network IP: port. Do you want to continue?',
showIgnore: 'View ignore application',
+1 -1
View File
@@ -1610,7 +1610,7 @@ const message = {
takeDown: '已廢棄',
allReadyInstalled: '已安裝',
installHelper: '配置鏡像加速可以解決鏡像拉取失敗的問題',
upgradeHelper: '異常應用需要先同步到正常狀態',
upgradeHelper: '異常應用程式需要先同步到正常狀態,升級失敗請在日誌審計-系統日誌中查看失敗原因',
installWarn: '當前未勾選端口外部訪問,將無法通過外網IP:端口訪問,是否繼續? ',
showIgnore: '查看忽略應用',
cancelIgnore: '取消忽略',
+1 -1
View File
@@ -1610,7 +1610,7 @@ const message = {
takeDown: '已废弃',
allReadyInstalled: '已安装',
installHelper: '配置镜像加速可以解决镜像拉取失败的问题',
upgradeHelper: '异常应用需要先同步到正常状态',
upgradeHelper: '异常应用需要先同步到正常状态,升级失败请在日志审计-系统日志中查看失败原因',
installWarn: '当前未勾选端口外部访问,将无法通过外网IP:端口访问,是否继续?',
showIgnore: '查看忽略应用',
cancelIgnore: '取消忽略',