Update ali

This commit is contained in:
FongMi 2023-03-23 17:35:37 +08:00
parent d27e09c54c
commit f1d12b2b0d
4 changed files with 27 additions and 5 deletions

View File

@ -30,12 +30,15 @@ import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.TimeZone;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -69,7 +72,15 @@ public class API {
} }
public void setRefreshToken(String token) { public void setRefreshToken(String token) {
if (auth.getRefreshToken().isEmpty()) auth.setRefreshToken(token); try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault());
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
long expireTime = sdf.parse(auth.getExpireTime()).getTime();
boolean expired = expireTime < System.currentTimeMillis();
if (expired) auth.setRefreshToken(token);
} catch (Exception e) {
auth.setRefreshToken(token);
}
} }
public void setShareId(String shareId) { public void setShareId(String shareId) {
@ -365,9 +376,14 @@ public class API {
} }
private void delete(String fileId) { private void delete(String fileId) {
String json = "{\"requests\":[{\"body\":{\"drive_id\":\"%s\",\"file_id\":\"%s\"},\"headers\":{\"Content-Type\":\"application/json\"},\"id\":\"%s\",\"method\":\"POST\",\"url\":\"/file/delete\"}],\"resource\":\"file\"}"; try {
json = String.format(json, auth.getDriveId(), fileId, fileId); JSONObject body = new JSONObject();
auth("adrive/v2/batch", json, true); body.put("file_id", fileId);
body.put("drive_id", auth.getDriveId());
oauth("openFile/delete", body.toString(), false);
} catch (Exception e) {
e.printStackTrace();
}
} }
public Object[] proxySub(Map<String, String> params) { public Object[] proxySub(Map<String, String> params) {

View File

@ -20,6 +20,8 @@ public class Auth {
private String userId; private String userId;
@SerializedName("driveId") @SerializedName("driveId")
private String driveId; private String driveId;
@SerializedName("expire_time")
private String expireTime;
public static Auth objectFrom(String str) { public static Auth objectFrom(String str) {
Auth item = new Gson().fromJson(str, Auth.class); Auth item = new Gson().fromJson(str, Auth.class);
@ -74,6 +76,10 @@ public class Auth {
this.userId = userId; this.userId = userId;
} }
public String getExpireTime() {
return TextUtils.isEmpty(expireTime) ? "" : expireTime;
}
public boolean isEmpty() { public boolean isEmpty() {
return getAccessToken().isEmpty(); return getAccessToken().isEmpty();
} }

Binary file not shown.

View File

@ -1 +1 @@
ac115573e4f120c68c0702f89150dbf3 1ca9fdc9e2698559f42704622465c286