From b1c33bfba123ab2854109e165249035d3568e494 Mon Sep 17 00:00:00 2001 From: 1e99 Date: Mon, 16 Dec 2024 16:36:34 +0100 Subject: [PATCH] refactor pixel chat uploader --- .../src/eu/e99/pixelchat/fabric/PixelChat.java | 4 ++-- .../pixelchat/fabric/image/PixelChatUploader.java | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/mod-fabric/src/eu/e99/pixelchat/fabric/PixelChat.java b/mod-fabric/src/eu/e99/pixelchat/fabric/PixelChat.java index c27d396..3b31f12 100644 --- a/mod-fabric/src/eu/e99/pixelchat/fabric/PixelChat.java +++ b/mod-fabric/src/eu/e99/pixelchat/fabric/PixelChat.java @@ -19,8 +19,8 @@ public class PixelChat implements ClientModInitializer { UPLOADS = new ImageUploads( MinecraftClient.getInstance(), new ImageUploader[]{ - new PixelChatUploader("https", "pc.1e99.eu", 443), - new PixelChatUploader("https", "localhost", 443) + new PixelChatUploader("https://pc.1e99.eu"), + new PixelChatUploader("http://localhost:3000") } ); } diff --git a/mod-fabric/src/eu/e99/pixelchat/fabric/image/PixelChatUploader.java b/mod-fabric/src/eu/e99/pixelchat/fabric/image/PixelChatUploader.java index 263ae07..a0a78cd 100644 --- a/mod-fabric/src/eu/e99/pixelchat/fabric/image/PixelChatUploader.java +++ b/mod-fabric/src/eu/e99/pixelchat/fabric/image/PixelChatUploader.java @@ -1,6 +1,5 @@ package eu.e99.pixelchat.fabric.image; -import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -10,15 +9,14 @@ import java.nio.file.Path; public class PixelChatUploader implements ImageUploader { private final HttpClient client; - private final String scheme; private final String host; - private final int port; - public PixelChatUploader(String scheme, String host, int port) { + /** + * @param host A valid URI to the server. Must not end with a slash. Valid examples are: {@code https://pc.1e99.eu} or {@code http://localhost:3000}. + */ + public PixelChatUploader(String host) { this.client = HttpClient.newHttpClient(); - this.scheme = scheme; this.host = host; - this.port = port; } @Override @@ -42,6 +40,6 @@ public class PixelChatUploader implements ImageUploader { } private String url(String path) { - return String.format("%s://%s:%d/%s", this.scheme, this.host, this.port, path); + return String.format("%s/%s", this.host, path); } }