mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
deployment: Add Modrinth deployment functionality
This commit is contained in:
@@ -21,6 +21,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.google.code.gson:gson:2.11.0")
|
||||
implementation("com.squareup.okhttp3:okhttp:4.12.0")
|
||||
implementation("org.jetbrains:annotations:26.0.2")
|
||||
|
||||
implementation("de.oliver.FancyAnalytics:java-sdk:0.0.2")
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.google.gson.annotations.SerializedName;
|
||||
public record Configuration(
|
||||
@SerializedName("project_id") String projectID,
|
||||
@SerializedName("plugin_jar_path") String pluginJarPath,
|
||||
@SerializedName("changelog_path") String changeLogPath,
|
||||
String version,
|
||||
@SerializedName("supported_versions") String[] supportedVersions,
|
||||
String channel,
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package de.oliver.deployment.modrinth;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public record CreateVersionRequest(
|
||||
String name,
|
||||
@SerializedName("version_number") String versionName,
|
||||
String changelog,
|
||||
@SerializedName("game_versions") String[] gameVersions,
|
||||
@SerializedName("version_type") String versionType,
|
||||
String[] loaders,
|
||||
boolean featured,
|
||||
@SerializedName("project_id") String projectId,
|
||||
@SerializedName("file_parts") String[] fileParts,
|
||||
@SerializedName("primary_file") String primaryFile
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package de.oliver.deployment.modrinth;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import de.oliver.deployment.Configuration;
|
||||
import okhttp3.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ModrinthService {
|
||||
private static final String BASE_URL = "https://api.modrinth.com/v2/version";
|
||||
private final OkHttpClient client = new OkHttpClient();
|
||||
private final String apiKey;
|
||||
|
||||
public ModrinthService(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public void deployPlugin(Configuration config) throws IOException {
|
||||
String changelog = Files.readString(Path.of(config.changeLogPath()));
|
||||
|
||||
CreateVersionRequest req = new CreateVersionRequest(
|
||||
config.version(),
|
||||
config.version(),
|
||||
changelog,
|
||||
config.supportedVersions(),
|
||||
config.channel(),
|
||||
config.loaders(),
|
||||
config.featured(),
|
||||
config.projectID(),
|
||||
new String[]{"plugin"},
|
||||
"plugin"
|
||||
);
|
||||
|
||||
File pluginFile = new File(config.pluginJarPath());
|
||||
|
||||
RequestBody body = new MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.addFormDataPart("data", new Gson().toJson(req))
|
||||
.addFormDataPart("plugin", pluginFile.getName(),
|
||||
RequestBody.create(pluginFile, MediaType.parse("application/java-archive")))
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(BASE_URL)
|
||||
.addHeader("Authorization", apiKey)
|
||||
.post(body)
|
||||
.build();
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
System.out.println("Response: " + response.code() + " - " + response.body().string());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user