Compare commits
2 Commits
27894f8ff0
...
ba717cfdb6
Author | SHA1 | Date | |
---|---|---|---|
ba717cfdb6 | |||
e57d2d9d1d |
33
main.go
33
main.go
@ -8,6 +8,7 @@ import (
|
|||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -98,14 +99,15 @@ func main() {
|
|||||||
|
|
||||||
body, writer := io.Pipe()
|
body, writer := io.Pipe()
|
||||||
|
|
||||||
url := fmt.Sprintf("http://%v:%v/api/v0/add", ipfsHost, ipfsPort)
|
targetUrl := fmt.Sprintf("http://%v:%v/api/v0/add", ipfsHost, ipfsPort)
|
||||||
req, err := http.NewRequest(http.MethodPost, url, body)
|
req, err := http.NewRequest(http.MethodPost, targetUrl, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
githubactions.Fatalf("Unable to create request: %v", err.Error())
|
githubactions.Fatalf("Unable to create request: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
q := req.URL.Query()
|
q := req.URL.Query()
|
||||||
q.Add("wrap-with-directory", "true")
|
q.Add("wrap-with-directory", "true")
|
||||||
|
q.Add("progress", "false")
|
||||||
req.URL.RawQuery = q.Encode()
|
req.URL.RawQuery = q.Encode()
|
||||||
|
|
||||||
mwriter := NewIpfsMultipartWriter(writer)
|
mwriter := NewIpfsMultipartWriter(writer)
|
||||||
@ -121,12 +123,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
_, err = mwriter.CreateIpfsDirectoryPart(innerPath)
|
// _, err = mwriter.CreateIpfsDirectoryPart(innerPath)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return err
|
// return err
|
||||||
}
|
// }
|
||||||
} else {
|
} else {
|
||||||
w, err := mwriter.CreateIpfsFilePart(innerPath)
|
relPath, _ := filepath.Rel(path, innerPath)
|
||||||
|
w, err := mwriter.CreateIpfsFilePart(url.QueryEscape(fmt.Sprintf("/%v", relPath)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -164,11 +167,15 @@ func main() {
|
|||||||
githubactions.Fatalf(err.Error())
|
githubactions.Fatalf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
var ipfsAddResponse []AddResponse
|
githubactions.Infof("Response: %v", string(resBody))
|
||||||
json.Unmarshal(resBody, &ipfsAddResponse)
|
d := json.NewDecoder(res.Body)
|
||||||
if err != nil {
|
for {
|
||||||
githubactions.Fatalf(err.Error())
|
var ipfsAddResponse []AddResponse
|
||||||
|
if err := d.Decode(&ipfsAddResponse); err == io.EOF {
|
||||||
|
break
|
||||||
|
} else if err != nil {
|
||||||
|
githubactions.Warningf("Failed to unmarshal response: %v", fmt.Errorf("%w", err))
|
||||||
|
}
|
||||||
|
githubactions.Infof("Received response: %v", ipfsAddResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
githubactions.Infof("Response: %v", ipfsAddResponse)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user