From 7fc39b1d533f93b60e4a011f0e6e7682b6406050 Mon Sep 17 00:00:00 2001 From: Vankka Date: Sat, 22 Jun 2024 11:12:33 +0300 Subject: [PATCH] Reuse encoder for debugs --- .../common/command/combined/commands/DebugCommand.java | 2 +- .../main/java/com/discordsrv/common/debug/DebugReport.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/discordsrv/common/command/combined/commands/DebugCommand.java b/common/src/main/java/com/discordsrv/common/command/combined/commands/DebugCommand.java index 6965584e..aa191f50 100644 --- a/common/src/main/java/com/discordsrv/common/command/combined/commands/DebugCommand.java +++ b/common/src/main/java/com/discordsrv/common/command/combined/commands/DebugCommand.java @@ -86,7 +86,7 @@ public class DebugCommand extends CombinedCommand { } private static final String URL_FORMAT = DiscordSRV.WEBSITE + "/debug/%s#%s"; - private static final Base64.Encoder KEY_ENCODER = Base64.getUrlEncoder().withoutPadding(); + public static final Base64.Encoder KEY_ENCODER = Base64.getUrlEncoder().withoutPadding(); private final PasteService pasteService; diff --git a/common/src/main/java/com/discordsrv/common/debug/DebugReport.java b/common/src/main/java/com/discordsrv/common/debug/DebugReport.java index 3c8b0704..7e061db1 100644 --- a/common/src/main/java/com/discordsrv/common/debug/DebugReport.java +++ b/common/src/main/java/com/discordsrv/common/debug/DebugReport.java @@ -53,6 +53,8 @@ import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import static com.discordsrv.common.command.combined.commands.DebugCommand.KEY_ENCODER; + public class DebugReport { private static final int BIG_FILE_SPLIT_SIZE = 50000; @@ -101,7 +103,7 @@ public class DebugReport { try { Paste paste = service.uploadFile(convertToJson(file).toString().getBytes(StandardCharsets.UTF_8)); node.put("url", paste.url()); - node.put("decryption_key", new String(Base64.getUrlEncoder().encode(paste.decryptionKey()), StandardCharsets.UTF_8)); + node.put("decryption_key", new String(KEY_ENCODER.encode(paste.decryptionKey()), StandardCharsets.UTF_8)); node.put("length", length); } catch (Throwable e) { node.put("content", "Failed to upload file\n\n" + ExceptionUtils.getStackTrace(e));