]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/GetAttachmentCommand.java
Fix getUserStatus command with only username parameter
[signal-cli] / src / main / java / org / asamk / signal / commands / GetAttachmentCommand.java
index 6deed90a4b1d9fb2a63bd9f143e7cda74d43ad9f..99ba1ecaf332e79320eb45eac76ba87c1af256d1 100644 (file)
@@ -26,6 +26,7 @@ public class GetAttachmentCommand implements JsonRpcLocalCommand {
 
     @Override
     public void attachToSubparser(final Subparser subparser) {
 
     @Override
     public void attachToSubparser(final Subparser subparser) {
+        subparser.help("Retrieve an already downloaded attachment base64 encoded.");
         subparser.addArgument("--id").required(true).help("The ID of the attachment file.");
         var mut = subparser.addMutuallyExclusiveGroup().required(true);
         mut.addArgument("--recipient").help("Sender of the attachment");
         subparser.addArgument("--id").required(true).help("The ID of the attachment file.");
         var mut = subparser.addMutuallyExclusiveGroup().required(true);
         mut.addArgument("--recipient").help("Sender of the attachment");
@@ -40,12 +41,11 @@ public class GetAttachmentCommand implements JsonRpcLocalCommand {
         final var id = ns.getString("id");
 
         try (InputStream attachment = m.retrieveAttachment(id)) {
         final var id = ns.getString("id");
 
         try (InputStream attachment = m.retrieveAttachment(id)) {
-            if (outputWriter instanceof PlainTextWriter writer) {
-                final var bytes = attachment.readAllBytes();
-                final var base64 = Base64.getEncoder().encodeToString(bytes);
-                writer.println(base64);
-            } else if (outputWriter instanceof JsonWriter writer) {
-                writer.write(new JsonAttachmentData(attachment));
+            final var bytes = attachment.readAllBytes();
+            final var base64 = Base64.getEncoder().encodeToString(bytes);
+            switch (outputWriter) {
+                case PlainTextWriter writer -> writer.println(base64);
+                case JsonWriter writer -> writer.write(new JsonAttachmentData(base64));
             }
         } catch (FileNotFoundException ex) {
             throw new UserErrorException("Could not find attachment with ID: " + id, ex);
             }
         } catch (FileNotFoundException ex) {
             throw new UserErrorException("Could not find attachment with ID: " + id, ex);