Skip to content

Commit

Permalink
Update compress.go
Browse files Browse the repository at this point in the history
  • Loading branch information
vlssu committed Apr 25, 2024
1 parent c106a46 commit ecced08
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions server/filesystem/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (

"github.com/pterodactyl/wings/internal/ufs"
"github.com/pterodactyl/wings/server/filesystem/archiverext"

"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
)

// CompressFiles compresses all the files matching the given paths in the
Expand Down Expand Up @@ -51,6 +54,17 @@ func (fs *Filesystem) CompressFiles(dir string, paths []string) (ufs.FileInfo, e
return f.Stat()
}

// decodeGBK 解码 GBK 编码的字符串
func decodeGBK(input string) (string, error) {
decoder := simplifiedchinese.GBK.NewDecoder()
decoded, _, err := transform.String(decoder, input)
if err != nil {
return "", err
}
return decoded, nil
}

// archiverFileSystem 使用 archiver 根据文件的格式返回文件系统
func (fs *Filesystem) archiverFileSystem(ctx context.Context, p string) (iofs.FS, error) {
f, err := fs.unixFS.Open(p)
if err != nil {
Expand Down Expand Up @@ -87,6 +101,14 @@ func (fs *Filesystem) archiverFileSystem(ctx context.Context, p string) (iofs.FS
case archiver.Archival:
return archiver.ArchiveFS{Stream: io.NewSectionReader(f, 0, info.Size()), Format: ff, Context: ctx}, nil
case archiver.Compression:
// 如果文件名为 GBK 编码,则使用 GBK 解码。
if strings.Contains(filepath.Base(p), "GBK") {
gbkName, err := decodeGBK(filepath.Base(p))
if err != nil {
return nil, err
}
return archiverext.FileFS{File: f, Compression: ff, FileName: gbkName}, nil

Check failure on line 110 in server/filesystem/compress.go

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-22.04, 1.21.8, linux, amd64)

unknown field FileName in struct literal of type archiverext.FileFS

Check failure on line 110 in server/filesystem/compress.go

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-22.04, 1.21.8, linux, arm64)

unknown field FileName in struct literal of type archiverext.FileFS

Check failure on line 110 in server/filesystem/compress.go

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-22.04, 1.22.1, linux, amd64)

unknown field FileName in struct literal of type archiverext.FileFS

Check failure on line 110 in server/filesystem/compress.go

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu-22.04, 1.22.1, linux, arm64)

unknown field FileName in struct literal of type archiverext.FileFS
}
return archiverext.FileFS{File: f, Compression: ff}, nil
}
}
Expand Down

0 comments on commit ecced08

Please sign in to comment.