Update ali : remove cache
This commit is contained in:
parent
a8601a0855
commit
865f4c0fee
|
|
@ -21,7 +21,6 @@ import com.github.catvod.crawler.SpiderDebug;
|
|||
import com.github.catvod.net.OkHttp;
|
||||
import com.github.catvod.spider.Init;
|
||||
import com.github.catvod.spider.Proxy;
|
||||
import com.github.catvod.utils.Prefers;
|
||||
import com.github.catvod.utils.QRCode;
|
||||
import com.github.catvod.utils.Trans;
|
||||
import com.github.catvod.utils.Utils;
|
||||
|
|
@ -30,15 +29,12 @@ import org.json.JSONArray;
|
|||
import org.json.JSONObject;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -61,7 +57,7 @@ public class API {
|
|||
}
|
||||
|
||||
private API() {
|
||||
auth = Auth.objectFrom(Prefers.getString("aliyundrive"));
|
||||
auth = new Auth();
|
||||
quality = new HashMap<>();
|
||||
quality.put("4K", "UHD");
|
||||
quality.put("2k", "QHD");
|
||||
|
|
@ -72,15 +68,7 @@ public class API {
|
|||
}
|
||||
|
||||
public void setRefreshToken(String 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);
|
||||
}
|
||||
auth.setRefreshToken(token);
|
||||
}
|
||||
|
||||
public void setShareId(String shareId) {
|
||||
|
|
@ -145,6 +133,12 @@ public class API {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean checkManyRequest(String result) {
|
||||
if (!result.contains("Too Many Requests")) return false;
|
||||
Init.show("洗洗睡吧,Too Many Requests。");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void checkAccessToken() {
|
||||
if (auth.getAccessToken().isEmpty()) refreshAccessToken();
|
||||
}
|
||||
|
|
@ -186,14 +180,20 @@ public class API {
|
|||
oauthRedirect(object.getString("redirectUri").split("code=")[1]);
|
||||
}
|
||||
|
||||
private void oauthRedirect(String code) throws Exception {
|
||||
SpiderDebug.log("OAuth Redirect...");
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("code", code);
|
||||
body.put("grant_type", "authorization_code");
|
||||
JSONObject object = new JSONObject(post("https://api.nn.ci/alist/ali_open/code", body));
|
||||
Log.e("DDD", object.toString());
|
||||
auth.setRefreshTokenOpen(object.getString("refresh_token"));
|
||||
private void oauthRedirect(String code) {
|
||||
try {
|
||||
SpiderDebug.log("OAuth Redirect...");
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("code", code);
|
||||
body.put("grant_type", "authorization_code");
|
||||
String result = post("https://api.nn.ci/alist/ali_open/code", body);
|
||||
Log.e("DDD", result);
|
||||
if (checkManyRequest(result)) return;
|
||||
JSONObject object = new JSONObject(result);
|
||||
auth.setRefreshTokenOpen(object.getString("refresh_token"));
|
||||
} catch (Exception e) {
|
||||
SpiderDebug.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean refreshOpenToken() {
|
||||
|
|
@ -202,11 +202,12 @@ public class API {
|
|||
JSONObject body = new JSONObject();
|
||||
body.put("grant_type", "refresh_token");
|
||||
body.put("refresh_token", auth.getRefreshTokenOpen());
|
||||
JSONObject object = new JSONObject(post("https://api.nn.ci/alist/ali_open/token", body));
|
||||
Log.e("DDD", object.toString());
|
||||
String result = post("https://api.nn.ci/alist/ali_open/token", body);
|
||||
Log.e("DDD", result);
|
||||
if (checkManyRequest(result)) return false;
|
||||
JSONObject object = new JSONObject(result);
|
||||
auth.setRefreshTokenOpen(object.optString("refresh_token"));
|
||||
auth.setAccessTokenOpen(object.optString("token_type") + " " + object.optString("access_token"));
|
||||
auth.save();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
SpiderDebug.log(e);
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
255c5dca97c64efb39b5fbe7d748cc0b
|
||||
4777a559fab527837e373a6a1a59b3a1
|
||||
|
|
|
|||
Loading…
Reference in New Issue