refactor pixel chat uploader

This commit is contained in:
1e99 2024-12-16 16:36:34 +01:00
parent bd12e1fbc9
commit b1c33bfba1
2 changed files with 7 additions and 9 deletions

View file

@ -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")
}
);
}

View file

@ -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);
}
}