0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/spec/system/page_objects/modals/share_target.rb
Rafael dos Santos Silva 6167f3bbac
FEATURE: Accept shared files via the Web Share Target (#41030)
Previously, Discourse only registered as a Level 1 Web Share Target — a
`GET` text-only handler that could not receive images or other files
from the OS share sheet.

This change registers a modern `POST`/`multipart/form-data` share
target. The service worker intercepts the incoming share, stashes the
shared title, text, url, and files in the Cache API, and redirects to a
`share-target` route that opens a modal asking whether to start a new
topic, a new message, or save the content to add to the next reply.
Topics and messages open the composer pre-filled with the shared text
and uploaded files; the reply option buffers the content and injects it
into the next reply composer that opens.

### Notes
- The file `accept` list covers images, video, audio, PDFs, and common
document types; the server still enforces `authorized_extensions`.
- Adds a `composer:uploader-ready` app event so shared files are only
handed to the uploader once it is bound, avoiding a race on cold
composer open.
- Only Android Chromium-based browsers currently implement file-capable
share targets; iOS has no Web Share Target support.

---------

Co-authored-by: Penar Musaraj <pmusaraj@gmail.com>
2026-06-18 17:35:09 -03:00

19 lines
431 B
Ruby
Vendored

# frozen_string_literal: true
module PageObjects
module Modals
class ShareTarget < PageObjects::Modals::Base
def initialize
super(modal_selector: ".share-target-modal")
end
def click_new_topic
footer.find(".share-target-modal__new-topic").click
end
def has_preview_text?(text)
body.has_css?(".share-target-modal__preview-text", text: text)
end
end
end
end