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

package padArchiver
import (
"os"
"github.com/fatih/color"
)
//Storage is the directory where are stored the repos
const Storage = "reposStorage"
//Repo is the directory where is placed the repository of pads
type Repo struct {
Dir string
}
//OpenRepo opens a repo from the directory
func OpenRepo(directory string) Repo {
//if not exist create the repos directory
_ = os.Mkdir(Storage, os.ModePerm)
var repo Repo
repo.Dir = Storage + "/" + directory
//create the repo directory
_ = os.Mkdir(repo.Dir, os.ModePerm)
return repo
}
//StorePad gets a pad from the link, and stores it into local directory. Then also, adds the file to IPFS.
func (repo *Repo) StorePad(link string, directory string, title string, ipfsActive bool) (string, error) {
path, err := repo.GetPad(link, "md", directory, title)
if err != nil {
color.Red(err.Error())
return "", err
}
if !ipfsActive {
return "", nil
}
hash, err := IpfsAdd(path)
if err != nil {
color.Red(err.Error())
return hash, err
}
err = AddLineToFile(path, "IPFS hash of this document: "+hash)
if err != nil {
color.Red(err.Error())
return hash, err
}
// TODO
// err = repo.GitUpdate("update commit")
// if err != nil {
// color.Red(err.Error())
// return hash, err
// }
return hash, nil
}