Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 547bc4b

Browse files
committed
improve error handling for image upload failures
1 parent 2b97902 commit 547bc4b

File tree

7 files changed

+24
-16
lines changed

7 files changed

+24
-16
lines changed

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/screenshotUtils/ImageScreen.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ protected void init() {
102102
int contentsHeight = height - ((isRemote ? 38 : 33) + 33);
103103
int buttonWidth = 75;
104104
double imgAspectRatio = image.image().getWidth() / (double) image.image().getHeight();
105-
int imageWidth = Math.min((int) (contentsHeight * imgAspectRatio), width - buttonWidth - 4 - 10);
105+
int imageWidth = Math.min((int) (contentsHeight * imgAspectRatio), width - buttonWidth - 4 - 20);
106106
int imageHeight = (int) (imageWidth / imgAspectRatio);
107107

108108

109109
var element = addButton(new ImageElement(imageWidth, imageHeight));
110110
if (width / 2 > (imageWidth / 2) + buttonWidth + 4) {
111111
element.setPosition(width / 2 - imageWidth / 2, 36);
112112
} else {
113-
element.setPosition(10, 36);
113+
element.setPosition(width/2 - imageWidth/2 - buttonWidth/2 - 2, 36);
114114
}
115115
int actionX = element.x + imageWidth + 4;
116116
var actions = new ArrayList<ButtonWidget>();
@@ -120,7 +120,7 @@ protected void init() {
120120
b.active = false;
121121
ImageShare.getInstance().upload(local.location()).thenAccept(s -> {
122122
if (s.isEmpty()) {
123-
Notifications.getInstance().addStatus("gallery.image.upload.failure", "gallery.image.upload.description");
123+
Notifications.getInstance().addStatus("gallery.image.upload.failure", "gallery.image.upload.failure.description");
124124
} else {
125125
client.execute(() -> client.openScreen(new ImageScreen(parent, local.toShared(s, API.getInstance().getSelf().getUuid(), Instant.now()), freeOnClose)));
126126
client.keyboard.setClipboard(s);

1.20/src/main/java/io/github/axolotlclient/modules/screenshotUtils/ImageScreen.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ protected void init() {
101101
int contentsHeight = height - ((isRemote ? 38 : 33) + 33);
102102
int buttonWidth = 75;
103103
double imgAspectRatio = image.image().getWidth() / (double) image.image().getHeight();
104-
int imageWidth = Math.min((int) (contentsHeight * imgAspectRatio), width - buttonWidth - 4 - 10);
104+
int imageWidth = Math.min((int) (contentsHeight * imgAspectRatio), width - buttonWidth - 4 - 20);
105105
int imageHeight = (int) (imageWidth / imgAspectRatio);
106106

107107

108108
var element = addDrawableChild(new ImageElement(imageWidth, imageHeight));
109109
if (width / 2 > (imageWidth / 2) + buttonWidth + 4) {
110110
element.setPosition(width/2 - imageWidth/2, 36);
111111
} else {
112-
element.setPosition(10, 36);
112+
element.setPosition(width/2 - imageWidth/2 - buttonWidth/2 - 2, 36);
113113
}
114114
int actionX = element.getX() + imageWidth + 4;
115115
var actions = new ArrayList<ButtonWidget>();
@@ -119,7 +119,7 @@ protected void init() {
119119
b.active = false;
120120
ImageShare.getInstance().upload(local.location()).thenAccept(s -> {
121121
if (s.isEmpty()) {
122-
Notifications.getInstance().addStatus("gallery.image.upload.failure", "gallery.image.upload.description");
122+
Notifications.getInstance().addStatus("gallery.image.upload.failure", "gallery.image.upload.failure.description");
123123
} else {
124124
client.execute(() -> client.setScreen(new ImageScreen(parent, local.toShared(s, API.getInstance().getSelf().getUuid(), Instant.now()), freeOnClose)));
125125
client.keyboard.setClipboard(s);

1.21.4/src/main/java/io/github/axolotlclient/modules/screenshotUtils/ImageScreen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected void init() {
9696

9797
int buttonWidth = 75;
9898
double imgAspectRatio = image.image().getWidth() / (double) image.image().getHeight();
99-
int imageWidth = Math.min((int) (layout.getContentHeight() * imgAspectRatio), layout.getWidth() - buttonWidth - 4 - 10);
99+
int imageWidth = Math.min((int) (layout.getContentHeight() * imgAspectRatio), layout.getWidth() - buttonWidth - 4 - 20);
100100
int imageHeight = (int) (imageWidth / imgAspectRatio);
101101

102102
var contents = layout.addToContents(LinearLayout.horizontal().spacing(4));
@@ -112,7 +112,7 @@ protected void init() {
112112
b.active = false;
113113
ImageShare.getInstance().upload(local.location()).thenAccept(s -> {
114114
if (s.isEmpty()) {
115-
Notifications.getInstance().addStatus("gallery.image.upload.failure", "gallery.image.upload.description");
115+
Notifications.getInstance().addStatus("gallery.image.upload.failure", "gallery.image.upload.failure.description");
116116
} else {
117117
minecraft.execute(() -> minecraft.setScreen(new ImageScreen(parent, local.toShared(s, API.getInstance().getSelf().getUuid(), Instant.now()), freeOnClose)));
118118
minecraft.keyboardHandler.setClipboard(s);

1.21/src/main/java/io/github/axolotlclient/modules/screenshotUtils/ImageScreen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected void init() {
9494

9595
int buttonWidth = 75;
9696
double imgAspectRatio = image.image().getWidth() / (double) image.image().getHeight();
97-
int imageWidth = Math.min((int) (layout.getContentsHeight() * imgAspectRatio), layout.getWidth() - buttonWidth - 4 - 10);
97+
int imageWidth = Math.min((int) (layout.getContentsHeight() * imgAspectRatio), layout.getWidth() - buttonWidth - 4 - 20);
9898
int imageHeight = (int) (imageWidth / imgAspectRatio);
9999

100100
var contents = layout.addToContents(LinearLayoutWidget.createHorizontal().setSpacing(4));
@@ -110,7 +110,7 @@ protected void init() {
110110
b.active = false;
111111
ImageShare.getInstance().upload(local.location()).thenAccept(s -> {
112112
if (s.isEmpty()) {
113-
Notifications.getInstance().addStatus("gallery.image.upload.failure", "gallery.image.upload.description");
113+
Notifications.getInstance().addStatus("gallery.image.upload.failure", "gallery.image.upload.failure.description");
114114
} else {
115115
client.execute(() -> client.setScreen(new ImageScreen(parent, local.toShared(s, API.getInstance().getSelf().getUuid(), Instant.now()), freeOnClose)));
116116
client.keyboard.setClipboard(s);

1.8.9/src/main/java/io/github/axolotlclient/modules/screenshotUtils/ImageScreen.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void init() {
102102
int contentsHeight = height - ((isRemote ? 38 : 33) + 33);
103103
int buttonWidth = 75;
104104
double imgAspectRatio = image.image().getWidth() / (double) image.image().getHeight();
105-
int imageWidth = Math.min((int) (contentsHeight * imgAspectRatio), width - buttonWidth - 4 - 10);
105+
int imageWidth = Math.min((int) (contentsHeight * imgAspectRatio), width - buttonWidth - 4 - 20);
106106
int imageHeight = (int) (imageWidth / imgAspectRatio);
107107

108108

@@ -111,7 +111,7 @@ public void init() {
111111
if (width / 2 > (imageWidth / 2) + buttonWidth + 4) {
112112
element.setPosition(width / 2 - imageWidth / 2, 36);
113113
} else {
114-
element.setPosition(10, 36);
114+
element.setPosition(width/2 - imageWidth/2 - buttonWidth/2 - 2, 36);
115115
}
116116
int actionX = element.x + imageWidth + 4;
117117
var actions = new ArrayList<ButtonWidget>();
@@ -148,7 +148,7 @@ protected void buttonClicked(ButtonWidget b) {
148148
ImageInstance.Local local = (ImageInstance.Local) image;
149149
ImageShare.getInstance().upload(local.location()).thenAccept(s -> {
150150
if (s.isEmpty()) {
151-
Notifications.getInstance().addStatus("gallery.image.upload.failure", "gallery.image.upload.description");
151+
Notifications.getInstance().addStatus("gallery.image.upload.failure", "gallery.image.upload.failure.description");
152152
} else {
153153
minecraft.submit(() -> minecraft.openScreen(new ImageScreen(parent, local.toShared(s, API.getInstance().getSelf().getUuid(), Instant.now()), freeOnClose)));
154154
setClipboard(s);

common/src/main/java/io/github/axolotlclient/api/Response.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private Object parseJson(String json) throws IOException {
8989
}
9090

9191
public String toString() {
92-
return "Response(body=" + bodyToString(this.getBody()) + ", plainBody=" + getPlainBody() + ", status=" + this.getStatus() + ", error=" + this.getError() + ")";
92+
return "Response(headers="+this.getHeaders() +", body=" + bodyToString(this.getBody()) + ", plainBody=" + getPlainBody() + ", status=" + this.getStatus() + ", error=" + this.getError() + ")";
9393
}
9494

9595
@SuppressWarnings("unchecked")

common/src/main/java/io/github/axolotlclient/modules/screenshotUtils/ImageNetworking.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.regex.Matcher;
3333
import java.util.regex.Pattern;
3434

35+
import io.github.axolotlclient.AxolotlClientCommon;
3536
import io.github.axolotlclient.api.API;
3637
import io.github.axolotlclient.api.Constants;
3738
import io.github.axolotlclient.api.Request;
@@ -46,13 +47,20 @@ protected CompletableFuture<String> upload(Path file) {
4647
try {
4748
return upload(file.getFileName().toString(), Files.readAllBytes(file));
4849
} catch (IOException e) {
50+
AxolotlClientCommon.getInstance().getLogger().error("Failed to upload image", e);
4951
return CompletableFuture.completedFuture("");
5052
}
5153
}
5254

5355
protected CompletableFuture<String> upload(String name, byte[] data) {
5456
return API.getInstance().post(Request.Route.IMAGE.builder().path(name).rawBody(data).build())
55-
.thenApply(response -> response.isError() ? "" : idToUrl(response.getPlainBody()));
57+
.thenApply(response -> {
58+
if (response.isError()) {
59+
AxolotlClientCommon.getInstance().getLogger().error("Failed to upload image, server responded with "+response);
60+
return "";
61+
}
62+
return idToUrl(response.getPlainBody());
63+
});
5664
}
5765

5866
protected static String idToUrl(String id) {
@@ -76,7 +84,7 @@ protected static Optional<String> ensureUrl(String urlOrId) {
7684

7785
protected CompletableFuture<ImageData> download(String url) {
7886
Optional<String> id = urlToId(url);
79-
return id.map(s -> API.getInstance().get(Request.Route.IMAGE.builder().path(s).build())
87+
return id.map(s -> API.getInstance().get(Request.Route.IMAGE.builder().requiresAuthentication(false).path(s).build())
8088
.thenApply(res -> {
8189
if (res.isError()) {
8290
return ImageData.EMPTY;

0 commit comments

Comments
 (0)