Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: initial attempt at fixing multi-page resource response #296

Merged
merged 2 commits into from
Jun 23, 2024
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
12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("org.springframework.boot") version "3.3.0"
id("org.springframework.boot") version "3.3.1"
id("io.spring.dependency-management") version "1.1.5"
id("com.github.ben-manes.versions") version "0.51.0"
id("java")
Expand Down Expand Up @@ -29,17 +29,17 @@ dependencies {
implementation("org.springframework.cloud:spring-cloud-starter-openfeign")
implementation("com.github.ben-manes.caffeine:caffeine:3.1.8")
implementation("org.mariadb.jdbc:mariadb-java-client:3.4.0")
implementation("org.flywaydb:flyway-mysql:10.14.0")
implementation("org.flywaydb:flyway-core:10.14.0")
implementation("io.jsonwebtoken:jjwt-api:0.12.5")
implementation("org.flywaydb:flyway-mysql:10.15.0")
implementation("org.flywaydb:flyway-core:10.15.0")
implementation("io.jsonwebtoken:jjwt-api:0.12.6")
implementation("com.github.xMrAfonso:Hangar4J:1.2.3") {
exclude(group = "com.google.code.gson", module = "gson")
}
implementation("com.google.code.gson:gson:2.11.0")
implementation("com.github.usefulness:webp-imageio:0.8.0")

runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.5")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.12.5")
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.12.6")
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.12.6")

developmentOnly("org.springframework.boot:spring-boot-devtools")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClientResponseException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Component
public final class SpigotClient extends BasicHttpClient {
public SpigotClient() {
Expand Down Expand Up @@ -35,12 +39,32 @@ public ResponseEntity<SpigotResource> getResource(int id) {
}

public ResponseEntity<SpigotResource[]> getAllByAuthor(int id) {
try {
return get(String.format("getResourcesByAuthor&id=%d", id), SpigotResource[].class);
} catch (RestClientResponseException ex) {
Log.error("Failed to load all Spigot Resources by author id %d: %s", id, ex.getMessage());
ex.printStackTrace();
return null;
final List<SpigotResource> resources = new ArrayList<>();
int page = 1;

while (true) {
try {
final String url = String.format("getResourcesByAuthor&id=%d&page=%d", id, page);
final ResponseEntity<SpigotResource[]> response = get(url, SpigotResource[].class);

if (response.getBody() == null || response.getBody().length == 0) {
break;
}

resources.addAll(Arrays.asList(response.getBody()));

page++;
} catch (RestClientResponseException ex) {
Log.error("Failed to load Spigot Resources by author id %d on page %d: %s", id, page, ex.getMessage());
ex.printStackTrace();
return null;

}
}

final SpigotResource[] resourcesArray = new SpigotResource[resources.size()];
resources.toArray(resourcesArray);

return ResponseEntity.ok(resourcesArray);
}
}
Loading