Skip to content

Commit 6611a63

Browse files
committed
10.1.0 - by Zoriot:
- Makes Self Updater work fine with Ptero Setups - Disable Java update on Ptero (force-enable option added if needed) - New fallback download rule: This rule permits files with a text/plain content type to pass validation, provided that the file name ends with a .jar extension. - Support for Velocity and Bungeecord plugin updates via the Modrinth API by replacing a hardcoded loader approach with a dynamic, server-software-aware system.
1 parent 84b6b50 commit 6611a63

3 files changed

Lines changed: 27 additions & 14 deletions

File tree

‎pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ AUTO-GENERATED FILE, CHANGES SHOULD BE DONE IN ./JPM.java or ./src/main/java//JP
1111
<modelVersion>4.0.0</modelVersion>
1212
<groupId>com.osiris.autoplug.client</groupId>
1313
<artifactId>AutoPlug-Client</artifactId>
14-
<version>10.0.5</version>
14+
<version>10.1.0</version>
1515
<properties>
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1717
<java.version>9</java.version>
18-
<version>10.0.5</version>
18+
<version>10.1.0</version>
1919
<main-class>com.osiris.autoplug.client.Main</main-class>
2020
<slf4j.version>2.0.13</slf4j.version>
2121
<name>AutoPlug-Client</name>

‎src/main/java/JPM.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public ThisProject(List<String> args) throws Exception {
3434
// Override default configurations
3535
this.groupId = "com.osiris.autoplug.client";
3636
this.artifactId = "AutoPlug-Client";
37-
this.version = "10.0.5";
37+
this.version = "10.1.0";
3838
this.mainClass = "com.osiris.autoplug.client.Main";
3939
this.jarName = "AutoPlug-Client-original.jar";
4040
this.fatJarName = "AutoPlug-Client.jar";

‎src/main/java/com/osiris/autoplug/client/tasks/updater/TaskDownload.java‎

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ public void runAtStart() throws Exception {
7777
body = response.body();
7878
if (body == null)
7979
throw new Exception("Download of '" + dest.getName() + "' failed because of null response body!");
80-
if (!isAllowedContentType(fileName, body.contentType(), ignoreContentType, allowedSubContentTypes))
81-
throw new Exception("Download of '" + dest.getName() + "' failed because of invalid content type: " + body.contentType());
82-
80+
validateContentType(dest.getName(), body.contentType(), ignoreContentType, allowedSubContentTypes);
8381
long completeFileSize = body.contentLength();
8482
setMax(completeFileSize);
8583

@@ -142,20 +140,35 @@ public boolean compareWithSHA256(String expectedHash) {
142140
return result;
143141
}
144142

145-
static boolean isAllowedContentType(String fileName, okhttp3.MediaType contentType, boolean ignoreContentType, String... allowedSubContentTypes) {
146-
if (ignoreContentType) return true;
147-
if (contentType == null) return false;
143+
static void validateContentType(String fileName, okhttp3.MediaType contentType, boolean ignoreContentType, String... allowedSubContentTypes) throws Exception {
144+
if (ignoreContentType) {
145+
return;
146+
}
147+
if (contentType == null) {
148+
throw new Exception("Download of '" + fileName + "' failed due to null content type!");
149+
}
150+
148151
String type = contentType.type();
149152
String subtype = contentType.subtype();
153+
150154
if ("application".equals(type)) {
151-
if ("java-archive".equals(subtype) || "jar".equals(subtype) || "octet-stream".equals(subtype)) return true;
152-
if (allowedSubContentTypes == null) return false;
153-
return Arrays.asList(allowedSubContentTypes).contains(subtype);
155+
if ("java-archive".equals(subtype) || "jar".equals(subtype) || "octet-stream".equals(subtype)) {
156+
return;
157+
}
158+
if (allowedSubContentTypes == null || !Arrays.asList(allowedSubContentTypes).contains(subtype)) {
159+
throw new Exception("Download of '" + fileName + "' failed because of invalid sub-content type: " + subtype);
160+
}
161+
return;
154162
}
155-
return fileName != null
163+
164+
if (fileName != null
156165
&& fileName.toLowerCase(Locale.ROOT).endsWith(".jar")
157166
&& "text".equals(type)
158-
&& "plain".equals(subtype);
167+
&& "plain".equals(subtype)) {
168+
return;
169+
}
170+
171+
throw new Exception("Download of '" + fileName + "' failed because of invalid content type: " + type);
159172
}
160173

161174
}

0 commit comments

Comments
 (0)