尝试修正peers和pin请求 · java780/java-ipfs-cluster-api@510e0c2 · GitHub
Skip to content

Commit 510e0c2

Browse files
author
li
committed
尝试修正peers和pin请求
1 parent 3329738 commit 510e0c2

4 files changed

Lines changed: 170 additions & 10 deletions

File tree

pom.xml

Lines changed: 8 additions & 0 deletions

src/main/java/io/ipfs/cluster/api/IPFSCluster.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.ipfs.cluster.api;
22

3+
import com.alibaba.fastjson.JSONArray;
4+
import com.alibaba.fastjson.JSONObject;
35
import io.ipfs.cid.*;
46
import io.ipfs.multihash.Multihash;
57
import io.ipfs.multiaddr.MultiAddress;
@@ -25,7 +27,7 @@ public enum PinType {all, direct, indirect, recursive}
2527
*/
2628
public class Pin {
2729
public List<Multihash> add(Multihash hash) throws IOException {
28-
return ((List<Object>)((Map)retrieveAndParse("pin/add?stream-channels=true&arg=" + hash)).get("Pins"))
30+
return ((List<Object>)((Map)retrieveAndParse("pins/add?stream-channels=true&arg=" + hash)).get("Pins"))
2931
.stream()
3032
.map(x -> Cid.decode((String) x))
3133
.collect(Collectors.toList());
@@ -36,7 +38,7 @@ public Map<Multihash, Object> ls() throws IOException {
3638
}
3739

3840
public Map<Multihash, Object> ls(PinType type) throws IOException {
39-
return ((Map<String, Object>)(((Map)retrieveAndParse("pin/ls?stream-channels=true&t="+type.name())).get("Keys"))).entrySet()
41+
return ((Map<String, Object>)(((Map)retrieveAndParse("pins?stream-channels=true&t="+type.name())).get("Keys"))).entrySet()
4042
.stream()
4143
.collect(Collectors.toMap(x -> Cid.decode(x.getKey()), x-> x.getValue()));
4244
}
@@ -46,7 +48,7 @@ public List<Multihash> rm(Multihash hash) throws IOException {
4648
}
4749

4850
public List<Multihash> rm(Multihash hash, boolean recursive) throws IOException {
49-
Map json = retrieveMap("pin/rm?stream-channels=true&r=" + recursive + "&arg=" + hash);
51+
Map json = retrieveMap("pins/rm?stream-channels=true&r=" + recursive + "&arg=" + hash);
5052
return ((List<Object>) json.get("Pins")).stream().map(x -> Cid.decode((String) x)).collect(Collectors.toList());
5153
}
5254
}
@@ -59,15 +61,20 @@ public List<Multihash> add(Multihash hash) throws IOException {
5961
.collect(Collectors.toList());
6062
}
6163

62-
public Map<Multihash, Object> ls() throws IOException {
63-
return ls(PinType.direct);
64+
public List<Map<String, Object>> ls() throws IOException {
65+
List<Map<String, Object>> map = ((List<Map<String, Object>>)retrieveAndParse("peers"));
66+
return map;
6467
}
6568

66-
public Map<Multihash, Object> ls(PinType type) throws IOException {
67-
return ((Map<String, Object>)(((Map)retrieveAndParse("peers/ls?stream-channels=true&t="+type.name())).get("Keys"))).entrySet()
68-
.stream()
69-
.collect(Collectors.toMap(x -> Cid.decode(x.getKey()), x-> x.getValue()));
70-
}
69+
// public Map<Multihash, Object> ls() throws IOException {
70+
// return ls(PinType.direct);
71+
// }
72+
73+
// public Map<Multihash, Object> ls(PinType type) throws IOException {
74+
// return ((Map<String, Object>)(((Map)retrieveAndParse("peers")).get("Keys"))).entrySet()
75+
// .stream()
76+
// .collect(Collectors.toMap(x -> Cid.decode(x.getKey()), x-> x.getValue()));
77+
// }
7178

7279
public List<Multihash> rm(Multihash hash) throws IOException {
7380
return rm(hash, true);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.ipfs.cluster.api;
2+
3+
import java.io.IOException;
4+
5+
public class TEST {
6+
7+
public static void main(String args[]){
8+
9+
IPFSCluster ipfsCluster = new IPFSCluster("127.0.0.1", 9094);
10+
try {
11+
System.out.println("id" + ipfsCluster.id());
12+
System.out.println("version" + ipfsCluster.version());
13+
System.out.println("peers.ls" + ipfsCluster.peers.ls());
14+
System.out.println("pin.ls" + ipfsCluster.peers.ls());
15+
16+
} catch (IOException e) {
17+
e.printStackTrace();
18+
}
19+
}
20+
}
Lines changed: 125 additions & 0 deletions

0 commit comments

Comments
 (0)