fix bug
This commit is contained in:
parent
4f4f51ee37
commit
c7110a15ea
@ -1,6 +1,7 @@
|
||||
package cn.montaro.aria2;
|
||||
|
||||
import cn.montaro.aria2.annotation.Aria2Method;
|
||||
import cn.montaro.aria2.bean.Task;
|
||||
import cn.montaro.aria2.constants.Aria2MethodName;
|
||||
import cn.montaro.aria2.resp.Aria2Status;
|
||||
|
||||
@ -80,7 +81,7 @@ public interface Aria2Client {
|
||||
String getServers(String gid);
|
||||
|
||||
@Aria2Method(Aria2MethodName.TELL_ACTIVE)
|
||||
String tellActive(String... keys);
|
||||
List<Task> tellActive(String... keys);
|
||||
|
||||
@Aria2Method(Aria2MethodName.TELL_WAITING)
|
||||
String tellWaiting(int offset, int num, String... keys);
|
||||
|
||||
78
src/main/java/cn/montaro/aria2/bean/Task.java
Normal file
78
src/main/java/cn/montaro/aria2/bean/Task.java
Normal file
@ -0,0 +1,78 @@
|
||||
package cn.montaro.aria2.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Task implements Serializable {
|
||||
|
||||
public Long completedLength;
|
||||
|
||||
private Integer connections;
|
||||
|
||||
private Long downloadSpeed;
|
||||
|
||||
private String gid;
|
||||
|
||||
private Long totalLength;
|
||||
|
||||
private String status;
|
||||
|
||||
public int getProgress() {
|
||||
if (Objects.isNull(completedLength)
|
||||
|| completedLength == 0
|
||||
|| Objects.isNull(totalLength)
|
||||
|| totalLength == 0) {
|
||||
return 0;
|
||||
}
|
||||
return (int) (completedLength * 100 / totalLength);
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Long getTotalLength() {
|
||||
return totalLength;
|
||||
}
|
||||
|
||||
public void setTotalLength(Long totalLength) {
|
||||
this.totalLength = totalLength;
|
||||
}
|
||||
|
||||
public String getGid() {
|
||||
return gid;
|
||||
}
|
||||
|
||||
public void setGid(String gid) {
|
||||
this.gid = gid;
|
||||
}
|
||||
|
||||
public Long getDownloadSpeed() {
|
||||
return downloadSpeed;
|
||||
}
|
||||
|
||||
public void setDownloadSpeed(Long downloadSpeed) {
|
||||
this.downloadSpeed = downloadSpeed;
|
||||
}
|
||||
|
||||
public Integer getConnections() {
|
||||
return connections;
|
||||
}
|
||||
|
||||
public void setConnections(Integer connections) {
|
||||
this.connections = connections;
|
||||
}
|
||||
|
||||
public Long getCompletedLength() {
|
||||
return completedLength;
|
||||
}
|
||||
|
||||
public void setCompletedLength(Long completedLength) {
|
||||
this.completedLength = completedLength;
|
||||
}
|
||||
|
||||
}
|
||||
@ -8,10 +8,7 @@ import com.google.gson.*;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.ListIterator;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class Aria2HttpProxy implements InvocationHandler {
|
||||
|
||||
@ -26,6 +23,9 @@ public class Aria2HttpProxy implements InvocationHandler {
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
Aria2Method aria2Method = method.getDeclaredAnnotation(Aria2Method.class);
|
||||
if (Objects.isNull(aria2Method)) {
|
||||
return method.invoke(this, args);
|
||||
}
|
||||
String methodName = aria2Method.value();
|
||||
Type resultType = method.getGenericReturnType();
|
||||
String body = this.serialize(methodName, args);
|
||||
@ -79,14 +79,12 @@ public class Aria2HttpProxy implements InvocationHandler {
|
||||
}
|
||||
|
||||
private Object deserialize(String json, Type resultType) {
|
||||
if (resultType.equals(String.class)) {
|
||||
return json;
|
||||
}
|
||||
JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject();
|
||||
JsonElement result = jsonObject.get("result");
|
||||
if (result instanceof JsonObject && resultType.equals(String.class)) {
|
||||
return result.toString();
|
||||
}
|
||||
if (resultType.equals(String.class)) {
|
||||
return result.getAsString();
|
||||
}
|
||||
return gson.fromJson(result, resultType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user