Skip to content

Commit 803771e

Browse files
authored
Switch to pastes.dev for /ess dump (#6011)
Requires merge of EssentialsX/Website#106
1 parent 667b0f7 commit 803771e

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,14 @@ private void runDump(Server server, CommandSource sender, String commandLabel, S
461461
final CompletableFuture<PasteUtil.PasteResult> future = PasteUtil.createPaste(files);
462462
future.thenAccept(result -> {
463463
if (result != null) {
464-
final String dumpUrl = "https://essentialsx.net/dump.html?id=" + result.getPasteId();
464+
final String dumpUrl = "https://essentialsx.net/dump.html?bytebin=" + result.getPasteId();
465465
sender.sendTl("dumpUrl", dumpUrl);
466-
sender.sendTl("dumpDeleteKey", result.getDeletionKey());
466+
// pastes.dev doesn't support deletion keys
467+
//sender.sendTl("dumpDeleteKey", result.getDeletionKey());
467468
if (sender.isPlayer()) {
468469
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpConsoleUrl", dumpUrl)));
469-
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpDeleteKey", result.getDeletionKey())));
470+
// pastes.dev doesn't support deletion keys
471+
//ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpDeleteKey", result.getDeletionKey())));
470472
}
471473
}
472474
files.clear();

Essentials/src/main/java/com/earth2me/essentials/utils/PasteUtil.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.google.common.io.CharStreams;
55
import com.google.gson.Gson;
66
import com.google.gson.JsonArray;
7-
import com.google.gson.JsonElement;
87
import com.google.gson.JsonObject;
98
import org.checkerframework.checker.nullness.qual.Nullable;
109

@@ -17,10 +16,11 @@
1716
import java.util.concurrent.CompletableFuture;
1817
import java.util.concurrent.ExecutorService;
1918
import java.util.concurrent.Executors;
19+
import java.util.zip.GZIPOutputStream;
2020

2121
public final class PasteUtil {
22-
private static final String PASTE_URL = "https://paste.gg/";
23-
private static final String PASTE_UPLOAD_URL = "https://api.paste.gg/v1/pastes";
22+
private static final String PASTE_URL = "https://pastes.dev/";
23+
private static final String PASTE_UPLOAD_URL = "https://api.pastes.dev/post";
2424
private static final ExecutorService PASTE_EXECUTOR_SERVICE = Executors.newSingleThreadExecutor();
2525
private static final Gson GSON = new Gson();
2626

@@ -42,7 +42,8 @@ public static CompletableFuture<PasteResult> createPaste(List<PasteFile> pages)
4242
connection.setDoInput(true);
4343
connection.setDoOutput(true);
4444
connection.setRequestProperty("User-Agent", "EssentialsX plugin");
45-
connection.setRequestProperty("Content-Type", "application/json");
45+
connection.setRequestProperty("Content-Type", "text/json");
46+
connection.setRequestProperty("Content-Encoding", "gzip");
4647
final JsonObject body = new JsonObject();
4748
final JsonArray files = new JsonArray();
4849
for (final PasteFile page : pages) {
@@ -56,24 +57,22 @@ public static CompletableFuture<PasteResult> createPaste(List<PasteFile> pages)
5657
}
5758
body.add("files", files);
5859

59-
try (final OutputStream os = connection.getOutputStream()) {
60+
try (final OutputStream os = new GZIPOutputStream(connection.getOutputStream())) {
6061
os.write(body.toString().getBytes(Charsets.UTF_8));
6162
}
6263

6364
if (connection.getResponseCode() >= 400) {
64-
//noinspection UnstableApiUsage
6565
future.completeExceptionally(new Error(CharStreams.toString(new InputStreamReader(connection.getErrorStream(), StandardCharsets.UTF_8))));
6666
return;
6767
}
6868

6969
// Read URL
7070
final JsonObject object = GSON.fromJson(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8), JsonObject.class);
71-
final String pasteId = object.get("result").getAsJsonObject().get("id").getAsString();
71+
final String pasteId = object.get("key").getAsString();
7272
final String pasteUrl = PASTE_URL + pasteId;
73-
final JsonElement deletionKey = object.get("result").getAsJsonObject().get("deletion_key");
7473
connection.disconnect();
7574

76-
final PasteResult result = new PasteResult(pasteId, pasteUrl, deletionKey != null ? deletionKey.getAsString() : null);
75+
final PasteResult result = new PasteResult(pasteId, pasteUrl, null);
7776
future.complete(result);
7877
} catch (Exception e) {
7978
future.completeExceptionally(e);

0 commit comments

Comments
 (0)