Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/me/itzg/helpers/McImageHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,4 @@ public Integer call() throws Exception {
return ExitCode.OK;
}
}
}
}
24 changes: 21 additions & 3 deletions src/main/java/me/itzg/helpers/fabric/FabricMetaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public class FabricMetaClient {

private final SharedFetch sharedFetch;
private final UriBuilder uriBuilder;

/**
* Retry attempts for metadata, non-downloads
*/
@Setter
private long retryMaxAttempts = 5;
/**
* Retry minimum backoff for metadata, non-downloads
*/
@Setter
private Duration retryMinBackoff = Duration.ofMillis(500);

@Setter
private int downloadRetryMaxAttempts = 5;
@Setter
Expand Down Expand Up @@ -59,7 +71,9 @@ else if (isSnapshot(version)) {
return findFirst(versionEntries, versionEntry -> versionEntry.getVersion().equalsIgnoreCase(version))
.switchIfEmpty(Mono.error(() -> new GenericException("Unable to find requested version")));
}
});
})
.retryWhen(Retry.backoff(retryMaxAttempts, retryMinBackoff).filter(IOException.class::isInstance))
.checkpoint();
}

private static boolean isSnapshot(@Nullable String version) {
Expand Down Expand Up @@ -91,7 +105,9 @@ public Mono<String> resolveLoaderVersion(String minecraftVersion, String loaderV
.getLoader();

return Mono.just(loader.getVersion());
});
})
.retryWhen(Retry.backoff(retryMaxAttempts, retryMinBackoff).filter(IOException.class::isInstance))
.checkpoint();
}

public Mono<String> resolveInstallerVersion(String installerVersion) {
Expand All @@ -111,7 +127,9 @@ public Mono<String> resolveInstallerVersion(String installerVersion) {
.orElseGet(
() -> Mono.error(new GenericException("Failed to find stable installer from " + uriBuilder.getBaseUrl()))
)
);
)
.retryWhen(Retry.backoff(retryMaxAttempts, retryMinBackoff).filter(IOException.class::isInstance))
.checkpoint();
}

public Mono<Path> downloadLauncher(
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/me/itzg/helpers/http/ObjectFetchBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import java.io.IOException;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import me.itzg.helpers.errors.GenericException;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import reactor.netty.ByteBufMono;
import reactor.netty.http.client.HttpClient;
import reactor.netty.http.client.HttpClientResponse;

import java.io.IOException;
import java.util.List;

@Slf4j
public class ObjectFetchBuilder<T> extends FetchBuilderBase<ObjectFetchBuilder<T>>
implements RequestResponseAssembler<T>
Expand Down Expand Up @@ -84,7 +82,7 @@ private <R> Mono<R> handleResponse(HttpClientResponse resp, ByteBufMono bodyMono
try {
return Mono.just(reader.readValue(inputStream));
} catch (IOException e) {
return Mono.error(new GenericException(
return Mono.error(new ResponseParsingException(
"Failed to parse response body into " +
(listOf ? "list of " + type : type),
e
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/me/itzg/helpers/http/ResponseParsingException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package me.itzg.helpers.http;

import java.io.IOException;

public class ResponseParsingException extends IOException {

public ResponseParsingException(String message, Throwable cause) {
super(message, cause);
}
}
3 changes: 3 additions & 0 deletions src/main/java/me/itzg/helpers/modrinth/ModrinthApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;

/**
* Provides a client for <a href="https://docs.modrinth.com/api/">Modrinth Labrinth API</a>
*/
@Slf4j
public class ModrinthApiClient implements AutoCloseable {

Expand Down
15 changes: 11 additions & 4 deletions src/main/java/me/itzg/helpers/modrinth/model/VersionFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
import java.util.Map;
import lombok.Data;

/**
* Refer to <code>files</code> of <a href="https://docs.modrinth.com/api/operations/getversion/#200">getversion</a>
*/
@Data
public class VersionFile {
Map<String,String> hashes;

String url;
/**
* key is either sha512 or sha1
*/
Map<String, String> hashes;

String filename;
String url;

boolean primary;
String filename;

boolean primary;
}