Clean code

This commit is contained in:
FongMi 2023-09-20 01:50:05 +08:00
parent 6e4f3dd77f
commit 9ea7bc4016
5 changed files with 15 additions and 34 deletions

View File

@ -434,11 +434,7 @@ public class AliYun {
}
private void startFlow() {
if (Utils.isMobile()) {
Init.run(this::showInput);
} else {
getQRCode();
}
}
private void showInput() {

View File

@ -1,12 +1,10 @@
package com.github.catvod.net;
import android.net.Uri;
import android.text.TextUtils;
import com.github.catvod.crawler.Spider;
import java.io.IOException;
import java.net.Authenticator;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.List;
@ -43,8 +41,12 @@ public class OkHttp {
}
public static OkHttpClient.Builder getBuilder() {
return getBuilder(proxy());
}
public static OkHttpClient.Builder getBuilder(Uri proxy) {
OkHttpClient.Builder builder = new OkHttpClient.Builder().dns(safeDns()).readTimeout(30, TimeUnit.SECONDS).writeTimeout(30, TimeUnit.SECONDS).connectTimeout(30, TimeUnit.SECONDS).hostnameVerifier(SSLCompat.VERIFIER).sslSocketFactory(new SSLCompat(), SSLCompat.TM);
if (!TextUtils.isEmpty(proxy())) setProxy(builder);
if (proxy != null && proxy.getScheme() != null && proxy.getHost() != null && proxy.getPort() > 0) setProxy(builder, proxy);
return builder;
}
@ -64,17 +66,9 @@ public class OkHttp {
}
}
public static String proxy() {
public static Uri proxy() {
try {
return (String) Spider.class.getMethod("proxy").invoke(null);
} catch (Exception e) {
return null;
}
}
public static Authenticator auth() {
try {
return (Authenticator) Spider.class.getMethod("auth").invoke(null);
return (Uri) Spider.class.getMethod("proxy").invoke(null);
} catch (Exception e) {
return null;
}
@ -164,14 +158,12 @@ public class OkHttp {
return null;
}
private static void setProxy(OkHttpClient.Builder builder) {
Uri uri = Uri.parse(proxy());
String userInfo = uri.getUserInfo();
if (uri.getScheme() != null && uri.getScheme().startsWith("socks")) {
builder.proxy(new Proxy(Proxy.Type.SOCKS, InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort())));
}
if (uri.getScheme() != null && uri.getScheme().startsWith("http")) {
builder.proxy(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort())));
private static void setProxy(OkHttpClient.Builder builder, Uri proxy) {
String userInfo = proxy.getUserInfo();
if (proxy.getScheme() == null || proxy.getScheme().startsWith("socks")) {
builder.proxy(new Proxy(Proxy.Type.SOCKS, InetSocketAddress.createUnresolved(proxy.getHost(), proxy.getPort())));
} else if (proxy.getScheme().startsWith("http")) {
builder.proxy(new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(proxy.getHost(), proxy.getPort())));
if (userInfo != null && userInfo.contains(":")) builder.proxyAuthenticator((route, response) -> {
String credential = Credentials.basic(userInfo.split(":")[0], userInfo.split(":")[1]);
return response.request().newBuilder().header("Proxy-Authorization", credential).build();

View File

@ -48,13 +48,6 @@ public class Utils {
return RULE.matcher(url).find();
}
public static boolean isMobile() {
boolean hasCamera = Init.context().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
boolean hasPhone = Init.context().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
boolean hasBT = Init.context().getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH);
return hasCamera && hasPhone && hasBT;
}
public static byte[] toUtf8(byte[] bytes) {
try {
UniversalDetector detector = new UniversalDetector(null);

Binary file not shown.

View File

@ -1 +1 @@
17be876e842892abafa9dd0306e63cc3
f6c79a469fd9a93db4dbd5fb568b705a