MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / getContent

Method getContent

agent/utils/files/fileinfo.go:484–504  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

482}
483
484func (f *FileInfo) getContent() error {
485 if IsBlockDevice(f.FileMode) {
486 return buserr.New("ErrFileCanNotRead")
487 }
488 if f.Size > 10*1024*1024 {
489 return buserr.New("ErrFileToLarge")
490 }
491 if IsBinaryPreviewFile(f.MimeType, f.Extension) {
492 return buserr.New("ErrFileCanNotRead")
493 }
494 afs := &afero.Afero{Fs: f.Fs}
495 cByte, err := afs.ReadFile(f.Path)
496 if err != nil {
497 return nil
498 }
499 if len(cByte) > 0 && DetectBinary(cByte) {
500 return buserr.New("ErrFileCanNotRead")
501 }
502 f.Content = string(cByte)
503 return nil
504}
505
506func IsBinaryPreviewFile(mimeType, extension string) bool {
507 mimeType = strings.ToLower(strings.TrimSpace(mimeType))

Callers 1

handleExpansionFunction · 0.80

Calls 3

IsBlockDeviceFunction · 0.85
IsBinaryPreviewFileFunction · 0.85
DetectBinaryFunction · 0.85

Tested by

no test coverage detected