Clean code
This commit is contained in:
parent
de0d6af3fd
commit
fde087f1be
|
|
@ -12,6 +12,7 @@ android {
|
||||||
targetSdk 29
|
targetSdk 29
|
||||||
ndk { abiFilters "armeabi-v7a" }
|
ndk { abiFilters "armeabi-v7a" }
|
||||||
buildConfigField("String", "APP_ID", "\"${appId}\"")
|
buildConfigField("String", "APP_ID", "\"${appId}\"")
|
||||||
|
buildConfigField("String", "CLIENT_ID", "\"${clientId}\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|
|
||||||
|
|
@ -116,16 +116,16 @@ public class API {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String authOpen(String url, JSONObject body, boolean retry) {
|
private String authOpen(String url, String json, boolean retry) {
|
||||||
String result = OkHttp.postJson(url, body.toString(), getHeaderAuthOpen());
|
String result = OkHttp.postJson(url, json, getHeaderAuthOpen());
|
||||||
if (retry && check401Open(result)) return authOpen(url, body, false);
|
if (retry && check401Open(result)) return authOpen(url, json, false);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String sign(String url, JSONObject body, boolean retry) {
|
private String sign(String url, String json, boolean retry) {
|
||||||
url = url.startsWith("https") ? url : "https://api.aliyundrive.com/" + url;
|
url = url.startsWith("https") ? url : "https://api.aliyundrive.com/" + url;
|
||||||
String result = OkHttp.postJson(url, body.toString(), getHeaderSign());
|
String result = OkHttp.postJson(url, json, getHeaderSign());
|
||||||
if (retry && check401(result)) return sign(url, body, false);
|
if (retry && check401(result)) return sign(url, json, false);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,7 +170,7 @@ public class API {
|
||||||
body = new JSONObject();
|
body = new JSONObject();
|
||||||
body.put("authorize", 1);
|
body.put("authorize", 1);
|
||||||
body.put("scope", "user:base,file:all:read,file:all:write");
|
body.put("scope", "user:base,file:all:read,file:all:write");
|
||||||
object = new JSONObject(auth("https://open.aliyundrive.com/oauth/users/authorize?client_id=76917ccccd4441c39457a04f6084fb2f&redirect_uri=https://alist.nn.ci/tool/aliyundrive/callback&scope=user:base,file:all:read,file:all:write&state=", body, false));
|
object = new JSONObject(auth("https://open.aliyundrive.com/oauth/users/authorize?client_id=" + BuildConfig.CLIENT_ID + "&redirect_uri=https://alist.nn.ci/tool/aliyundrive/callback&scope=user:base,file:all:read,file:all:write&state=", body, false));
|
||||||
String code = object.toString().substring(object.toString().indexOf("code=") + 5, 104);
|
String code = object.toString().substring(object.toString().indexOf("code=") + 5, 104);
|
||||||
//OAuth Redirect
|
//OAuth Redirect
|
||||||
body = new JSONObject();
|
body = new JSONObject();
|
||||||
|
|
@ -234,7 +234,7 @@ public class API {
|
||||||
body.put("nonce", 0);
|
body.put("nonce", 0);
|
||||||
body.put("pubKey", pubKey);
|
body.put("pubKey", pubKey);
|
||||||
body.put("refreshToken", auth.getRefreshToken());
|
body.put("refreshToken", auth.getRefreshToken());
|
||||||
JSONObject object = new JSONObject(sign("users/v1/users/device/create_session", body, false));
|
JSONObject object = new JSONObject(sign("users/v1/users/device/create_session", body.toString(), false));
|
||||||
if (!object.getBoolean("success")) throw new Exception(object.toString());
|
if (!object.getBoolean("success")) throw new Exception(object.toString());
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
@ -358,7 +358,7 @@ public class API {
|
||||||
JSONObject body = new JSONObject();
|
JSONObject body = new JSONObject();
|
||||||
body.put("file_id", fileId);
|
body.put("file_id", fileId);
|
||||||
body.put("drive_id", auth.getDriveId());
|
body.put("drive_id", auth.getDriveId());
|
||||||
String url = new JSONObject(authOpen("https://open.aliyundrive.com/adrive/v1.0/openFile/getDownloadUrl", body, true)).optString("url");
|
String url = new JSONObject(authOpen("https://open.aliyundrive.com/adrive/v1.0/openFile/getDownloadUrl", body.toString(), true)).optString("url");
|
||||||
delete(fileId);
|
delete(fileId);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
@ -428,7 +428,7 @@ public class API {
|
||||||
body.put("share_id", auth.getShareId());
|
body.put("share_id", auth.getShareId());
|
||||||
body.put("template_id", "");
|
body.put("template_id", "");
|
||||||
body.put("category", "live_transcoding");
|
body.put("category", "live_transcoding");
|
||||||
String json = sign("v2/file/get_share_link_video_preview_play_info", body, true);
|
String json = sign("v2/file/get_share_link_video_preview_play_info", body.toString(), true);
|
||||||
JSONArray taskList = new JSONObject(json).getJSONObject("video_preview_play_info").getJSONArray("live_transcoding_task_list");
|
JSONArray taskList = new JSONObject(json).getJSONObject("video_preview_play_info").getJSONArray("live_transcoding_task_list");
|
||||||
Map<String, List<String>> respHeaders = new HashMap<>();
|
Map<String, List<String>> respHeaders = new HashMap<>();
|
||||||
OkHttp.stringNoRedirect(getPreviewQuality(taskList, flag), getHeader(), respHeaders);
|
OkHttp.stringNoRedirect(getPreviewQuality(taskList, flag), getHeader(), respHeaders);
|
||||||
|
|
|
||||||
|
|
@ -20,3 +20,4 @@ android.useAndroidX=true
|
||||||
# thereby reducing the size of the R class for that library
|
# thereby reducing the size of the R class for that library
|
||||||
android.nonTransitiveRClass=true
|
android.nonTransitiveRClass=true
|
||||||
appId=5dde4e1bdf9e4966b387ba58f4b3fdc3
|
appId=5dde4e1bdf9e4966b387ba58f4b3fdc3
|
||||||
|
clientId=76917ccccd4441c39457a04f6084fb2f
|
||||||
Binary file not shown.
|
|
@ -1 +1 @@
|
||||||
1862134a5028c5720a5c9eb24245144a
|
45d9462277175c390ccab72992b8c917
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue