fix call to proofs

This commit is contained in:
Cayo Puigdefabregas 2024-11-28 18:48:50 +01:00
parent 1e08f0fc0c
commit 81e7ba267d

View file

@ -1,11 +1,13 @@
import json
import logging import logging
from django.views.generic.edit import View from django.views.generic.edit import View
from django.http import JsonResponse from django.http import JsonResponse
from evidence.xapian import search
from dpp.models import Proof
from dpp.api_dlt import ALGORITHM from dpp.api_dlt import ALGORITHM
from evidence.models import Evidence
from evidence.parse import Build
from dpp.models import Proof
logger = logging.getLogger('django') logger = logging.getLogger('django')
@ -20,27 +22,23 @@ class ProofView(View):
proof = Proof.objects.filter(timestamp=timestamp).first() proof = Proof.objects.filter(timestamp=timestamp).first()
if not proof: if not proof:
return JsonResponse({}, status=404) return JsonResponse({}, status=404)
ev_uuid = 'uuid:"{}"'.format(proof.uuid) ev = Evidence(proof.uuid)
matches = search(None, ev_uuid, limit=1) if not ev.doc:
if not matches or matches.size() < 1:
return JsonResponse({}, status=404) return JsonResponse({}, status=404)
for x in matches: dev = Build(ev.doc, None, check=True)
snap = x.document.get_data() doc = dev.get_phid()
data = {
"algorithm": ALGORITHM,
"document": snap
}
d = { data = {
'@context': ['https://ereuse.org/proof0.json'], "algorithm": ALGORITHM,
'data': data, "document": json.dumps(doc)
} }
response = JsonResponse(d, status=200)
response["Access-Control-Allow-Origin"] = "*"
return response
return JsonResponse({}, status=404)
d = {
'@context': ['https://ereuse.org/proof0.json'],
'data': data,
}
response = JsonResponse(d, status=200)
response["Access-Control-Allow-Origin"] = "*"
return response