Support sharing to the app via the Web Share Target API#9929
Open
bdolgov wants to merge 2 commits into
Open
Conversation
Two dev-environment fixes that surfaced while testing the PWA locally: - assets.ts: allow extra Vite hosts via the TRILIUM_DEV_ALLOWED_HOSTS env var (comma-separated). Vite 5+ rejects any Host other than localhost, so reaching the dev server through a reverse proxy or LAN hostname otherwise fails with "Blocked request" / dynamic-import errors. Inert when unset. - app.ts: serve manifest.webmanifest, icon.png and robots.txt from the dev/prod-aware getClientDir() instead of dist/public. In dev, dist/public is never built, so these 404'd (the PWA manifest could not be fetched). Prod behaviour is unchanged (getClientDir() resolves to the built public dir there). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Code Review
This pull request implements the PWA Web Share Target API, enabling users to share text, URLs, and files directly to Trilium. Key changes include updating the web manifest, adding a new server-side route handler with unit tests, and refactoring the upload middleware to support multi-file uploads. Feedback highlights an inconsistency in the isProtected flag for images, a logic issue where text/URLs are ignored if files are present, and a typo in a file size error message.
8829162 to
1c3ff3e
Compare
Lets the installed PWA receive content from the OS share sheet and turn it into a note in the inbox. - manifest.webmanifest: declare a POST/multipart share_target at /share-target accepting title, text, url and a files array. - routes/api/share_target.ts: new handler. Shared text becomes an HTML text note (escaped, newlines -> <br>); a shared url becomes a linked text note with a pageUrl label; shared files become image or file notes. Notes are created in the inbox and tagged with a sharedToTrilium label; responds with a 303 redirect to the new note. Pure helpers (deriveTitle, buildBody, getOptionalString) are unit-tested in share_target.spec.ts. - route_api.ts: add createMultiUploadMiddleware(WithErrorHandling) using multer .array() so the share target can receive multiple files, factoring the shared multer setup out of createUploadMiddleware. - routes.ts: register POST /share-target behind session auth (no CSRF token is possible from the browser's share UI; SameSite=Lax cookies prevent cross-site POSTs from carrying credentials). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets the installed PWA receive content from the OS share sheet and turn it into a note in the inbox.
Also includes improvements to test PWA locally via Cloudflare Tunnel or similar setup that exploses devserver under a different host.