|
|
@ -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,17 +336,21 @@ func (f *FileInfo) getContent() error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func DetectBinary(buf []byte) bool {
|
|
|
|
func DetectBinary(buf []byte) bool {
|
|
|
|
whiteByte := 0
|
|
|
|
mimeType := http.DetectContentType(buf)
|
|
|
|
n := min(1024, len(buf))
|
|
|
|
if !strings.HasPrefix(mimeType, "text/") {
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
whiteByte := 0
|
|
|
|
if (buf[i] >= 0x20) || buf[i] == 9 || buf[i] == 10 || buf[i] == 13 {
|
|
|
|
n := min(1024, len(buf))
|
|
|
|
whiteByte++
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
} else if buf[i] <= 6 || (buf[i] >= 14 && buf[i] <= 31) {
|
|
|
|
if (buf[i] >= 0x20) || buf[i] == 9 || buf[i] == 10 || buf[i] == 13 {
|
|
|
|
return true
|
|
|
|
whiteByte++
|
|
|
|
|
|
|
|
} else if buf[i] <= 6 || (buf[i] >= 14 && buf[i] <= 31) {
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return whiteByte < 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
|
|
return whiteByte < 1
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func min(x, y int) int {
|
|
|
|
func min(x, y int) int {
|
|
|
|