Skip to content
This repository was archived by the owner on Sep 9, 2023. It is now read-only.

Commit 3d66e69

Browse files
Fixed 403 errors
1 parent 6516149 commit 3d66e69

4 files changed

Lines changed: 21 additions & 16 deletions

File tree

src/ml/northwestwind/Constants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import java.util.function.Supplier;
66

77
public class Constants {
8-
public static final String CURSEFORGE_API = "https://addons-ecs.forgesvc.net/api/v2/addon/";
9-
public static final String VERSION = "1.2.10";
8+
public static final String CURSEFORGE_API = "https://northwestwind.ml/api/curseforge/mods/";
9+
public static final String VERSION = "1.2.11";
1010
private static final String OS = System.getProperty("os.name").toLowerCase();
1111
public static final boolean IS_WINDOWS = (OS.contains("win"));
1212
public static final boolean IS_MAC = (OS.contains("mac"));

src/ml/northwestwind/Modpack.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.time.LocalDateTime;
1414
import java.time.LocalTime;
1515
import java.time.ZoneId;
16+
import java.time.format.DateTimeFormatter;
1617
import java.util.*;
1718
import java.util.concurrent.atomic.AtomicInteger;
1819
import java.util.stream.Collectors;
@@ -52,7 +53,7 @@ private static void install(String[] ids) {
5253
}
5354
try {
5455
JSONObject json = Utils.runRetry(() -> (JSONObject) Utils.readJsonFromUrl(Constants.CURSEFORGE_API + id));
55-
if (((long) ((JSONObject) json.get("categorySection")).get("gameCategoryId")) != 4471)
56+
if (((long) json.get("classId")) != 4471)
5657
throw new NoSuchObjectException("The ID " + id + " does not represent a modpack.");
5758
JSONObject files;
5859
if (fileId == null) files = (JSONObject) Utils.getLast((JSONArray) json.get("latestFiles"));
@@ -81,7 +82,7 @@ private static void install(String[] ids) {
8182
FileUtils.deleteDirectory(packFolder);
8283
}
8384
packFolder.mkdir();
84-
String downloadUrl = ((String) files.get("downloadUrl")).replaceFirst("edge", "media");
85+
String downloadUrl = ((String) files.get("downloadUrl"));
8586
String loc = Utils.downloadFile(downloadUrl, packFolder.getAbsolutePath());
8687
if (loc == null) throw new SyncFailedException("Failed to download modpack " + name);
8788
boolean success = Utils.unzip(loc);
@@ -233,13 +234,13 @@ private static void genProfile(String name, String path, String icon, String loa
233234
JSONObject json = (JSONObject) parser.parse(new FileReader(profileFile));
234235
JSONObject profiles = (JSONObject) json.get("profiles");
235236
JSONObject profile = new JSONObject();
236-
profile.put("created", LocalDateTime.now(ZoneId.of("UTC")).toString());
237+
profile.put("created", LocalDateTime.now().format(DateTimeFormatter.ISO_INSTANT));
237238
profile.put("gameDir", path);
238239
if (base64 == null) profile.put("icon", "Furnace_On");
239240
else profile.put("icon", base64);
240241
int memory = (int) Math.ceil(Runtime.getRuntime().maxMemory() / 1024.0 / 1024.0 / 1024.0);
241242
profile.put("javaArgs", String.format("-Xmx%dG -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M", memory));
242-
profile.put("lastUsed", LocalDateTime.of(LocalDate.MIN, LocalTime.MIN).atZone(ZoneId.of("UTC")).toString());
243+
profile.put("lastUsed", "1970-01-01T00:00:00.000Z");
243244
profile.put("lastVersionId", loader == null ? "latest-release" : loader);
244245
profile.put("name", name);
245246
profile.put("type", "custom");
@@ -358,13 +359,13 @@ private static void update(String[] ids, boolean force) {
358359
}
359360
String finalKey = key;
360361
JSONObject json = Utils.runRetry(() -> (JSONObject) Utils.readJsonFromUrl(Constants.CURSEFORGE_API + finalKey));
361-
if (((long) ((JSONObject) json.get("categorySection")).get("gameCategoryId")) != 4471)
362+
if (((long) json.get("classId")) != 4471)
362363
throw new NoSuchObjectException("The ID " + id + " does not represent a modpack.");
363364
String name = (String) json.get("name");
364365
System.out.println(Ansi.ansi().fg(Ansi.Color.YELLOW).a("Updating ").a(name).a("...").reset());
365366
File packFolder = new File(Config.modpackDir.getAbsolutePath() + File.separator + slug + "_" + key);
366367
JSONObject latest = (JSONObject) Utils.getLast((JSONArray) json.get("latestFiles"));
367-
String downloadUrl = ((String) latest.get("downloadUrl")).replaceFirst("edge", "media");
368+
String downloadUrl = ((String) latest.get("downloadUrl"));
368369
String loc = Utils.downloadFile(downloadUrl, packFolder.getAbsolutePath());
369370
if (loc == null) throw new SyncFailedException("Failed to download modpack " + name);
370371
boolean success = Utils.unzip(loc);

src/ml/northwestwind/Profile.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ private static void add(String[] ids) {
221221
try {
222222
if (!Utils.isInteger(id)) throw new NoSuchObjectException("Mod ID is invalid: " + id);
223223
JSONObject json = Utils.runRetry(() -> (JSONObject) Utils.readJsonFromUrl(Constants.CURSEFORGE_API + id));
224-
if (((long) ((JSONObject) json.get("categorySection")).get("gameCategoryId")) != 6)
224+
if (((long) json.get("classId")) != 6)
225225
throw new NoSuchObjectException("The ID " + id + " does not represent a mod.");
226226
JSONArray files = Utils.runRetry(() -> (JSONArray) Utils.readJsonFromUrl(Constants.CURSEFORGE_API + id + "/files"));
227-
List f = (List) files.stream().filter(o -> Utils.checkVersion((JSONArray) ((JSONObject) o).get("gameVersion"), config)).collect(Collectors.toList());
227+
List f = (List) files.stream().filter(o -> Utils.checkVersion((JSONArray) ((JSONObject) o).get("gameVersions"), config)).collect(Collectors.toList());
228228
f.sort((a, b) -> (int) ((long) ((JSONObject) b).get("id") - (long) ((JSONObject) a).get("id")));
229229
if (f.size() < 1)
230230
throw new InputMismatchException("No available file of " + id + " found for this profile.");
@@ -444,10 +444,10 @@ private static void update(String[] args) {
444444
for (Map.Entry<Integer, Map.Entry<Integer, String>> entry : mods.entrySet()) {
445445
try {
446446
JSONObject json = Utils.runRetry(() -> (JSONObject) Utils.readJsonFromUrl(Constants.CURSEFORGE_API + entry.getKey()));
447-
if (((long) ((JSONObject) json.get("categorySection")).get("gameCategoryId")) != 6)
447+
if (((long) json.get("classId")) != 6)
448448
throw new NoSuchObjectException("The ID " + entry.getKey() + " does not represent a mod.");
449449
JSONArray files = Utils.runRetry(() -> (JSONArray) Utils.readJsonFromUrl(Constants.CURSEFORGE_API + entry.getKey() + "/files"));
450-
List f = (List) files.stream().filter(o -> Utils.checkVersion((JSONArray) ((JSONObject) o).get("gameVersion"), config)).collect(Collectors.toList());
450+
List f = (List) files.stream().filter(o -> Utils.checkVersion((JSONArray) ((JSONObject) o).get("gameVersions"), config)).collect(Collectors.toList());
451451
f.sort((a, b) -> (int) ((long) ((JSONObject) b).get("id") - (long) ((JSONObject) a).get("id")));
452452
if (f.size() < 1) continue;
453453
JSONObject fjson = (JSONObject) f.get(0);
@@ -484,18 +484,18 @@ private static void update(String[] args) {
484484
continue;
485485
}
486486
JSONObject json = Utils.runRetry(() -> (JSONObject) Utils.readJsonFromUrl(Constants.CURSEFORGE_API + id));
487-
if (((long) ((JSONObject) json.get("categorySection")).get("gameCategoryId")) != 6)
487+
if (((long) json.get("classId")) != 6)
488488
throw new NoSuchObjectException("The ID " + id + " does not represent a mod.");
489489
JSONArray files = Utils.runRetry(() -> (JSONArray) Utils.readJsonFromUrl(Constants.CURSEFORGE_API + id + "/files"));
490-
List f = (List) files.stream().filter(o -> Utils.checkVersion((JSONArray) ((JSONObject) o).get("gameVersion"), config)).collect(Collectors.toList());
490+
List f = (List) files.stream().filter(o -> Utils.checkVersion((JSONArray) ((JSONObject) o).get("gameVersions"), config)).collect(Collectors.toList());
491491
f.sort((a, b) -> (int) ((long) ((JSONObject) b).get("id") - (long) ((JSONObject) a).get("id")));
492492
if (f.size() < 1)
493493
throw new InputMismatchException("No available file of " + id + " found for this profile.");
494494
JSONObject bestFile = (JSONObject) f.get(0);
495495
Map.Entry<Integer, String> entry = mods.get(Integer.parseInt(id));
496496
if (((long) bestFile.get("id")) > entry.getKey()) {
497497
System.out.println(Ansi.ansi().fg(Ansi.Color.YELLOW).a(entry.getValue()).reset().a(" | ").fg(Ansi.Color.MAGENTA).a(id));
498-
String downloadUrl = ((String) bestFile.get("downloadUrl")).replaceFirst("edge", "media");
498+
String downloadUrl = ((String) bestFile.get("downloadUrl"));
499499
String loc = Utils.downloadFile(downloadUrl, profileConfig.getParent() + File.separator + "mods", ((String) bestFile.get("fileName")).replace(".jar", "_" + id + "_" + bestFile.get("id") + ".jar"));
500500
if (loc == null) continue;
501501
new File(profileConfig.getParent() + File.separator + "mods" + File.separator + entry.getValue() + "_" + id + "_" + entry.getKey() + ".jar").delete();

update.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"1.2.11": {
3+
"title": "Fixed 403 Status Error",
4+
"description": "Removed the use of a deprecated API URL."
5+
},
26
"1.2.10": {
37
"title": "Support for running from another directory",
48
"description": "This is designed for users who want to put this into their PATH variable. The program will always store configurations at where it is."
@@ -39,5 +43,5 @@
3943
"1.2.0": {
4044
"title": "Update Checker & Profile Generator"
4145
},
42-
"latest": "1.2.10"
46+
"latest": "1.2.11"
4347
}

0 commit comments

Comments
 (0)