Give up on jsdelivr (Fix #46)

pull/55/head
Fox2Code 2 years ago
parent b97eaf140a
commit 08e0edbe6e

@ -138,10 +138,6 @@ public class RepoData {
moduleNotesUrl = Http.updateLink(moduleNotesUrl);
modulePropsUrl = Http.updateLink(modulePropsUrl);
moduleZipUrl = Http.updateLink(moduleZipUrl);
} else {
moduleNotesUrl = Http.fixUpLink(moduleNotesUrl);
modulePropsUrl = Http.fixUpLink(modulePropsUrl);
moduleZipUrl = Http.fixUpLink(moduleZipUrl);
}
RepoModule repoModule = this.moduleHashMap.get(moduleId);
if (repoModule == null) {

@ -68,8 +68,8 @@ public final class RepoManager {
this.repoData = new LinkedHashMap<>();
this.modules = new HashMap<>();
// We do not have repo list config yet.
this.addRepoData(MAGISK_REPO_JSDELIVR);
this.addRepoData(MAGISK_ALT_REPO_JSDELIVR);
this.addRepoData(MAGISK_REPO);
this.addRepoData(MAGISK_ALT_REPO);
this.addAndroidacyRepoData();
// Populate default cache
for (RepoData repoData:this.repoData.values()) {
@ -93,12 +93,12 @@ public final class RepoManager {
public RepoData get(String url) {
if (url == null) return null;
switch (url) {
case MAGISK_REPO_JSDELIVR:
case MAGISK_REPO_MANAGER:
case MAGISK_REPO:
url = MAGISK_REPO_JSDELIVR;
url = MAGISK_REPO;
break;
case MAGISK_ALT_REPO:
url = MAGISK_ALT_REPO_JSDELIVR;
case MAGISK_ALT_REPO_JSDELIVR:
url = MAGISK_ALT_REPO;
}
return this.repoData.get(url);
}

@ -113,11 +113,16 @@ public class Http {
+ " FoxMmm/" + BuildConfig.VERSION_CODE;
httpclientBuilder.addInterceptor(chain -> {
Request.Builder request = chain.request().newBuilder();
if (chain.request().url().host().endsWith(".androidacy.com")) {
request.header("Upgrade-Insecure-Requests", "1");
String host = chain.request().url().host();
if (host.endsWith(".androidacy.com")) {
request.header("User-Agent", androidacyUA);
} else if (InstallerInitializer.peekMagiskPath() != null) {
request.header("User-Agent", // Declare Magisk version to the server
"Magisk/" + InstallerInitializer.peekMagiskVersion());
} else if (!(host.equals("github.com") || host.endsWith(".github.com") ||
host.endsWith(".jsdelivr.net") || host.endsWith(".githubusercontent.com"))) {
if (InstallerInitializer.peekMagiskPath() != null) {
request.header("User-Agent", // Declare Magisk version to the server
"Magisk/" + InstallerInitializer.peekMagiskVersion());
}
}
if (chain.request().header("Accept-Language") == null) {
request.header("Accept-Language", // Send system language to the server
@ -148,13 +153,9 @@ public class Http {
return httpClientWithCache;
}
private static Request.Builder makeRequestBuilder() {
return new Request.Builder().header("Upgrade-Insecure-Requests", "1");
}
public static byte[] doHttpGet(String url,boolean allowCache) throws IOException {
Response response = (allowCache ? httpClientWithCache : httpClient).newCall(
makeRequestBuilder().url(url).get().build()
Response response = (allowCache ? getHttpClientWithCache() : getHttpClient()).newCall(
new Request.Builder().url(url).get().build()
).execute();
// 200/204 == success, 304 == cache valid
if (response.code() != 200 && response.code() != 204 &&
@ -172,8 +173,8 @@ public class Http {
}
public static byte[] doHttpPost(String url,String data,boolean allowCache) throws IOException {
Response response = (allowCache ? httpClientWithCache : httpClient).newCall(
makeRequestBuilder().url(url).post(JsonRequestBody.from(data))
Response response = (allowCache ? getHttpClientWithCache() : getHttpClient()).newCall(
new Request.Builder().url(url).post(JsonRequestBody.from(data))
.header("Content-Type", "application/json").build()
).execute();
// 200/204 == success, 304 == cache valid
@ -193,7 +194,8 @@ public class Http {
public static byte[] doHttpGet(String url,ProgressListener progressListener) throws IOException {
Log.d("Http", "Progress URL: " + url);
Response response = httpClient.newCall(makeRequestBuilder().url(url).get().build()).execute();
Response response = getHttpClient().newCall(
new Request.Builder().url(url).get().build()).execute();
if (response.code() != 200 && response.code() != 204) {
throw new IOException("Received error code: "+ response.code());
}
@ -442,28 +444,40 @@ public class Http {
*/
public static String updateLink(String string) {
if (string.startsWith("https://cdn.jsdelivr.net/gh/Magisk-Modules-Repo/")) {
int start = string.lastIndexOf('@'),
end = string.lastIndexOf('/');
String tmp = string.substring(48);
int start = tmp.lastIndexOf('@'),
end = tmp.lastIndexOf('/');
if ((end - 8) <= start) return string; // Skip if not a commit id
return string.substring(0, start + 1) + "master" + string.substring(end);
return "https://raw.githubusercontent.com/" +
tmp.substring(0, start) + "/master" + string.substring(end);
}
if (string.startsWith("https://github.com/Magisk-Modules-Repo/")) {
int i = string.lastIndexOf("/archive/");
if (i != -1) return string.substring(0, i + 9) + "master.zip";
if (i != -1 && string.indexOf('/', i + 9) == -1)
return string.substring(0, i + 9) + "master.zip";
}
return fixUpLink(string);
return string;
}
/**
* Change URL to appropriate url
* Change GitHub user-content url to jsdelivr url
* (Unused but kept as a documentation)
*/
public static String fixUpLink(String string) {
public static String cdnIfyLink(String string) {
if (string.startsWith("https://raw.githubusercontent.com/")) {
String[] tokens = string.substring(34).split("/", 4);
if (tokens.length != 4) return string;
return "https://cdn.jsdelivr.net/gh/" +
tokens[0] + "/" + tokens[1] + "@" + tokens[2] + "/" + tokens[3];
}
if (string.startsWith("https://github.com/")) {
int i = string.lastIndexOf("/archive/");
if (i == -1 || string.indexOf('/', i + 9) != -1)
return string; // Not an archive link
String[] tokens = string.substring(19).split("/", 4);
return "https://cdn.jsdelivr.net/gh/" +
tokens[0] + "/" + tokens[1] + "@" + tokens[2] + "/" + tokens[3];
}
return string;
}
}

@ -160,7 +160,7 @@ public class PropUtils {
break;
case "updateJson":
if (isInvalidURL(value)) break;
moduleInfo.updateJson = Http.fixUpLink(value);
moduleInfo.updateJson = value;
readUpdateJson = true;
break;
case "support":

Loading…
Cancel
Save