mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-02 04:20:38 +00:00
Minor improvements to GetAttachmentCommand
This commit is contained in:
parent
14c339a04c
commit
188149a51a
2 changed files with 13 additions and 3 deletions
|
@ -5,12 +5,14 @@ import net.sourceforge.argparse4j.inf.Subparser;
|
|||
|
||||
import org.asamk.signal.commands.exceptions.CommandException;
|
||||
import org.asamk.signal.commands.exceptions.UnexpectedErrorException;
|
||||
import org.asamk.signal.commands.exceptions.UserErrorException;
|
||||
import org.asamk.signal.json.JsonAttachmentData;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.output.JsonWriter;
|
||||
import org.asamk.signal.output.OutputWriter;
|
||||
import org.asamk.signal.output.PlainTextWriter;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Base64;
|
||||
|
@ -25,7 +27,14 @@ public class GetAttachmentCommand implements JsonRpcLocalCommand {
|
|||
@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");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,10 +53,11 @@ public class GetAttachmentCommand implements JsonRpcLocalCommand {
|
|||
|
||||
if (outputWriter instanceof PlainTextWriter writer) {
|
||||
writer.println(base64);
|
||||
}
|
||||
else if (outputWriter instanceof JsonWriter writer) {
|
||||
} else if (outputWriter instanceof JsonWriter writer) {
|
||||
writer.write(new JsonAttachmentData(base64));
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new UserErrorException("Could not find attachment with ID: " + id);
|
||||
} catch (IOException ex) {
|
||||
throw new UnexpectedErrorException("An error occurred reading attachment: " + id, ex);
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
package org.asamk.signal.json;
|
||||
|
||||
public record JsonAttachmentData(String dataBase64) {}
|
||||
public record JsonAttachmentData(String data) {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue