Update to match metadata and endpoints for Nightbloom

This commit is contained in:
2024-06-27 00:48:47 +02:00
parent 2aba3f99d4
commit 086e6d11a6
11 changed files with 75 additions and 11 deletions

View File

@@ -5,7 +5,7 @@ plugins {
}
group = 'com.hypherionmc.nightbloom'
version = '1.0.0'
version = '1.2.0'
configurations {
shadeMe

View File

@@ -1,6 +1,6 @@
#Sun Dec 10 23:57:41 SAST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@@ -14,10 +14,11 @@ import org.jetbrains.annotations.NotNull;
* @author HypherionSA
* Main API Client Class
*/
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class NightBloom4J {
@NonNull @Getter
@NonNull
private HttpClient client;
/**

View File

@@ -17,7 +17,7 @@ import java.io.IOException;
public abstract class HttpClient {
// Private variables, mostly for internal use
private final String API_BASE = "https://api.nightbloom.cc";
private final String API_BASE = "http://127.0.0.1:8787";
private final String baseUrl;
private final UserAgent agent;
@@ -112,6 +112,9 @@ public abstract class HttpClient {
bodyObject.addProperty("loader", String.join("|", data.getModloaders()));
bodyObject.addProperty("minecraft", String.join("|", data.getMinecraftVersions()));
bodyObject.addProperty("changelog", data.getChangelog());
bodyObject.addProperty("type", data.getType());
bodyObject.addProperty("dependsOn", data.getDependsOn());
bodyObject.addProperty("displayName", data.getDisplayName());
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)

View File

@@ -0,0 +1,27 @@
package com.hypherionmc.nightbloom.client.requests;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
@Setter
@RequiredArgsConstructor(staticName = "create")
public class ProjectFilesRequest {
private final String slug;
@NotNull
private String minecraft = "all";
@NotNull
private String loader = "all";
@NotNull
private String type = "all";
private int page = 1;
private int pageSize = 10;
public String buildRequest() {
String base = "projects/%s/files?mcVer=%s&loader=%s&type=%s&page=%s&pageSize=%s";
return String.format(base, slug, minecraft, loader, type, page, pageSize);
}
}

View File

@@ -2,10 +2,7 @@ package com.hypherionmc.nightbloom.client.requests;
import com.hypherionmc.nightbloom.NightBloom4J;
import com.hypherionmc.nightbloom.client.HttpClient;
import com.hypherionmc.nightbloom.model.ProjectFile;
import com.hypherionmc.nightbloom.model.ProjectMeta;
import com.hypherionmc.nightbloom.model.ProjectResponse;
import com.hypherionmc.nightbloom.model.StandardResponse;
import com.hypherionmc.nightbloom.model.*;
import lombok.RequiredArgsConstructor;
import java.io.File;
@@ -46,13 +43,13 @@ public class ProjectsEndpoint {
/**
* Get all files for a single project
* @param slug The project slug. For example 'craterlib'
* @param request An instance of {@link ProjectFilesRequest}
* @return A list of files uploaded to the project
* @throws IOException Thrown when an API error occurs
*/
public List<ProjectFile> getFiles(String slug) throws IOException {
public PaginatedFileResult getFiles(ProjectFilesRequest request) throws IOException {
HttpClient client = bloom4J.getClient();
return Arrays.stream(client.get("projects/" + slug + "/files", ProjectFile[].class)).collect(Collectors.toList());
return client.get(request.buildRequest(), PaginatedFileResult.class);
}
/**

View File

@@ -0,0 +1,13 @@
package com.hypherionmc.nightbloom.model;
import lombok.Getter;
@Getter
public class Depends {
private String slug;
private String title;
private String logo;
private String author;
}

View File

@@ -18,7 +18,10 @@ public class FileSummary {
private String version;
private int filesize;
private String filename;
private String type;
private Depends dependsOn;
private String downloadUrl;
private String displayName;
private Date createdAt;
private Date updatedAt;

View File

@@ -0,0 +1,14 @@
package com.hypherionmc.nightbloom.model;
import lombok.Getter;
import java.util.List;
@Getter
public class PaginatedFileResult {
private List<ProjectFile> files;
public int page;
public int totalPages;
public int totalCount;
public int pageSize;
}

View File

@@ -19,6 +19,9 @@ public class ProjectFile {
private int filesize;
private String filename;
private String downloadUrl;
private String type;
private Depends dependsOn;
private String displayName;
private Date createdAt;
private Date updatedAt;
}

View File

@@ -17,6 +17,9 @@ public class ProjectMeta {
private final List<String> modloaders = new ArrayList<>();
private final List<String> minecraftVersions = new ArrayList<>();
private final String changelog;
private final String type;
private final int dependsOn;
private final String displayName;
public void addModloader(String loader) {
if (!modloaders.contains(loader))