|
|
|
|
@ -1,19 +1,14 @@ |
|
|
|
|
package com.fongmi.quickjs.utils; |
|
|
|
|
|
|
|
|
|
import android.net.Uri; |
|
|
|
|
import android.util.Base64; |
|
|
|
|
|
|
|
|
|
import com.github.catvod.net.OkHttp; |
|
|
|
|
import com.github.catvod.utils.Asset; |
|
|
|
|
import com.github.catvod.utils.Path; |
|
|
|
|
import com.google.common.net.HttpHeaders; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
|
|
|
|
|
import okhttp3.Headers; |
|
|
|
|
import okhttp3.Response; |
|
|
|
|
|
|
|
|
|
public class Module { |
|
|
|
|
|
|
|
|
|
@ -41,17 +36,8 @@ public class Module { |
|
|
|
|
|
|
|
|
|
private String request(String url) { |
|
|
|
|
try { |
|
|
|
|
Uri uri = Uri.parse(url); |
|
|
|
|
File file = Path.js(uri.getLastPathSegment()); |
|
|
|
|
if (file.exists()) return Path.read(file); |
|
|
|
|
Response response = OkHttp.newCall(url, Headers.of(HttpHeaders.USER_AGENT, "Mozilla/5.0")).execute(); |
|
|
|
|
if (response.code() != 200) return ""; |
|
|
|
|
byte[] data = response.body().bytes(); |
|
|
|
|
boolean cache = !"127.0.0.1".equals(uri.getHost()); |
|
|
|
|
if (cache) new Thread(() -> Path.write(file, data)).start(); |
|
|
|
|
return new String(data, StandardCharsets.UTF_8); |
|
|
|
|
return OkHttp.newCall(url, Headers.of(HttpHeaders.USER_AGENT, "Mozilla/5.0")).execute().body().string(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|