summaryrefslogtreecommitdiff
path: root/server/src/leap
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-05-29 04:02:20 -0300
committerVictor Shyba <victor1984@riseup.net>2017-07-02 01:32:39 -0300
commit7ef11157c9af8dcddbc52f063f8f362bddc6c36f (patch)
treea3925efbeb2d059c0cc62188157360474fa1b0e1 /server/src/leap
parent154cfabeca53258e547adfb5ce815a59f8eff59c (diff)
[feature] make /incoming persist doc on CouchDB
-- Resolves: #8827
Diffstat (limited to 'server/src/leap')
-rw-r--r--server/src/leap/soledad/server/_incoming.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/server/src/leap/soledad/server/_incoming.py b/server/src/leap/soledad/server/_incoming.py
index 1583e362..a9845af1 100644
--- a/server/src/leap/soledad/server/_incoming.py
+++ b/server/src/leap/soledad/server/_incoming.py
@@ -18,11 +18,30 @@
A twisted resource that saves externally delivered documents into user's db.
"""
from twisted.web.resource import Resource
+from leap.soledad.common.document import ServerDocument
+from ._config import get_config
+from leap.soledad.common.couch.state import CouchServerState
+import json
__all__ = ['IncomingResource']
+def _default_backend():
+ conf = get_config()
+ return CouchServerState(conf['couch_url'], create_cmd=conf['create_cmd'])
+
+
class IncomingResource(Resource):
+ isLeaf = True
+
+ def __init__(self, backend_factory=None):
+ self.factory = backend_factory or _default_backend()
+
def render_PUT(self, request):
+ uuid, doc_id = request.postpath
+ db = self.factory.open_database(uuid)
+ doc = ServerDocument(doc_id)
+ doc.content = json.loads(request.content.read())
+ db.put_doc(doc)
return ''