|
|
@ -11,8 +11,11 @@ import ( |
|
|
|
sh "github.com/ipfs/go-ipfs-api" |
|
|
|
) |
|
|
|
|
|
|
|
const addedPads = "addedPads" |
|
|
|
const gettedPads = "gettedPads" |
|
|
|
//AddedPads is the directory where are stored the pads that are added to IPFS
|
|
|
|
const AddedPads = "addedPads" |
|
|
|
|
|
|
|
//GettedPads is the directory where are stored the pads that are getted from IPFS
|
|
|
|
const GettedPads = "gettedPads" |
|
|
|
|
|
|
|
//Add gets the content from the etherpad specified in the link, and downloads it in the format of the specified extension, and then, puts it into IPFS
|
|
|
|
func Add(link string, extension string) (string, error) { |
|
|
@ -26,7 +29,7 @@ func Add(link string, extension string) (string, error) { |
|
|
|
} |
|
|
|
|
|
|
|
//create the pads directory
|
|
|
|
_ = os.Mkdir(addedPads, os.ModePerm) |
|
|
|
_ = os.Mkdir(AddedPads, os.ModePerm) |
|
|
|
|
|
|
|
//get the pad name
|
|
|
|
linkSplitted := strings.Split(link, "/") |
|
|
@ -47,7 +50,7 @@ func Add(link string, extension string) (string, error) { |
|
|
|
} |
|
|
|
|
|
|
|
//save the content into a file
|
|
|
|
err = ioutil.WriteFile(addedPads+"/"+padName+"."+extension, content, 0644) |
|
|
|
err = ioutil.WriteFile(AddedPads+"/"+padName+"."+extension, content, 0644) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
return "", err |
|
|
@ -56,7 +59,7 @@ func Add(link string, extension string) (string, error) { |
|
|
|
//connect to ipfs shell
|
|
|
|
s := sh.NewShell("localhost:5001") |
|
|
|
//save the file into IPFS
|
|
|
|
ipfsHash, err := s.AddDir(addedPads + "/" + padName + "." + extension) |
|
|
|
ipfsHash, err := s.AddDir(AddedPads + "/" + padName + "." + extension) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
return "", err |
|
|
@ -67,11 +70,11 @@ func Add(link string, extension string) (string, error) { |
|
|
|
//Get gets the content from IPFS for a given hash, and saves it into a file
|
|
|
|
func Get(hash string, filename string) error { |
|
|
|
//create the pads directory
|
|
|
|
_ = os.Mkdir(gettedPads, os.ModePerm) |
|
|
|
_ = os.Mkdir(GettedPads, os.ModePerm) |
|
|
|
|
|
|
|
//connect to ipfs shell
|
|
|
|
s := sh.NewShell("localhost:5001") |
|
|
|
err := s.Get(hash, gettedPads+"/"+filename) |
|
|
|
err := s.Get(hash, GettedPads+"/"+filename) |
|
|
|
if err != nil { |
|
|
|
fmt.Println(err) |
|
|
|
return err |
|
|
|