Compare commits
No commits in common. "7030386bebc5aa8b416e0d2217e0bcb2ec6aaa52" and "97e0a69474d7fe6b4244a11788b430b9d944816a" have entirely different histories.
7030386beb
...
97e0a69474
@ -1,3 +0,0 @@
|
|||||||
# ipfs-node-pin
|
|
||||||
|
|
||||||
Pin a directory to an IPFS node through its RPC API.
|
|
@ -1,51 +0,0 @@
|
|||||||
package ipfsnodepin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"mime/multipart"
|
|
||||||
"net/textproto"
|
|
||||||
"net/url"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IpfsMultipartWriter struct {
|
|
||||||
multipart.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
var quoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"")
|
|
||||||
|
|
||||||
func escapeQuotes(s string) string {
|
|
||||||
return quoteEscaper.Replace(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewIpfsMultipartWriter(w io.Writer) *IpfsMultipartWriter {
|
|
||||||
return &IpfsMultipartWriter{
|
|
||||||
Writer: *multipart.NewWriter(w),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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-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-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-Type", "application/octet-stream")
|
|
||||||
return w.CreatePart(h)
|
|
||||||
}
|
|
49
main.go
49
main.go
@ -5,11 +5,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/textproto"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"gitea.bruyant.xyz/alexandre/ipfs-node-pin/ipfsnodepin"
|
|
||||||
"github.com/sethvargo/go-githubactions"
|
"github.com/sethvargo/go-githubactions"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,8 +23,48 @@ type AddResponse struct {
|
|||||||
Size string
|
Size string
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
type IpfsMultipartWriter struct {
|
||||||
|
multipart.Writer
|
||||||
|
}
|
||||||
|
|
||||||
|
var quoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"")
|
||||||
|
|
||||||
|
func escapeQuotes(s string) string {
|
||||||
|
return quoteEscaper.Replace(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewIpfsMultipartWriter(w io.Writer) *IpfsMultipartWriter {
|
||||||
|
return &IpfsMultipartWriter{
|
||||||
|
Writer: *multipart.NewWriter(w),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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-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-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-Type", "application/octet-stream")
|
||||||
|
return w.CreatePart(h)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
githubactions.Debugf("Checking inputs")
|
githubactions.Debugf("Checking inputs")
|
||||||
|
|
||||||
path := githubactions.GetInput("path_to_add")
|
path := githubactions.GetInput("path_to_add")
|
||||||
@ -69,7 +112,7 @@ func main() {
|
|||||||
q.Add("stream-true", "false")
|
q.Add("stream-true", "false")
|
||||||
req.URL.RawQuery = q.Encode()
|
req.URL.RawQuery = q.Encode()
|
||||||
|
|
||||||
mwriter := ipfsnodepin.NewIpfsMultipartWriter(writer)
|
mwriter := NewIpfsMultipartWriter(writer)
|
||||||
req.Header.Add("Content-Type", mwriter.FormDataContentType())
|
req.Header.Add("Content-Type", mwriter.FormDataContentType())
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user