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