summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2017-12-08 22:34:34 -0200
committerdrebs <drebs@leap.se>2017-12-13 13:49:27 -0200
commit7aa8e9496e74f8f1265bf008ae412a3f733ea2b4 (patch)
treea0e62b96d3a2da3d5cada84f3c8ebd421c9952a6 /src
parent96dff026a7b58d116543b4f181c93946e04894b0 (diff)
[refactor] make list_blobs() return a deferred
Diffstat (limited to 'src')
-rw-r--r--src/leap/soledad/server/_blobs.py13
-rw-r--r--src/leap/soledad/server/interfaces.py4
2 files changed, 12 insertions, 5 deletions
diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py
index 42c00841..7210cb6a 100644
--- a/src/leap/soledad/server/_blobs.py
+++ b/src/leap/soledad/server/_blobs.py
@@ -184,7 +184,7 @@ class FilesystemBlobsBackend(object):
blob_ids = list(self._filter_flag(blob_ids, filter_flag))
blob_ids = [os.path.basename(path).replace('.deleted', '')
for path in blob_ids]
- return blob_ids
+ return defer.succeed(blob_ids)
def _filter_flag(self, blob_paths, flag):
for blob_path in blob_paths:
@@ -288,10 +288,13 @@ class BlobsResource(resource.Resource):
order = request.args.get('order_by', [None])[0]
filter_flag = request.args.get('filter_flag', [False])[0]
deleted = request.args.get('deleted', [False])[0]
- blobs = self._handler.list_blobs(user, namespace,
- order_by=order, deleted=deleted,
- filter_flag=filter_flag)
- return json.dumps(blobs)
+ d = self._handler.list_blobs(user, namespace,
+ order_by=order, deleted=deleted,
+ filter_flag=filter_flag)
+ d.addCallback(lambda blobs: json.dumps(blobs))
+ d.addCallback(lambda blobs: request.write(blobs))
+ d.addCallback(lambda _: request.finish())
+ return NOT_DONE_YET
only_flags = request.args.get('only_flags', [False])[0]
try:
if only_flags:
diff --git a/src/leap/soledad/server/interfaces.py b/src/leap/soledad/server/interfaces.py
index a1762647..7009cb85 100644
--- a/src/leap/soledad/server/interfaces.py
+++ b/src/leap/soledad/server/interfaces.py
@@ -127,6 +127,10 @@ class IBlobsBackend(Interface):
:return: A list of blob ids, optionally ordered and/or restricted by
namespace.
:rtype: list of str
+
+ :return: A deferred that fires with a list of blob ids, optionally
+ ordered and/or restricted by namespace.
+ :rtype: twisted.internet.defer.Deferred
"""
def get_total_storage(user):