Skip to content
Snippets Groups Projects
Unverified Commit ae7e2989 authored by Simon Désaulniers's avatar Simon Désaulniers
Browse files

http_server: put values, specific user_type,vid

parent 7197c1fb
No related branches found
No related tags found
No related merge requests found
......@@ -42,13 +42,22 @@ class DhtServer(resource.Resource):
def render_POST(self, req):
uri = req.uri[1:]
data = req.args[b'data'][0] if b'data' in req.args else None
user_type = req.args[b'user_type'][0].decode() if b'user_type' in req.args else ""
try:
vid = int(req.args[b'id'][0].decode()) if b'id' in req.args else 0
except ValueError:
vid = 0
if not data and b'base64' in req.args:
data = base64.b64decode(req.args[b'base64'][0])
h = dht.InfoHash(uri) if len(uri) == 40 else dht.InfoHash.get(uri.decode())
print('POST', h, data)
req.setHeader(b"content-type", b"application/json")
if data:
self.node.put(h, dht.Value(data))
v = dht.Value(data)
if vid != 0:
v.id = vid
v.user_type = user_type
self.node.put(h, v)
return json.dumps({'success':True}).encode()
else:
req.setResponseCode(400)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment