Add command to get an attachment

This commit is contained in:
cedb 2022-10-31 17:52:42 -04:00
parent 49aaff2bbe
commit 589f5378df
9 changed files with 97 additions and 0 deletions

View file

@ -0,0 +1,3 @@
package org.asamk.signal.manager;
public record AttachmentPointer(String id, String fileName, String contentType) {}

View file

@ -39,6 +39,12 @@ public class AttachmentStore {
Optional.ofNullable(pointer.getContentType()));
}
public File getAttachmentFile(AttachmentPointer pointer) {
return getAttachmentFile(SignalServiceAttachmentRemoteId.from(pointer.id()),
Optional.ofNullable(pointer.fileName()),
Optional.ofNullable(pointer.contentType()));
}
private void storeAttachment(final File attachmentFile, final AttachmentStorer storer) throws IOException {
createAttachmentsDir();
try (OutputStream output = new FileOutputStream(attachmentFile)) {

View file

@ -272,6 +272,8 @@ public interface Manager extends Closeable {
void addClosedListener(Runnable listener);
File getAttachmentFile(AttachmentPointer pointer);
@Override
void close() throws IOException;

View file

@ -1147,6 +1147,10 @@ class ManagerImpl implements Manager {
}
}
public File getAttachmentFile(AttachmentPointer pointer) {
return context.getAttachmentHelper().getAttachmentFile(pointer);
}
@Override
public void close() {
Thread thread;

View file

@ -1,5 +1,6 @@
package org.asamk.signal.manager.helper;
import org.asamk.signal.manager.AttachmentPointer;
import org.asamk.signal.manager.AttachmentStore;
import org.asamk.signal.manager.SignalDependencies;
import org.asamk.signal.manager.api.AttachmentInvalidException;
@ -38,6 +39,11 @@ public class AttachmentHelper {
return attachmentStore.getAttachmentFile(pointer);
}
public File getAttachmentFile(AttachmentPointer pointer) {
return attachmentStore.getAttachmentFile(pointer);
}
public List<SignalServiceAttachment> uploadAttachments(final List<String> attachments) throws AttachmentInvalidException, IOException {
var attachmentStreams = AttachmentUtils.createAttachmentStreams(attachments);