]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/commands/GetAttachmentCommand.java
Update libsignal-service-java
[signal-cli] / src / main / java / org / asamk / signal / commands / GetAttachmentCommand.java
index 560be9f9071418a810e90cd41c5a4383917e87ba..99ba1ecaf332e79320eb45eac76ba87c1af256d1 100644 (file)
@@ -26,33 +26,26 @@ public class GetAttachmentCommand implements JsonRpcLocalCommand {
 
     @Override
     public void attachToSubparser(final Subparser subparser) {
 
     @Override
     public void attachToSubparser(final Subparser subparser) {
-        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");
-        mut.addArgument("-g", "--group-id")
-                .help("Group in which the attachment was received");
+        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");
+        mut.addArgument("-g", "--group-id").help("Group in which the attachment was received");
     }
 
     @Override
     public void handleCommand(
     }
 
     @Override
     public void handleCommand(
-            final Namespace ns,
-            final Manager m,
-            final OutputWriter outputWriter
+            final Namespace ns, final Manager m, final OutputWriter outputWriter
     ) throws CommandException {
 
         final var id = ns.getString("id");
 
     ) throws CommandException {
 
         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));
+        try (InputStream attachment = m.retrieveAttachment(id)) {
+            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);