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