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.

52 lines
964 B

  1. package padArchiver
  2. import (
  3. "os"
  4. "github.com/fatih/color"
  5. )
  6. const Storage = "reposStorage"
  7. type Repo struct {
  8. Dir string
  9. }
  10. func OpenRepo(directory string) Repo {
  11. //if not exist create the repos directory
  12. _ = os.Mkdir(Storage, os.ModePerm)
  13. var repo Repo
  14. repo.Dir = Storage + "/" + directory
  15. //create the repo directory
  16. _ = os.Mkdir(repo.Dir, os.ModePerm)
  17. return repo
  18. }
  19. func (repo *Repo) StorePad(link string, directory string, title string) (string, error) {
  20. path, err := repo.GetPad(link, "md", directory, title)
  21. if err != nil {
  22. color.Red(err.Error())
  23. return "", err
  24. }
  25. hash, err := IpfsAdd(path)
  26. if err != nil {
  27. color.Red(err.Error())
  28. return hash, err
  29. }
  30. err = AddLineToFile(path, "IPFS hash of this document: "+hash)
  31. if err != nil {
  32. color.Red(err.Error())
  33. return hash, err
  34. }
  35. // TODO
  36. // err = repo.GitUpdate("update commit")
  37. // if err != nil {
  38. // color.Red(err.Error())
  39. // return hash, err
  40. // }
  41. return hash, nil
  42. }