mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +01:00
Add method for listing folders with files available
for download (owner only)
This commit is contained in:
@@ -96,6 +96,17 @@ interface MailboxApi {
|
||||
void deleteFile(MailboxProperties properties, String folderId,
|
||||
String fileId) throws IOException, ApiException;
|
||||
|
||||
/**
|
||||
* Lists all contact outboxes that have files available
|
||||
* for the owner to download.
|
||||
*
|
||||
* @return a list of folder names
|
||||
* to be used with {@link #getFiles(MailboxProperties, String)}.
|
||||
* @throws IllegalArgumentException if used by non-owner.
|
||||
*/
|
||||
List<String> getFolders(MailboxProperties properties)
|
||||
throws IOException, ApiException;
|
||||
|
||||
@Immutable
|
||||
@JsonSerialize
|
||||
class MailboxContact {
|
||||
|
||||
@@ -234,6 +234,39 @@ class MailboxApiImpl implements MailboxApi {
|
||||
if (response.code() != 200) throw new ApiException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFolders(MailboxProperties properties)
|
||||
throws IOException, ApiException {
|
||||
if (!properties.isOwner()) throw new IllegalArgumentException();
|
||||
Response response = sendGetRequest(properties, "/folders");
|
||||
if (response.code() != 200) throw new ApiException();
|
||||
|
||||
ResponseBody body = response.body();
|
||||
if (body == null) throw new ApiException();
|
||||
try {
|
||||
JsonNode node = mapper.readTree(body.string());
|
||||
JsonNode filesNode = node.get("folders");
|
||||
if (filesNode == null || !filesNode.isArray()) {
|
||||
throw new ApiException();
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
for (JsonNode fileNode : filesNode) {
|
||||
if (!fileNode.isObject()) throw new ApiException();
|
||||
ObjectNode objectNode = (ObjectNode) fileNode;
|
||||
JsonNode idNode = objectNode.get("id");
|
||||
if (idNode == null || !idNode.isTextual()) {
|
||||
throw new ApiException();
|
||||
}
|
||||
String id = idNode.asText();
|
||||
if (!isValidToken(id)) throw new ApiException();
|
||||
list.add(id);
|
||||
}
|
||||
return list;
|
||||
} catch (JacksonException e) {
|
||||
throw new ApiException();
|
||||
}
|
||||
}
|
||||
|
||||
/* Helper Functions */
|
||||
|
||||
private Response sendGetRequest(MailboxProperties properties, String path)
|
||||
|
||||
Reference in New Issue
Block a user