From 701dc4f4086915a396a7e8f3a8ec7dc73069bdac Mon Sep 17 00:00:00 2001 From: pedro Date: Mon, 14 Oct 2024 13:45:08 +0200 Subject: [PATCH] workbench snapshot api: return dhid and public url --- api/views.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/api/views.py b/api/views.py index cfb7d6e..6dafbd2 100644 --- a/api/views.py +++ b/api/views.py @@ -1,3 +1,4 @@ +import logging import json from django.urls import reverse_lazy @@ -22,6 +23,7 @@ from user.models import User from api.models import Token from api.tables import TokensTable +logger = logging.getLogger(__name__) def save_in_disk(data, user): pass @@ -65,13 +67,23 @@ def NewSnapshot(request): # save_in_disk(data, tk.user) try: - Build(data, tk.owner) - except Exception: + snapshot_build = Build(data, tk.owner) + # TODO this is hardcoded, it should select the user preferred algorithm + dhid = snapshot_build.get_hid_14() + shortid = dhid[:6] + device_url = request.build_absolute_uri("/device") + response = { + 'status': 'success', + 'public_url': f"{device_url}/{dhid}", + 'dhid': shortid, + } + except Exception as e: + logger.error(e) return JsonResponse({'status': 'fail'}, status=200) - return JsonResponse({'status': 'success'}, status=200) + return JsonResponse(response, status=200) class TokenView(DashboardView, SingleTableView): -- 2.30.2