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.

59 lines
1.3 KiB

  1. package padArchiver
  2. import (
  3. "os"
  4. "github.com/fatih/color"
  5. )
  6. //Storage is the directory where are stored the repos
  7. const Storage = "reposStorage"
  8. //Repo is the directory where is placed the repository of pads
  9. type Repo struct {
  10. Dir string
  11. }
  12. //OpenRepo opens a repo from the directory
  13. func OpenRepo(directory string) Repo {
  14. //if not exist create the repos directory
  15. _ = os.Mkdir(Storage, os.ModePerm)
  16. var repo Repo
  17. repo.Dir = Storage + "/" + directory
  18. //create the repo directory
  19. _ = os.Mkdir(repo.Dir, os.ModePerm)
  20. return repo
  21. }
  22. //StorePad gets a pad from the link, and stores it into local directory. Then also, adds the file to IPFS.
  23. func (repo *Repo) StorePad(link string, directory string, title string, ipfsActive bool) (string, error) {
  24. path, err := repo.GetPad(link, "md", directory, title)
  25. if err != nil {
  26. color.Red(err.Error())
  27. return "", err
  28. }
  29. if !ipfsActive {
  30. return "", nil
  31. }
  32. hash, err := IpfsAdd(path)
  33. if err != nil {
  34. color.Red(err.Error())
  35. return hash, err
  36. }
  37. err = AddLineToFile(path, "IPFS hash of this document: "+hash)
  38. if err != nil {
  39. color.Red(err.Error())
  40. return hash, err
  41. }
  42. // TODO
  43. // err = repo.GitUpdate("update commit")
  44. // if err != nil {
  45. // color.Red(err.Error())
  46. // return hash, err
  47. // }
  48. return hash, nil
  49. }