summaryrefslogtreecommitdiff
path: root/server/src/leap
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-03-23 20:33:20 -0300
committerdrebs <drebs@leap.se>2017-04-04 18:27:38 +0200
commit26a65d100f91883027c17c219d018461968eda65 (patch)
tree1c2cdb4a8438aa730f4ac064cfe15ebf843e0740 /server/src/leap
parent45b73d58930a2a66394a6797c94a50c34e8f96e7 (diff)
[feature] add blobs listing
Diffstat (limited to 'server/src/leap')
-rw-r--r--server/src/leap/soledad/server/_blobs.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/server/src/leap/soledad/server/_blobs.py b/server/src/leap/soledad/server/_blobs.py
index 25266b18..3eac536e 100644
--- a/server/src/leap/soledad/server/_blobs.py
+++ b/server/src/leap/soledad/server/_blobs.py
@@ -27,6 +27,7 @@ environments.
import commands
import os
import base64
+import json
from twisted.logger import Logger
from twisted.web import static
@@ -65,6 +66,13 @@ class IBlobsBackend(Interface):
:returns: a deferred that fires upon finishing.
"""
+ def list_blobs(user, request):
+ """
+ Returns a json-encoded list of ids from user's blob.
+
+ :returns: a deferred that fires upon finishing.
+ """
+
def tag_header(user, blob_id, request):
"""
Adds a header 'Tag' with the last 20 bytes of the encoded file,
@@ -101,6 +109,13 @@ class FilesystemBlobsBackend(object):
os.makedirs(blobs_path)
self.path = blobs_path
+ def list_blobs(self, user, request):
+ blob_ids = []
+ base_path = os.path.join(self.path, user)
+ for _, _, filenames in os.walk(base_path):
+ blob_ids += filenames
+ return json.dumps(blob_ids)
+
def tag_header(self, user, blob_id, request):
with open(self._get_path(user, blob_id)) as doc_file:
doc_file.seek(-16, 2)
@@ -185,6 +200,8 @@ class BlobsResource(resource.Resource):
def render_GET(self, request):
logger.info("http get: %s" % request.path)
user, blob_id = request.postpath
+ if not blob_id:
+ return self._handler.list_blobs(user, request)
self._handler.tag_header(user, blob_id, request)
return self._handler.read_blob(user, blob_id, request)