feat: convert local file to memory file
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
张泊明518370910136 2024-06-30 08:45:17 -04:00
parent 97f89d210b
commit 739069a18f
GPG Key ID: D47306D7062CDA9D

View File

@ -1,6 +1,7 @@
package sandbox package sandbox
import ( import (
"log/slog"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -113,7 +114,12 @@ func convertPBFile(i stage.CmdFile) *pb.Request_File {
i.Src = &absPath i.Src = &absPath
} }
} }
return &pb.Request_File{File: &pb.Request_File_Local{Local: &pb.Request_LocalFile{Src: *i.Src}}} s, err := os.ReadFile(*i.Src)
if err != nil {
s = []byte{}
slog.Error("read file error", "path", *i.Src, "error", err)
}
return &pb.Request_File{File: &pb.Request_File_Memory{Memory: &pb.Request_MemoryFile{Content: s}}}
case i.Content != nil: case i.Content != nil:
s := strToBytes(*i.Content) s := strToBytes(*i.Content)
return &pb.Request_File{File: &pb.Request_File_Memory{Memory: &pb.Request_MemoryFile{Content: s}}} return &pb.Request_File{File: &pb.Request_File_Memory{Memory: &pb.Request_MemoryFile{Content: s}}}