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.

43 lines
1.1 KiB

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