-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
147 lines (118 loc) · 3.49 KB
/
index.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { NativeModules } from 'react-native';
import * as base64 from "base64-js";
const { GomobileIpfs } = NativeModules;
export var RequestOption;
(function (RequestOption) {
RequestOption[RequestOption['Bool'] = 'b'] = 'Bool';
RequestOption[RequestOption['String'] = 's'] = 'String';
RequestOption[RequestOption['Bytes'] = 'd'] = 'Bytes';
})(RequestOption || (RequestOption = {}));
export var RequestBody;
(function (RequestBody) {
RequestBody[RequestBody['String'] = 's'] = 'String';
RequestBody[RequestBody['Bytes'] = 'd'] = 'Bytes';
})(RequestBody || (RequestBody = {}));
export class RequestBuilder {
constructor(ptr) {
this._ptr = ptr;
}
async withArgument(argument) {
const ptr = await GomobileIpfs.requestBuilderWithArgument(this._ptr, argument);
this._ptr = null;
return new RequestBuilder(ptr);
}
async withOption(option, type, value) {
if (type === RequestOption.Bytes) {
value = base64.fromByteArray(value);
}
const ptr = await GomobileIpfs.requestBuilderWithOption(this._ptr, option, type, value);
this._ptr = null;
return new RequestBuilder(ptr);
}
async withBody(type, body) {
if (type === RequestBody.Bytes) {
body = base64.fromByteArray(body);
}
const ptr = await GomobileIpfs.requestBuilderWithBody(this._ptr, type, body);
this._ptr = null;
return new RequestBuilder(ptr);
}
async withHeader(header, value) {
const ptr = await GomobileIpfs.requestBuilderWithHeader(this._ptr, header, value);
this._ptr = null;
return new RequestBuilder(ptr);
}
async send() {
const res = await GomobileIpfs.requestBuilderSend(this._ptr);
return base64.toByteArray(res);
}
sendToDict() {
return GomobileIpfs.requestBuilderSendToDict(this._ptr);
}
async free() {
const res = await GomobileIpfs.requestBuilderFree(this._ptr);
this._ptr = null;
return res;
}
}
export class IPFS {
constructor(ptr) {
this._ptr = ptr;
}
static async create(repoPath, internalStorage) {
if (!repoPath) {
repoPath = IPFS.defaultRepoPath;
}
if (typeof internalStorage !== 'boolean') {
internalStorage = true
}
const ptr = await GomobileIpfs.ipfsCreate(repoPath, internalStorage);
return new IPFS(ptr);
}
static setDNSPair(primary, secondary) {
return GomobileIpfs.ipfsSetDNSPair(primary, secondary);
}
start() {
return GomobileIpfs.ipfsStart(this._ptr);
}
stop() {
return GomobileIpfs.ipfsStop(this._ptr);
}
restart() {
return GomobileIpfs.ipfsRestart(this._ptr);
}
isStarted() {
return GomobileIpfs.ipfsIsStarted(this._ptr);
}
getConfig() {
return GomobileIpfs.ipfsGetConfig(this._ptr);
}
setConfig(config) {
return GomobileIpfs.ipfsSetConfig(this._ptr, config);
}
getConfigKey(key) {
return GomobileIpfs.ipfsGetConfigKey(this._ptr, key);
}
setConfigKey(key, value) {
return GomobileIpfs.ipfsSetConfigKey(this._ptr, key, value);
}
enablePubsubExperiment() {
return GomobileIpfs.ipfsEnablePubsubExperiment(this._ptr);
}
enableNamesysPubsub() {
return GomobileIpfs.ipfsEnableNamesysPubsub(this._ptr);
}
getAbsoluteRepoPath() {
return GomobileIpfs.ipfsGetAbsoluteRepoPath(this._ptr);
}
async newRequest(command) {
const ptr = await GomobileIpfs.ipfsNewRequest(this._ptr, command);
return new RequestBuilder(ptr);
}
async free() {
const res = await GomobileIpfs.ipfsFree(this._ptr);
this._ptr = null;
return res;
}
}
IPFS.defaultRepoPath = "ipfs/repo";