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

Refs https://github.com/1Panel-dev/1Panel/issues/5374
pull/5436/head
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"
"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
}

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',

View File

@ -1610,7 +1610,7 @@ const message = {
takeDown: '',
allReadyInstalled: '',
installHelper: '',
upgradeHelper: '',
upgradeHelper: '-',
installWarn: 'IP: ',
showIgnore: '',
cancelIgnore: '',

View File

@ -1610,7 +1610,7 @@ const message = {
takeDown: '',
allReadyInstalled: '',
installHelper: '',
upgradeHelper: '',
upgradeHelper: '-',
installWarn: '访IP:访',
showIgnore: '',
cancelIgnore: '',