|
|
@ -7,6 +7,7 @@ import ( |
|
|
|
"github.com/1Panel-dev/1Panel/backend/buserr" |
|
|
|
"github.com/1Panel-dev/1Panel/backend/buserr" |
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant" |
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant" |
|
|
|
"io/fs" |
|
|
|
"io/fs" |
|
|
|
|
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
|
"os/exec" |
|
|
|
"path" |
|
|
|
"path" |
|
|
@ -335,6 +336,8 @@ func (f *FileInfo) getContent() error { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func DetectBinary(buf []byte) bool { |
|
|
|
func DetectBinary(buf []byte) bool { |
|
|
|
|
|
|
|
mimeType := http.DetectContentType(buf) |
|
|
|
|
|
|
|
if !strings.HasPrefix(mimeType, "text/") { |
|
|
|
whiteByte := 0 |
|
|
|
whiteByte := 0 |
|
|
|
n := min(1024, len(buf)) |
|
|
|
n := min(1024, len(buf)) |
|
|
|
for i := 0; i < n; i++ { |
|
|
|
for i := 0; i < n; i++ { |
|
|
@ -344,9 +347,11 @@ func DetectBinary(buf []byte) bool { |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return whiteByte < 1 |
|
|
|
return whiteByte < 1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func min(x, y int) int { |
|
|
|
func min(x, y int) int { |
|
|
|
if x < y { |
|
|
|
if x < y { |
|
|
|