1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-16 18:54:43 +08:00

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

Refs https://github.com/1Panel-dev/1Panel/issues/5374
This commit is contained in:
zhengkunwang 2024-06-12 14:32:37 +08:00 committed by GitHub
parent 9bd9700bac
commit 09dc15a940
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 14 deletions

View File

@ -10,6 +10,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
"unicode/utf8"
"github.com/1Panel-dev/1Panel/backend/app/dto/request" "github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/response" "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) content := []byte(info.Content)
var decodeName string
if len(content) > 1024 { if len(content) > 1024 {
_, decodeName, _ = charset.DetermineEncoding(content[:1024], "") content = content[:1024]
} else {
_, decodeName, _ = charset.DetermineEncoding(content, "")
} }
if decodeName == "windows-1252" { if !utf8.Valid(content) {
reader := strings.NewReader(info.Content) _, decodeName, _ := charset.DetermineEncoding(content, "")
item := transform.NewReader(reader, simplifiedchinese.GBK.NewDecoder()) if decodeName == "windows-1252" {
contents, err := io.ReadAll(item) reader := strings.NewReader(info.Content)
if err != nil { item := transform.NewReader(reader, simplifiedchinese.GBK.NewDecoder())
return response.FileInfo{}, err 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 return response.FileInfo{FileInfo: *info}, nil
} }

View File

@ -1729,7 +1729,8 @@ const message = {
takeDown: 'TakeDown', takeDown: 'TakeDown',
allReadyInstalled: 'Installed', allReadyInstalled: 'Installed',
installHelper: 'Configuring image acceleration can solve the problem of image pull failure', 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: 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?', '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', showIgnore: 'View ignore application',

View File

@ -1610,7 +1610,7 @@ const message = {
takeDown: '已廢棄', takeDown: '已廢棄',
allReadyInstalled: '已安裝', allReadyInstalled: '已安裝',
installHelper: '配置鏡像加速可以解決鏡像拉取失敗的問題', installHelper: '配置鏡像加速可以解決鏡像拉取失敗的問題',
upgradeHelper: '異常應用需要先同步到正常狀態', upgradeHelper: '異常應用程式需要先同步到正常狀態升級失敗請在日誌審計-系統日誌中查看失敗原因',
installWarn: '當前未勾選端口外部訪問將無法通過外網IP:端口訪問是否繼續 ', installWarn: '當前未勾選端口外部訪問將無法通過外網IP:端口訪問是否繼續 ',
showIgnore: '查看忽略應用', showIgnore: '查看忽略應用',
cancelIgnore: '取消忽略', cancelIgnore: '取消忽略',

View File

@ -1610,7 +1610,7 @@ const message = {
takeDown: '已废弃', takeDown: '已废弃',
allReadyInstalled: '已安装', allReadyInstalled: '已安装',
installHelper: '配置镜像加速可以解决镜像拉取失败的问题', installHelper: '配置镜像加速可以解决镜像拉取失败的问题',
upgradeHelper: '异常应用需要先同步到正常状态', upgradeHelper: '异常应用需要先同步到正常状态升级失败请在日志审计-系统日志中查看失败原因',
installWarn: '当前未勾选端口外部访问将无法通过外网IP:端口访问是否继续', installWarn: '当前未勾选端口外部访问将无法通过外网IP:端口访问是否继续',
showIgnore: '查看忽略应用', showIgnore: '查看忽略应用',
cancelIgnore: '取消忽略', cancelIgnore: '取消忽略',