Move Close
All checks were successful
Create and publish a Docker image / build-and-push-image (push) Successful in 56s

This commit is contained in:
Alexandre Bruyant 2024-01-07 22:19:37 +01:00
parent ba717cfdb6
commit dfd4fc1ecf

38
main.go
View File

@ -108,14 +108,15 @@ func main() {
q := req.URL.Query() q := req.URL.Query()
q.Add("wrap-with-directory", "true") q.Add("wrap-with-directory", "true")
q.Add("progress", "false") q.Add("progress", "false")
q.Add("stream-true", "false")
req.URL.RawQuery = q.Encode() req.URL.RawQuery = q.Encode()
mwriter := NewIpfsMultipartWriter(writer) mwriter := NewIpfsMultipartWriter(writer)
req.Header.Add("Content-Type", mwriter.FormDataContentType()) req.Header.Add("Content-Type", mwriter.FormDataContentType())
go func() { go func() {
defer mwriter.Close()
defer writer.Close() defer writer.Close()
defer mwriter.Close()
err = filepath.Walk(path, func(innerPath string, info fs.FileInfo, err error) error { err = filepath.Walk(path, func(innerPath string, info fs.FileInfo, err error) error {
if err != nil { if err != nil {
@ -123,27 +124,24 @@ func main() {
} }
if info.IsDir() { if info.IsDir() {
// _, err = mwriter.CreateIpfsDirectoryPart(innerPath) return nil
// if err != nil { }
// return err
// }
} else {
relPath, _ := filepath.Rel(path, innerPath)
w, err := mwriter.CreateIpfsFilePart(url.QueryEscape(fmt.Sprintf("/%v", relPath)))
if err != nil {
return err
}
fileReader, err := os.Open(innerPath) relPath, _ := filepath.Rel(path, innerPath)
if err != nil { w, err := mwriter.CreateIpfsFilePart(url.QueryEscape(fmt.Sprintf("/%v", relPath)))
return err if err != nil {
} return err
defer fileReader.Close() }
written, err := io.Copy(w, fileReader) fileReader, err := os.Open(innerPath)
if err != nil { if err != nil {
return fmt.Errorf("error copying %s (%d bytes written): %v", innerPath, written, err) return err
} }
defer fileReader.Close()
written, err := io.Copy(w, fileReader)
if err != nil {
return fmt.Errorf("error copying %s (%d bytes written): %v", innerPath, written, err)
} }
return nil return nil