This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
90 lines (78 loc) · 1.78 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
dmca "github.com/ipfs/refs/dmca"
shell "github.com/whyrusleeping/ipfs-shell"
"flag"
"fmt"
"log"
)
func addSkeleton(sh *shell.Shell, dmca string) (string, error) {
hdenylists, err := sh.NewObject("unixfs-dir")
if err != nil {
return "", err
}
hdenylists, err = sh.PatchLink(hdenylists, "dmca", dmca, true)
if err != nil {
return "", err
}
hlists, err := sh.NewObject("unixfs-dir")
if err != nil {
return "", err
}
hlists, err = sh.PatchLink(hlists, "denylists", hdenylists, true)
if err != nil {
return "", err
}
hroot, err := sh.NewObject("unixfs-dir")
if err != nil {
return "", err
}
hroot, err = sh.PatchLink(hroot, "lists", hlists, true)
if err != nil {
return "", err
}
return hroot, nil
}
func addPrevious(sh *shell.Shell, h string, c string) (string, error) {
cur, err := sh.ResolvePath(c)
if err != nil {
log.Fatalf("could not resolve current version: %s", err)
}
prev, err := sh.ResolvePath(c + "/previous")
if err == nil {
h, err = sh.PatchLink(h, "previous", prev, true)
if err != nil {
return "", err
}
}
if h != cur {
h, err = sh.PatchLink(h, "previous", cur, true)
if err != nil {
return "", err
}
}
return h, nil
}
func main() {
u := flag.String("uri", "127.0.0.1:5001", "the IPFS API endpoint to use")
c := flag.String("current", "/ipns/refs.ipfs.io", "add links to previous versions")
flag.Parse()
sh := shell.NewShell(*u)
h, err := dmca.AddDenylist(sh)
if err != nil {
log.Fatalf("dmca.AddDenylist: %s", err)
}
if len(*c) > 0 {
p, err := addPrevious(sh, h, *c+"/lists/denylists/dmca")
if err != nil {
log.Printf("could not add previous link: %s\n", err)
} else {
h = p
}
}
h, err = addSkeleton(sh, h)
if err != nil {
log.Fatalf("main.addSkeleton: %s", err)
}
fmt.Println(h)
}