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

@@ -78,9 +78,13 @@ urlpatterns = [
name='ui.integrations.ios.shortcut',
),
path(
# Turns out PWAs can register a share target in Windows 11 when
# installed through Edge. Neat, too. I wish I knew this when I defined
# this URL path. Now it's gonna stay forever like this due to backwards
# compat ;).
'integrations/android/share-sheet/',
integrations.android.share_sheet,
name='ui.integrations.android.share_sheet',
integrations.pwa.share_sheet,
name='ui.integrations.pwa.share_sheet',
),
path(
'integrations/extension/authenticate/',

View File

@@ -1,3 +1,3 @@
from . import android # noqa: F401
from . import extension # noqa: F401
from . import ios # noqa: F401
from . import pwa # noqa: F401

View File

@@ -21,10 +21,14 @@ def share_sheet(request: HttpRequest) -> HttpResponse:
try:
assert request.user.is_anonymous is False, 'Login required'
assert 'text' in request.POST, 'Bad request: Missing `text`'
url = request.POST['text'].split('\n')[0].strip()
assert url != '', 'Bad request: Empty `text`'
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,

View File

@@ -50,7 +50,7 @@ def manifest_json(request: HttpRequest) -> JsonResponse:
'scope': '/',
'share_target': {
'action': request.build_absolute_uri(
reverse('ui.integrations.android.share_sheet'),
reverse('ui.integrations.pwa.share_sheet'),
),
'method': 'POST',
'enctype': 'multipart/form-data',