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