This commit is contained in:
1e99 2024-12-16 15:56:33 +01:00
parent 2ae3d83e97
commit 470118ac1c
2 changed files with 3 additions and 50 deletions

View file

@ -4,5 +4,8 @@ import java.nio.file.Path;
public interface ImageUploader {
/**
* @return An URL to a downloadable PNG file
*/
String upload(Path path) throws Throwable;
}

View file

@ -79,55 +79,5 @@ public class ImageUploads {
}
this.client.send(() -> bossBars.remove(bossBar.getUuid()));
/*try {
this.minecraft.send(() -> bossBars.add(bossBar.getUuid(), bossBar));
// TODO: Report some sort of progress?
HttpRequest req = HttpRequest.newBuilder()
.POST(HttpRequest.BodyPublishers.ofFile(path))
.uri(this.endpoint)
.build();
HttpResponse<String> res = this.client.send(
req,
HttpResponse.BodyHandlers.ofString()
);
if (res.statusCode() != 201) {
throw new RuntimeException(String.format("Failed to upload, expected status 201, got %d", res.statusCode()));
}
this.minecraft.send(() -> {
// TODO: Are we actually playing?
if (this.minecraft.player == null) {
return;
}
bossBar.setName(Text.translatable("pixelchat.upload_completed"));
bossBar.setPercent(1.0f);
bossBar.setColor(BossBar.Color.GREEN);
String id = res.body();
String url = String.format("%s", id);
this.minecraft.inGameHud.getChatHud().addToMessageHistory(url);
this.minecraft.player.networkHandler.sendChatMessage(url);
});
} catch (Throwable e) {
PixelChat.LOGGER.error("Upload failed", e);
this.minecraft.send(() -> {
bossBar.setName(Text.translatable("pixelchat.upload_failed"));
bossBar.setPercent(1.0f);
bossBar.setColor(BossBar.Color.RED);
});
} finally {
try {
Thread.sleep(5000);
} catch (InterruptedException ignored) {
}
this.minecraft.send(() -> bossBars.remove(bossBar.getUuid()));
}*/
}
}