mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-02 05:21:52 +01:00
Switch to pastes.dev for /ess dump (#6011)
Requires merge of https://github.com/EssentialsX/Website/pull/106
This commit is contained in:
parent
667b0f7523
commit
803771e74a
@ -461,12 +461,14 @@ public class Commandessentials extends EssentialsCommand {
|
|||||||
final CompletableFuture<PasteUtil.PasteResult> future = PasteUtil.createPaste(files);
|
final CompletableFuture<PasteUtil.PasteResult> future = PasteUtil.createPaste(files);
|
||||||
future.thenAccept(result -> {
|
future.thenAccept(result -> {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
final String dumpUrl = "https://essentialsx.net/dump.html?id=" + result.getPasteId();
|
final String dumpUrl = "https://essentialsx.net/dump.html?bytebin=" + result.getPasteId();
|
||||||
sender.sendTl("dumpUrl", dumpUrl);
|
sender.sendTl("dumpUrl", dumpUrl);
|
||||||
sender.sendTl("dumpDeleteKey", result.getDeletionKey());
|
// pastes.dev doesn't support deletion keys
|
||||||
|
//sender.sendTl("dumpDeleteKey", result.getDeletionKey());
|
||||||
if (sender.isPlayer()) {
|
if (sender.isPlayer()) {
|
||||||
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpConsoleUrl", dumpUrl)));
|
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpConsoleUrl", dumpUrl)));
|
||||||
ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpDeleteKey", result.getDeletionKey())));
|
// pastes.dev doesn't support deletion keys
|
||||||
|
//ess.getLogger().info(AdventureUtil.miniToLegacy(tlLiteral("dumpDeleteKey", result.getDeletionKey())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
files.clear();
|
files.clear();
|
||||||
|
@ -4,7 +4,6 @@ import com.google.common.base.Charsets;
|
|||||||
import com.google.common.io.CharStreams;
|
import com.google.common.io.CharStreams;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
@ -17,10 +16,11 @@ import java.util.List;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
public final class PasteUtil {
|
public final class PasteUtil {
|
||||||
private static final String PASTE_URL = "https://paste.gg/";
|
private static final String PASTE_URL = "https://pastes.dev/";
|
||||||
private static final String PASTE_UPLOAD_URL = "https://api.paste.gg/v1/pastes";
|
private static final String PASTE_UPLOAD_URL = "https://api.pastes.dev/post";
|
||||||
private static final ExecutorService PASTE_EXECUTOR_SERVICE = Executors.newSingleThreadExecutor();
|
private static final ExecutorService PASTE_EXECUTOR_SERVICE = Executors.newSingleThreadExecutor();
|
||||||
private static final Gson GSON = new Gson();
|
private static final Gson GSON = new Gson();
|
||||||
|
|
||||||
@ -42,7 +42,8 @@ public final class PasteUtil {
|
|||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
connection.setRequestProperty("User-Agent", "EssentialsX plugin");
|
connection.setRequestProperty("User-Agent", "EssentialsX plugin");
|
||||||
connection.setRequestProperty("Content-Type", "application/json");
|
connection.setRequestProperty("Content-Type", "text/json");
|
||||||
|
connection.setRequestProperty("Content-Encoding", "gzip");
|
||||||
final JsonObject body = new JsonObject();
|
final JsonObject body = new JsonObject();
|
||||||
final JsonArray files = new JsonArray();
|
final JsonArray files = new JsonArray();
|
||||||
for (final PasteFile page : pages) {
|
for (final PasteFile page : pages) {
|
||||||
@ -56,24 +57,22 @@ public final class PasteUtil {
|
|||||||
}
|
}
|
||||||
body.add("files", files);
|
body.add("files", files);
|
||||||
|
|
||||||
try (final OutputStream os = connection.getOutputStream()) {
|
try (final OutputStream os = new GZIPOutputStream(connection.getOutputStream())) {
|
||||||
os.write(body.toString().getBytes(Charsets.UTF_8));
|
os.write(body.toString().getBytes(Charsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connection.getResponseCode() >= 400) {
|
if (connection.getResponseCode() >= 400) {
|
||||||
//noinspection UnstableApiUsage
|
|
||||||
future.completeExceptionally(new Error(CharStreams.toString(new InputStreamReader(connection.getErrorStream(), StandardCharsets.UTF_8))));
|
future.completeExceptionally(new Error(CharStreams.toString(new InputStreamReader(connection.getErrorStream(), StandardCharsets.UTF_8))));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read URL
|
// Read URL
|
||||||
final JsonObject object = GSON.fromJson(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8), JsonObject.class);
|
final JsonObject object = GSON.fromJson(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8), JsonObject.class);
|
||||||
final String pasteId = object.get("result").getAsJsonObject().get("id").getAsString();
|
final String pasteId = object.get("key").getAsString();
|
||||||
final String pasteUrl = PASTE_URL + pasteId;
|
final String pasteUrl = PASTE_URL + pasteId;
|
||||||
final JsonElement deletionKey = object.get("result").getAsJsonObject().get("deletion_key");
|
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
|
|
||||||
final PasteResult result = new PasteResult(pasteId, pasteUrl, deletionKey != null ? deletionKey.getAsString() : null);
|
final PasteResult result = new PasteResult(pasteId, pasteUrl, null);
|
||||||
future.complete(result);
|
future.complete(result);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
future.completeExceptionally(e);
|
future.completeExceptionally(e);
|
||||||
|
Loading…
Reference in New Issue
Block a user