|
|
|
|
@ -1,11 +1,15 @@ |
|
|
|
|
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; |
|
|
|
|
@ -36,7 +40,22 @@ public class Module { |
|
|
|
|
|
|
|
|
|
private String request(String url) { |
|
|
|
|
try { |
|
|
|
|
return OkHttp.newCall(url, Headers.of(HttpHeaders.USER_AGENT, "Mozilla/5.0")).execute().body().string(); |
|
|
|
|
Uri uri = Uri.parse(url); |
|
|
|
|
File file = Path.js(uri.getLastPathSegment()); |
|
|
|
|
boolean cache = !"127.0.0.1".equals(uri.getHost()); |
|
|
|
|
byte[] data = OkHttp.newCall(url, Headers.of(HttpHeaders.USER_AGENT, "Mozilla/5.0")).execute().body().bytes(); |
|
|
|
|
if (cache) new Thread(() -> Path.write(file, data)).start(); |
|
|
|
|
return new String(data, StandardCharsets.UTF_8); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
return cache(url); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String cache(String url) { |
|
|
|
|
try { |
|
|
|
|
Uri uri = Uri.parse(url); |
|
|
|
|
File file = Path.js(uri.getLastPathSegment()); |
|
|
|
|
return file.exists() ? Path.read(file) : ""; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
|