@@ -17,6 +17,7 @@ public class IPFS {
17
17
18
18
public static final Version MIN_VERSION = Version .parse ("0.4.11" );
19
19
public enum PinType {all , direct , indirect , recursive }
20
+ public enum PinStatus {queued , pinning , pinned , failed }
20
21
public List <String > ObjectTemplates = Arrays .asList ("unixfs-dir" );
21
22
public List <String > ObjectPatchTypes = Arrays .asList ("add-link" , "rm-link" , "set-data" , "append-data" );
22
23
private static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 10_000 ;
@@ -206,7 +207,10 @@ public List<Multihash> add(Multihash hash) throws IOException {
206
207
.map (x -> Cid .decode ((String ) x ))
207
208
.collect (Collectors .toList ());
208
209
}
209
-
210
+ public Map addRemote (String service , Multihash hash , Optional <String > name , boolean background ) throws IOException {
211
+ String nameArg = name .isPresent () ? "&name=" + name .get () : "" ;
212
+ return retrieveMap ("pin/remote/add?arg=" + hash + "&service=" + service + nameArg + "&background=" + background );
213
+ }
210
214
public Map <Multihash , Object > ls () throws IOException {
211
215
return ls (PinType .direct );
212
216
}
@@ -217,6 +221,13 @@ public Map<Multihash, Object> ls(PinType type) throws IOException {
217
221
.collect (Collectors .toMap (x -> Cid .decode (x .getKey ()), x -> x .getValue ()));
218
222
}
219
223
224
+ public Map lsRemote (String service , Optional <String > name , Optional <List <PinStatus >> statusList ) throws IOException {
225
+ String nameArg = name .isPresent () ? "&name=" + name .get () : "" ;
226
+ String statusArg = statusList .isPresent () ? statusList .get ().stream ().
227
+ map (p -> "&status=" + p ).collect (Collectors .joining ()) : "" ;
228
+ return retrieveMap ("pin/remote/ls?service=" + service + nameArg + statusArg );
229
+ }
230
+
220
231
public List <Multihash > rm (Multihash hash ) throws IOException {
221
232
return rm (hash , true );
222
233
}
@@ -226,12 +237,36 @@ public List<Multihash> rm(Multihash hash, boolean recursive) throws IOException
226
237
return ((List <Object >) json .get ("Pins" )).stream ().map (x -> Cid .decode ((String ) x )).collect (Collectors .toList ());
227
238
}
228
239
240
+ public String rmRemote (String service , Optional <String > name , Optional <List <PinStatus >> statusList , Optional <List <Multihash >> cidList ) throws IOException {
241
+ String nameArg = name .isPresent () ? "&name=" + name .get () : "" ;
242
+ String statusArg = statusList .isPresent () ? statusList .get ().stream ().
243
+ map (p -> "&status=" + p ).collect (Collectors .joining ()) : "" ;
244
+ String cidArg = cidList .isPresent () ? cidList .get ().stream ().
245
+ map (p -> "&cid=" + p .toBase58 ()).collect (Collectors .joining ()) : "" ;
246
+ return retrieveString ("pin/remote/rm?service=" + service + nameArg + statusArg + cidArg );
247
+ }
248
+
249
+ public String addRemoteService (String service , String endPoint , String key ) throws IOException {
250
+ return retrieveString ("pin/remote/service/add?arg=" + service + "&arg=" + endPoint + "&arg=" + key );
251
+ }
252
+
253
+ public Map lsRemoteService (boolean stat ) throws IOException {
254
+ return retrieveMap ("pin/remote/service/ls?stat=" + stat );
255
+ }
256
+
257
+ public String rmRemoteService (String service ) throws IOException {
258
+ return retrieveString ("pin/remote/service/rm?arg=" + service );
259
+ }
260
+
229
261
public List <Multihash > update (Multihash existing , Multihash modified , boolean unpin ) throws IOException {
230
262
return ((List <Object >)((Map )retrieveAndParse ("pin/update?stream-channels=true&arg=" + existing + "&arg=" + modified + "&unpin=" + unpin )).get ("Pins" ))
231
263
.stream ()
232
264
.map (x -> Cid .decode ((String ) x ))
233
265
.collect (Collectors .toList ());
234
266
}
267
+ public Map verify (boolean verbose , boolean quite ) throws IOException {
268
+ return retrieveMap ("pin/verify?verbose=" + verbose + "&quite=" + quite );
269
+ }
235
270
}
236
271
237
272
/* 'ipfs key' is a command for dealing with IPNS keys.
0 commit comments