From 26a65d100f91883027c17c219d018461968eda65 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Thu, 23 Mar 2017 20:33:20 -0300 Subject: [feature] add blobs listing --- server/src/leap/soledad/server/_blobs.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'server') 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) -- cgit v1.2.3