Compare commits
4 Commits
8fd01e2798
...
97e0a69474
Author | SHA1 | Date | |
---|---|---|---|
97e0a69474 | |||
5247ffd083 | |||
0a6b3ea264 | |||
3f708b16d9 |
39
main.go
39
main.go
@ -41,30 +41,32 @@ func NewIpfsMultipartWriter(w io.Writer) *IpfsMultipartWriter {
|
||||
|
||||
func (w *IpfsMultipartWriter) CreateIpfsDirectoryPart(name string) (io.Writer, error) {
|
||||
h := make(textproto.MIMEHeader)
|
||||
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, name))
|
||||
encodedName := url.QueryEscape(name)
|
||||
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, encodedName))
|
||||
h.Set("Content-Type", "application/x-directory")
|
||||
return w.CreatePart(h)
|
||||
}
|
||||
|
||||
func (w *IpfsMultipartWriter) CreateIpfsFilePart(name string) (io.Writer, error) {
|
||||
h := make(textproto.MIMEHeader)
|
||||
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, escapeQuotes(name)))
|
||||
encodedName := url.QueryEscape(name)
|
||||
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, escapeQuotes(encodedName)))
|
||||
h.Set("Content-Type", "application/octet-stream")
|
||||
return w.CreatePart(h)
|
||||
}
|
||||
|
||||
func (w *IpfsMultipartWriter) CreateIpfsAbsFilePart(name, absPath string) (io.Writer, error) {
|
||||
h := make(textproto.MIMEHeader)
|
||||
encodedName := url.QueryEscape(name)
|
||||
h.Set("AbsPath", absPath)
|
||||
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, escapeQuotes(name)))
|
||||
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="file"; filename="%s"`, escapeQuotes(encodedName)))
|
||||
h.Set("Content-Type", "application/octet-stream")
|
||||
return w.CreatePart(h)
|
||||
}
|
||||
|
||||
func main() {
|
||||
githubactions.Infof("Checking inputs...")
|
||||
githubactions.Debugf("Checking inputs")
|
||||
|
||||
// Check inputs
|
||||
path := githubactions.GetInput("path_to_add")
|
||||
if path == "" {
|
||||
githubactions.Fatalf("Missing: path_to_add")
|
||||
@ -95,7 +97,7 @@ func main() {
|
||||
githubactions.Fatalf("%v is not a directory", path)
|
||||
}
|
||||
|
||||
githubactions.Infof("Inputs OK")
|
||||
githubactions.Debugf("Inputs OK")
|
||||
|
||||
body, writer := io.Pipe()
|
||||
|
||||
@ -106,7 +108,6 @@ func main() {
|
||||
}
|
||||
|
||||
q := req.URL.Query()
|
||||
q.Add("wrap-with-directory", "true")
|
||||
q.Add("progress", "false")
|
||||
q.Add("stream-true", "false")
|
||||
req.URL.RawQuery = q.Encode()
|
||||
@ -127,8 +128,7 @@ func main() {
|
||||
return nil
|
||||
}
|
||||
|
||||
relPath, _ := filepath.Rel(path, innerPath)
|
||||
w, err := mwriter.CreateIpfsFilePart(url.QueryEscape(fmt.Sprintf("/%v", relPath)))
|
||||
w, err := mwriter.CreateIpfsFilePart(innerPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -152,28 +152,37 @@ func main() {
|
||||
}
|
||||
}()
|
||||
|
||||
githubactions.Infof("Calling node API...")
|
||||
githubactions.Debugf("Calling node API...")
|
||||
client := &http.Client{}
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
githubactions.Fatalf(err.Error())
|
||||
}
|
||||
|
||||
githubactions.Infof("Reading response...")
|
||||
githubactions.Debugf("Reading response...")
|
||||
resBody, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
githubactions.Fatalf(err.Error())
|
||||
}
|
||||
|
||||
githubactions.Infof("Response: %v", string(resBody))
|
||||
githubactions.Debugf("Response: %v", string(resBody))
|
||||
d := json.NewDecoder(res.Body)
|
||||
addResponses := make([]*AddResponse, 0)
|
||||
for {
|
||||
var ipfsAddResponse []AddResponse
|
||||
if err := d.Decode(&ipfsAddResponse); err == io.EOF {
|
||||
var addResponse AddResponse
|
||||
if err := d.Decode(&addResponse); 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.Debugf("Unmarshaled response: %v", addResponse)
|
||||
addResponses = append(addResponses, &addResponse)
|
||||
}
|
||||
|
||||
for _, addResponse := range addResponses {
|
||||
if (*addResponse).Name == path {
|
||||
githubactions.SetOutput("cid", addResponse.Hash)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user