BTHLABS-65: Implement support for Win 11 payload in PWA share sheet endpoint

Co-authored-by: Tomek Wójcik <labs@tomekwojcik.pl>
Co-committed-by: Tomek Wójcik <labs@tomekwojcik.pl>
This commit is contained in:
2025-11-12 19:30:33 +00:00
committed by Tomek Wójcik
parent ac9c7a81c3
commit b358ef6686
7 changed files with 81 additions and 49 deletions

View File

@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
import http
import logging
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
from hotpocket_backend.apps.accounts.decorators import account_required
from hotpocket_backend.apps.ui.services.workflows import CreateSaveWorkflow
LOGGER = logging.getLogger(__name__)
@csrf_exempt
@account_required
def share_sheet(request: HttpRequest) -> HttpResponse:
LOGGER.debug('POST=`%s`', request.POST)
try:
assert request.user.is_anonymous is False, 'Login required'
url: str = ''
if 'url' in request.POST:
url = request.POST['url'].strip()
elif 'text' in request.POST:
url = request.POST['text'].split('\n')[0].strip()
assert url != '', 'Bad request: Empty `url`'
return CreateSaveWorkflow().run(
request=request,
account=request.user,
url=url,
force_post_save=True,
)
except Exception as exception:
LOGGER.error(
'Unhandled exception: %s',
exception,
exc_info=exception,
)
return render(
request,
'ui/errors/internal_server_error.html',
# Returning 200 here to avoid browsers showing generic error pages.
status=http.HTTPStatus.OK,
)