Compare commits
4 Commits
97e0a69474
...
8fd01e2798
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8fd01e2798 | ||
![]() |
91812ef33c | ||
![]() |
f0094b1a7a | ||
![]() |
cc34779294 |
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) {
|
func (w *IpfsMultipartWriter) CreateIpfsDirectoryPart(name string) (io.Writer, error) {
|
||||||
h := make(textproto.MIMEHeader)
|
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")
|
h.Set("Content-Type", "application/x-directory")
|
||||||
return w.CreatePart(h)
|
return w.CreatePart(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *IpfsMultipartWriter) CreateIpfsFilePart(name string) (io.Writer, error) {
|
func (w *IpfsMultipartWriter) CreateIpfsFilePart(name string) (io.Writer, error) {
|
||||||
h := make(textproto.MIMEHeader)
|
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")
|
h.Set("Content-Type", "application/octet-stream")
|
||||||
return w.CreatePart(h)
|
return w.CreatePart(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *IpfsMultipartWriter) CreateIpfsAbsFilePart(name, absPath string) (io.Writer, error) {
|
func (w *IpfsMultipartWriter) CreateIpfsAbsFilePart(name, absPath string) (io.Writer, error) {
|
||||||
h := make(textproto.MIMEHeader)
|
h := make(textproto.MIMEHeader)
|
||||||
|
encodedName := url.QueryEscape(name)
|
||||||
h.Set("AbsPath", absPath)
|
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")
|
h.Set("Content-Type", "application/octet-stream")
|
||||||
return w.CreatePart(h)
|
return w.CreatePart(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
githubactions.Infof("Checking inputs...")
|
githubactions.Debugf("Checking inputs")
|
||||||
|
|
||||||
// Check inputs
|
|
||||||
path := githubactions.GetInput("path_to_add")
|
path := githubactions.GetInput("path_to_add")
|
||||||
if path == "" {
|
if path == "" {
|
||||||
githubactions.Fatalf("Missing: path_to_add")
|
githubactions.Fatalf("Missing: path_to_add")
|
||||||
@ -95,7 +97,7 @@ func main() {
|
|||||||
githubactions.Fatalf("%v is not a directory", path)
|
githubactions.Fatalf("%v is not a directory", path)
|
||||||
}
|
}
|
||||||
|
|
||||||
githubactions.Infof("Inputs OK")
|
githubactions.Debugf("Inputs OK")
|
||||||
|
|
||||||
body, writer := io.Pipe()
|
body, writer := io.Pipe()
|
||||||
|
|
||||||
@ -106,7 +108,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
q := req.URL.Query()
|
q := req.URL.Query()
|
||||||
q.Add("wrap-with-directory", "true")
|
|
||||||
q.Add("progress", "false")
|
q.Add("progress", "false")
|
||||||
q.Add("stream-true", "false")
|
q.Add("stream-true", "false")
|
||||||
req.URL.RawQuery = q.Encode()
|
req.URL.RawQuery = q.Encode()
|
||||||
@ -127,8 +128,7 @@ func main() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
relPath, _ := filepath.Rel(path, innerPath)
|
w, err := mwriter.CreateIpfsFilePart(innerPath)
|
||||||
w, err := mwriter.CreateIpfsFilePart(url.QueryEscape(fmt.Sprintf("/%v", relPath)))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -152,28 +152,37 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
githubactions.Infof("Calling node API...")
|
githubactions.Debugf("Calling node API...")
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
res, err := client.Do(req)
|
res, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
githubactions.Fatalf(err.Error())
|
githubactions.Fatalf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
githubactions.Infof("Reading response...")
|
githubactions.Debugf("Reading response...")
|
||||||
resBody, err := io.ReadAll(res.Body)
|
resBody, err := io.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
githubactions.Fatalf(err.Error())
|
githubactions.Fatalf(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
githubactions.Infof("Response: %v", string(resBody))
|
githubactions.Debugf("Response: %v", string(resBody))
|
||||||
d := json.NewDecoder(res.Body)
|
d := json.NewDecoder(res.Body)
|
||||||
|
addResponses := make([]*AddResponse, 0)
|
||||||
for {
|
for {
|
||||||
var ipfsAddResponse []AddResponse
|
var addResponse AddResponse
|
||||||
if err := d.Decode(&ipfsAddResponse); err == io.EOF {
|
if err := d.Decode(&addResponse); err == io.EOF {
|
||||||
break
|
break
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
githubactions.Warningf("Failed to unmarshal response: %v", fmt.Errorf("%w", err))
|
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