padArchiver/listPadsImporter/main.go
listPadsImporter/main.goRaw
1package main
2
3import (
4 "encoding/json"
5 "fmt"
6 "io/ioutil"
7
8 padArchiver ".."
9 "github.com/fatih/color"
10)
11
12//PadModel is the data struct of each pad in the list.json file
13type PadModel struct {
14 Link string `json:"link"`
15 Dir string `json:"dir"`
16 Title string `json:"title"`
17}
18
19//ListModel is the struct of the data from the list.json file
20type ListModel struct {
21 RepoID string `json:"repoid"`
22 Pads []PadModel `json:"pads"`
23}
24
25func readList(path string) ListModel {
26 file, err := ioutil.ReadFile(path)
27 check(err)
28 content := string(file)
29 var list ListModel
30 json.Unmarshal([]byte(content), &list)
31 return list
32}
33
34func main() {
35 asciiart := `
36.
37. _ _ _
38. | | /\ | | (_)
39 _ __ __ _ __| | / \ _ __ ___| |__ ___ _____ _ __
40| '_ \ / _ |/ _ | / /\ \ | '__/ __| '_ \| \ \ / / _ \ '__|
41| |_) | (_| | (_| |/ ____ \| | | (__| | | | |\ V / __/ |
42| .__/ \__,_|\__,_/_/ \_\_| \___|_| |_|_| \_/ \___|_| - listPadsImporter
43| |
44|_|
45
46 `
47 color.Blue(asciiart)
48 fmt.Println(" v0.0.1")
49 color.Blue("https://github.com/arnaucode/padArchiver")
50 fmt.Println("")
51 fmt.Println("")
52 fmt.Println("")
53
54 list := readList("list.json")
55
56 //open the repo
57 repo := padArchiver.OpenRepo(list.RepoID)
58 fmt.Println("repo opened")
59 for _, pad := range list.Pads {
60 fmt.Println("importing pad:")
61 fmt.Println(" link: " + pad.Link)
62 fmt.Println(" dir: " + pad.Dir)
63 fmt.Println(" title: " + pad.Title)
64 ipfsHash, err := repo.StorePad(pad.Link, pad.Dir, pad.Title, false)
65 check(err)
66 fmt.Println(" ipfs hash: " + ipfsHash)
67 }
68 color.Green("listPadsImporter finished")
69}