Пример #1
0
def put_head(request):
    storage = get_storage(request)
    userid = request.matchdict["userid"]
    new_head = json.loads(request.body)["head"]
    storage.set_head(userid, new_head)
    request.response.status = 204
    return request.response
Пример #2
0
def put_chunk(request):
    storage = get_storage(request)
    userid = request.matchdict["userid"]
    chunk = request.matchdict["chunk"]
    storage.create_chunk(userid, chunk, request.body)
    request.response.status = 201
    return request.response
Пример #3
0
def put_transaction(request):
    storage = get_storage(request)
    userid = request.matchdict["userid"]
    trnid = request.matchdict["transaction"]
    params = json.loads(request.body)
    parent = params["parent"]
    chunks = params["chunks"]
    storage.create_transaction(userid, trnid, parent, chunks)
    request.response.status = 201
    return request.response
Пример #4
0
def get_transactions(request):
    storage = get_storage(request)
    userid = request.matchdict["userid"]
    frm = request.GET.get("from", ROOT_TRANSACTION)
    limit = int(request.GET.get("limit", "100"))
    return {
        "from": frm,
        "limit": limit,
        "transactions": list(storage.get_transactions(userid, frm, limit)),
    }
Пример #5
0
def get_transaction(request):
    storage = get_storage(request)
    userid = request.matchdict["userid"]
    trnid = request.matchdict["transaction"]
    trn = storage.get_transaction(userid, trnid)
    return {
        "id": trn["id"],
        "seq": trn["seq"],
        "parent": trn["parent"],
        "chunks": trn["chunks"]
    }
Пример #6
0
def delete_root(request):
    storage = get_storage(request)
    userid = request.matchdict["userid"]
    storage.reset(userid)
    request.response.status = 204
    return request.response
Пример #7
0
def get_chunk(request):
    storage = get_storage(request)
    userid = request.matchdict["userid"]
    chunk = request.matchdict["chunk"]
    payload = storage.get_chunk(userid, chunk)
    return Response(payload)
Пример #8
0
def get_head(request):
    storage = get_storage(request)
    userid = request.matchdict["userid"]
    return {"head": storage.get_head(userid)}