You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.0 KiB

  1. package padArchiver
  2. import (
  3. "fmt"
  4. "os"
  5. sh "github.com/ipfs/go-ipfs-api"
  6. )
  7. //GettedPads is the directory where are stored the pads that are getted from IPFS
  8. const IpfsStorage = "ipfsStorage"
  9. const GettedPads = "ipfsStorage/gettedPads"
  10. //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
  11. func IpfsAdd(path string) (string, error) {
  12. //connect to ipfs shell
  13. s := sh.NewShell("localhost:5001")
  14. //save the file into IPFS
  15. ipfsHash, err := s.AddDir(path)
  16. if err != nil {
  17. fmt.Println(err)
  18. return "", err
  19. }
  20. return ipfsHash, nil
  21. }
  22. //Get gets the content from IPFS for a given hash, and saves it into a file
  23. func IpfsGet(hash string, filename string) error { //create the pads directory
  24. //create the pads directory
  25. _ = os.Mkdir(IpfsStorage, os.ModePerm)
  26. _ = os.Mkdir(GettedPads, os.ModePerm)
  27. //connect to ipfs shell
  28. s := sh.NewShell("localhost:5001")
  29. err := s.Get(hash, GettedPads+"/"+filename)
  30. if err != nil {
  31. fmt.Println(err)
  32. return err
  33. }
  34. return nil
  35. }