mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-26 17:28:48 +08:00
fix: Fix the problem of garbled Chinese characters in file names (#10675)
This commit is contained in:
parent
e1a268b21d
commit
05d125c762
2 changed files with 55 additions and 59 deletions
|
|
@ -779,66 +779,67 @@ func (f *FileService) ConvertLog(req dto.PageInfo) (total int64, data []response
|
|||
}
|
||||
defer file.Close()
|
||||
|
||||
const chunkSize = 64 * 1024
|
||||
stat, err := file.Stat()
|
||||
if err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
size := stat.Size()
|
||||
fileSize := stat.Size()
|
||||
|
||||
buffer := make([]byte, 1)
|
||||
var line strings.Builder
|
||||
var lines []response.FileConvertLog
|
||||
var lineCount int64
|
||||
var (
|
||||
buf []byte
|
||||
remainder []byte
|
||||
offset = fileSize
|
||||
lines []string
|
||||
)
|
||||
|
||||
skipCount := int64((req.Page - 1) * req.PageSize)
|
||||
pageStart := int64((req.Page - 1) * req.PageSize)
|
||||
pageEnd := pageStart + int64(req.PageSize)
|
||||
|
||||
for offset := size - 1; offset >= 0; offset-- {
|
||||
_, err := file.ReadAt(buffer, offset)
|
||||
if err != nil {
|
||||
for offset > 0 {
|
||||
readSize := chunkSize
|
||||
if offset < int64(readSize) {
|
||||
readSize = int(offset)
|
||||
}
|
||||
offset -= int64(readSize)
|
||||
|
||||
tmp := make([]byte, readSize)
|
||||
if _, err := file.ReadAt(tmp, offset); err != nil && err != io.EOF {
|
||||
return 0, nil, err
|
||||
}
|
||||
|
||||
buf = append(tmp, remainder...)
|
||||
linesSplit := strings.Split(string(buf), "\n")
|
||||
|
||||
if offset > 0 {
|
||||
remainder = []byte(linesSplit[0])
|
||||
linesSplit = linesSplit[1:]
|
||||
}
|
||||
|
||||
for i := len(linesSplit) - 1; i >= 0; i-- {
|
||||
line := strings.TrimSpace(linesSplit[i])
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
total++
|
||||
if total > pageStart && total <= pageEnd {
|
||||
lines = append(lines, line)
|
||||
}
|
||||
if total >= pageEnd {
|
||||
break
|
||||
}
|
||||
}
|
||||
if total >= pageEnd {
|
||||
break
|
||||
}
|
||||
|
||||
if buffer[0] == '\n' {
|
||||
text := reverse(line.String())
|
||||
line.Reset()
|
||||
if text == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
var entry response.FileConvertLog
|
||||
if err := json.Unmarshal([]byte(text), &entry); err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if lineCount >= skipCount && len(lines) < req.PageSize {
|
||||
lines = append(lines, entry)
|
||||
}
|
||||
lineCount++
|
||||
} else {
|
||||
line.WriteByte(buffer[0])
|
||||
}
|
||||
}
|
||||
|
||||
if line.Len() > 0 {
|
||||
text := reverse(line.String())
|
||||
for _, line := range lines {
|
||||
var entry response.FileConvertLog
|
||||
if err := json.Unmarshal([]byte(text), &entry); err == nil {
|
||||
if lineCount >= skipCount && len(lines) < req.PageSize {
|
||||
lines = append(lines, entry)
|
||||
}
|
||||
lineCount++
|
||||
if err := json.Unmarshal([]byte(line), &entry); err == nil {
|
||||
data = append(data, entry)
|
||||
}
|
||||
}
|
||||
|
||||
total = lineCount
|
||||
data = lines
|
||||
return total, data, nil
|
||||
}
|
||||
|
||||
func reverse(s string) string {
|
||||
runes := []rune(s)
|
||||
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
|
||||
runes[i], runes[j] = runes[j], runes[i]
|
||||
}
|
||||
return string(runes)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@
|
|||
:label="$t('commons.table.type')"
|
||||
show-overflow-tooltip
|
||||
prop="type"
|
||||
width="60"
|
||||
width="70"
|
||||
></el-table-column>
|
||||
<el-table-column :label="$t('commons.button.log')" prop="log" min-width="160">
|
||||
<template #default="{ row }">
|
||||
|
|
@ -100,20 +100,15 @@
|
|||
</el-table-column>
|
||||
<el-table-column :label="$t('commons.table.message')" prop="status" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tooltip :content="row.message" placement="top">
|
||||
<el-button
|
||||
:type="
|
||||
row.status === 'FAILED'
|
||||
? 'danger'
|
||||
: row.status === 'SUCCESS'
|
||||
? 'success'
|
||||
: 'default'
|
||||
"
|
||||
link
|
||||
>
|
||||
{{ row.status }}
|
||||
<el-tooltip v-if="row.status === 'FAILED'" :content="row.message" placement="top">
|
||||
<el-button type="danger" link>
|
||||
{{ $t('commons.status.' + row.status.toLowerCase()) }}
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
|
||||
<el-button v-else :type="row.status === 'SUCCESS' ? 'success' : 'default'" link>
|
||||
{{ $t('commons.status.' + row.status.toLowerCase()) }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</ComplexTable>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue