forked from covalenthq/ipfs-pinner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinner.go
67 lines (54 loc) · 2 KB
/
pinner.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
// Pinner node which is a composer of services and APIs provided by the ipfs-pinner.
// Specifically, it aims to provide a way to upload data to pinning services using
// either IPFS remote pinning service API or direct/car file uploads.
package pinner
import (
"log"
car "github.com/covalenthq/ipfs-pinner/car"
"github.com/covalenthq/ipfs-pinner/core"
"github.com/covalenthq/ipfs-pinner/coreapi"
"github.com/covalenthq/ipfs-pinner/dag"
"github.com/covalenthq/ipfs-pinner/pinclient"
"github.com/covalenthq/ipfs-pinner/w3up"
)
type pinnerNode struct {
ipfsCore coreapi.CoreExtensionAPI
carExporter car.CarExporterAPI
unixfsService dag.UnixfsAPI
pinApiClient pinclient.PinServiceAPI
}
func NewPinnerNode(req PinnerNodeCreateRequest) PinnerNode {
node := pinnerNode{}
ipfsNode, err := core.CreateIpfsNode(req.cidComputeOnly)
if err != nil {
log.Fatal("error initializing ipfs node: ", err)
}
node.ipfsCore = coreapi.NewCoreExtensionApi(ipfsNode)
//SETUP W3UP
log.Print("setting up w3up for uploads....")
w3up := w3up.NewW3up(req.pinServiceRequest.W3_AgentKey, req.pinServiceRequest.W3_AgentDid, req.pinServiceRequest.W3_DelegationProofPath)
agentDid, err := w3up.WhoAmI()
if err != nil {
log.Fatal("error getting agent did: ", err)
}
log.Printf("w3up agent did: %s\n", agentDid.String())
spaceDid, err := w3up.SpaceAdd()
if err != nil {
log.Fatal("error adding space: ", err)
}
log.Printf("w3up space did: %s\n", spaceDid.String())
log.Print("w3up setup complete")
node.pinApiClient = pinclient.NewClient(req.pinServiceRequest, req.cidVersion, w3up)
node.carExporter = car.NewCarExporter(node.ipfsCore)
node.unixfsService = dag.NewUnixfsAPI(node.ipfsCore, req.cidVersion, req.cidComputeOnly, req.ipfsFetchUrls)
return &node
}
func (node *pinnerNode) CarExporter() car.CarExporterAPI {
return node.carExporter
}
func (node *pinnerNode) PinService() pinclient.PinServiceAPI {
return node.pinApiClient
}
func (node *pinnerNode) UnixfsService() dag.UnixfsAPI {
return node.unixfsService
}