Add method for deleting a file from a mailbox

This commit is contained in:
Torsten Grote
2022-01-21 12:08:52 -03:00
parent 0cb2dcf6b7
commit 482258fc92
3 changed files with 61 additions and 0 deletions

View File

@@ -88,6 +88,14 @@ interface MailboxApi {
void getFile(MailboxProperties properties, String folderId,
String fileId, File file) throws IOException, ApiException;
/**
* Used by owner and contacts to delete files.
* <p>
* Returns 200 OK (no exception) if deletion was successful.
*/
void deleteFile(MailboxProperties properties, String folderId,
String fileId) throws IOException, ApiException;
@Immutable
@JsonSerialize
class MailboxContact {

View File

@@ -221,6 +221,19 @@ class MailboxApiImpl implements MailboxApi {
copyAndClose(body.byteStream(), outputStream);
}
@Override
public void deleteFile(MailboxProperties properties, String folderId,
String fileId) throws IOException, ApiException {
String path = "/files/" + folderId + "/" + fileId;
Request request = getRequestBuilder(properties.getAuthToken())
.delete()
.url(properties.getOnionAddress() + path)
.build();
OkHttpClient client = httpClientProvider.get();
Response response = client.newCall(request).execute();
if (response.code() != 200) throw new ApiException();
}
/* Helper Functions */
private Response sendGetRequest(MailboxProperties properties, String path)