Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

feat: share target pwa support

Smaug6739b55701d018bc
diff --git a/frontend/app/components/Node/Resource/Inline.vue b/frontend/app/components/Node/Resource/Inline.vue
new file mode 100644
index 00000000..6569c09a
--- /dev/null
+++ b/frontend/app/components/Node/Resource/Inline.vue
@@ -0,0 +1,87 @@
+<template>
+ <div class="file-card">
+ <img v-if="file.preview" :src="file.preview" :alt="file.name" class="file-preview" />
+ <Icon v-else :name="resolveFileIcon(file.file.type)" display="lg" />
+ <div class="file-info">
+ <span class="file-name">{{ file.name }}</span>
+ <span class="file-size">{{ readableFileSize(file.file.size) }}</span>
+ </div>
+ <button class="file-remove" @click="removeFile">
+ <Icon name="close" />
+ </button>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { readableFileSize, resolveFileIcon } from '~/helpers/resources';
+
+interface SharedFile {
+ name: string;
+ preview?: string;
+ file: File;
+}
+
+defineProps<{
+ file: SharedFile;
+ removeFile: () => void;
+}>();
+</script>
+
+<style scoped lang="scss">
+.file-card {
+ display: flex;
+ align-items: center;
+ gap: 0.75rem;
+ padding: 0.75rem;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--border);
+
+ .file-preview {
+ width: 48px;
+ height: 48px;
+ border-radius: var(--radius-sm);
+ object-fit: cover;
+ }
+
+ .file-icon {
+ width: 48px;
+ height: 48px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ border-radius: var(--radius-sm);
+ color: var(--text-muted);
+ }
+
+ .file-info {
+ flex: 1;
+ min-width: 0;
+
+ .file-name {
+ display: block;
+ font-weight: 500;
+ color: var(--text-body);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+
+ .file-size {
+ font-size: 0.8rem;
+ color: var(--text-muted);
+ }
+ }
+
+ .file-remove {
+ padding: 0.25rem;
+ border-radius: var(--radius-sm);
+ color: var(--text-muted);
+ cursor: pointer;
+
+ &:hover {
+ background: var(--bg-tertiary);
+ color: var(--red);
+ }
+ }
+}
+</style>
diff --git a/frontend/app/pages/dashboard/share-target.vue b/frontend/app/pages/dashboard/share-target.vue
new file mode 100644
index 00000000..52965ffd
--- /dev/null
+++ b/frontend/app/pages/dashboard/share-target.vue
@@ -0,0 +1,323 @@
+<template>
+ <div class="page-card">
+ <h2 class="page-title"><Icon name="share" /> Shared Content</h2>
+ <p class="page-subtitle">Content received from another app.</p>
+
+ <Loader v-if="loading" />
+
+ <div v-else class="share-content">
+ <h2>Shared content</h2>
+ <!-- Shared text / URL preview -->
+ <section v-if="sharedText || sharedUrl" class="share-section">
+ <div class="preview-card">
+ <h3 v-if="sharedTitle">{{ sharedTitle }}</h3>
+ <p v-if="sharedText" class="shared-text">{{ sharedText }}</p>
+ <a v-if="sharedUrl" :href="sharedUrl" target="_blank" rel="noopener" class="shared-url">
+ {{ sharedUrl }}
+ </a>
+ </div>
+ </section>
+
+ <!-- Shared files preview -->
+ <section v-if="sharedFiles.length" class="share-section">
+ <div class="files-grid">
+ <NodeResourceInline v-for="(file, index) in sharedFiles" :key="index" :file="file" :remove-file="() => removeFile(index)" class="file-card" />
+ </div>
+ </section>
+
+ <section>
+ <label>Choose destination</label>
+ <AppSelect v-model="parentId" :items="categories" nullable placeholder="Select a workspace or category (optional)" />
+ </section>
+
+ <!-- Action: create note or upload files -->
+ <section class="share-actions">
+ <h2>What would you like to do?</h2>
+
+ <!-- Create note from shared content -->
+ <div class="action-card" @click="createNote">
+ <div class="action-icon">
+ <Icon name="document" />
+ </div>
+ <div class="action-info">
+ <h3>Create a new document</h3>
+ <p>Create a new Markdown document with the shared content</p>
+ </div>
+ </div>
+
+ <!-- Upload files if there are shared files -->
+ <div v-if="sharedFiles.length" class="action-card" @click="uploadFiles">
+ <div class="action-icon">
+ <Icon name="upload" />
+ </div>
+ <div class="action-info">
+ <h3>Upload as resources</h3>
+ <p>Upload the shared files to your resource library</p>
+ </div>
+ </div>
+ </section>
+ </div>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import type { Node } from '~/stores';
+
+definePageMeta({ breadcrumb: 'Share' });
+
+const nodesStore = useNodesStore();
+const resourcesStore = useResourcesStore();
+
+const notifications = useNotifications();
+const router = useRouter();
+const nodesTree = useNodesTree();
+
+const loading = ref(true);
+const sharedTitle = ref('');
+const sharedText = ref('');
+const sharedUrl = ref('');
+const sharedFiles = ref<{ name: string; file: File; preview?: string }[]>([]);
+const parentId = ref<string | undefined>(undefined);
+const processing = ref(false);
+
+const categories = nodesTree.categoriesTree;
+
+onMounted(async () => {
+ await retrieveSharedData();
+ loading.value = false;
+});
+
+/**
+ * Retrieve shared data from the service worker cache (POST share)
+ * or from URL query params (GET share fallback)
+ */
+async function retrieveSharedData() {
+ // Try to get data from the service worker cache (POST with files)
+ try {
+ const cache = await caches.open('share-target-cache');
+ const cachedResponse = await cache.match('/share-target-data');
+
+ if (!cachedResponse) throw new Error('No cached share data found');
+ const formData = await cachedResponse.formData();
+
+ sharedTitle.value = formData.get('title')?.toString() || '';
+ sharedText.value = formData.get('text')?.toString() || '';
+ sharedUrl.value = formData.get('url')?.toString() || '';
+
+ const files = formData.getAll('files') as File[];
+ for (const file of files) {
+ if (file && file.size > 0) {
+ const preview = file.type.startsWith('image/') ? URL.createObjectURL(file) : undefined;
+ sharedFiles.value.push({ name: file.name, file, preview });
+ }
+ }
+
+ // Clean up cache after reading
+ await cache.delete('/share-target-data');
+ } catch (e) {
+ console.warn('[share-target] Could not read from cache:', e);
+ }
+
+ // Fallback: URL query params (GET share, or simple text share)
+ const route = useRoute();
+ if (!sharedTitle.value && route.query.title) sharedTitle.value = route.query.title as string;
+ if (!sharedText.value && route.query.text) sharedText.value = route.query.text as string;
+ if (!sharedUrl.value && route.query.url) sharedUrl.value = route.query.url as string;
+}
+
+function removeFile(index: number) {
+ const file = sharedFiles.value[index];
+ if (file?.preview) URL.revokeObjectURL(file.preview);
+ sharedFiles.value.splice(index, 1);
+}
+
+/** Build markdown content from shared data */
+function buildMarkdownContent(): string {
+ const parts: string[] = [];
+
+ if (sharedText.value) {
+ parts.push(sharedText.value);
+ }
+
+ if (sharedUrl.value) {
+ parts.push(`[${sharedUrl.value}](${sharedUrl.value})`);
+ }
+
+ // If text files were shared, include their content
+ // (handled async in createNote)
+ return parts.join('\n\n');
+}
+
+async function readTextFile(file: File): Promise<string> {
+ return new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.onload = () => resolve(reader.result as string);
+ reader.onerror = () => reject(reader.error);
+ reader.readAsText(file);
+ });
+}
+
+async function createNote() {
+ if (processing.value) return;
+ processing.value = true;
+
+ try {
+ let content = buildMarkdownContent();
+ const title = sharedTitle.value || sharedText.value?.slice(0, 50) || 'Shared note';
+
+ // Append text file contents to the note
+ for (const sharedFile of sharedFiles.value) {
+ if (sharedFile.file.type.startsWith('text/') || sharedFile.name.endsWith('.md') || sharedFile.name.endsWith('.txt')) {
+ const text = await readTextFile(sharedFile.file);
+ content += `\n\n---\n\n## ${sharedFile.name}\n\n${text}`;
+ }
+ }
+
+ const doc: Partial<Node> = {
+ name: title,
+ content: content,
+ parent_id: parentId.value || undefined,
+ accessibility: 1,
+ role: 3,
+ };
+
+ const created = await nodesStore.post(doc);
+ notifications.add({ type: 'success', title: 'Document created from shared content' });
+
+ // Upload non-text files as resources linked to this note
+ const nonTextFiles = sharedFiles.value.filter(f => !f.file.type.startsWith('text/') && !f.name.endsWith('.md') && !f.name.endsWith('.txt'));
+
+ for (const sharedFile of nonTextFiles) {
+ try {
+ const formData = new FormData();
+ formData.append('file', sharedFile.file);
+ formData.append('parent_id', created.id);
+ await resourcesStore.post(formData);
+ } catch (e) {
+ console.error('[share-target] Failed to upload file:', sharedFile.name, e);
+ notifications.add({ type: 'warning', title: `Failed to upload ${sharedFile.name}` });
+ }
+ }
+
+ cleanupPreviews();
+ router.push(`/dashboard/docs/edit/${created.id}`);
+ } catch (e) {
+ notifications.add({ type: 'error', title: 'Error creating document', message: String(e) });
+ } finally {
+ processing.value = false;
+ }
+}
+
+async function uploadFiles() {
+ if (processing.value) return;
+ processing.value = true;
+
+ try {
+ let uploadedCount = 0;
+ for (const sharedFile of sharedFiles.value) {
+ const formData = new FormData();
+ formData.append('file', sharedFile.file);
+ if (parentId.value) formData.append('parent_id', parentId.value);
+ await resourcesStore.post(formData);
+ uploadedCount++;
+ }
+
+ notifications.add({ type: 'success', title: `${uploadedCount} file(s) uploaded successfully` });
+ cleanupPreviews();
+ router.push('/dashboard/cdn');
+ } catch (e) {
+ notifications.add({ type: 'error', title: 'Error uploading files', message: String(e) });
+ } finally {
+ processing.value = false;
+ }
+}
+
+function cleanupPreviews() {
+ sharedFiles.value.forEach(f => {
+ if (f.preview) URL.revokeObjectURL(f.preview);
+ });
+}
+
+onBeforeUnmount(() => {
+ cleanupPreviews();
+});
+</script>
+
+<style scoped lang="scss">
+section {
+ margin-top: 1.5rem;
+}
+.share-content {
+ gap: 1.5rem;
+}
+
+.preview-card {
+ padding: 1rem;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--border);
+
+ .shared-url {
+ display: block;
+ color: var(--primary);
+ word-break: break-all;
+ text-decoration: underline;
+
+ &:hover {
+ color: var(--primary-dark);
+ }
+ }
+}
+
+.files-grid {
+ display: flex;
+ flex-direction: column;
+ gap: 0.5rem;
+}
+
+.share-actions {
+ display: flex;
+ flex-direction: column;
+ gap: 0.75rem;
+}
+
+.action-card {
+ display: flex;
+ align-items: center;
+ gap: 1rem;
+ padding: 1rem;
+ background: var(--bg-secondary);
+ border-radius: var(--radius-md);
+ border: 1px solid var(--border);
+ cursor: pointer;
+ transition: all 0.15s ease;
+
+ &:hover {
+ border-color: var(--primary);
+ background: var(--selection-color);
+ }
+
+ .action-icon {
+ width: 40px;
+ height: 40px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ background: var(--primary);
+ border-radius: var(--radius-sm);
+ color: white;
+ flex-shrink: 0;
+ }
+
+ .action-info {
+ h3 {
+ font-size: 0.95rem;
+ margin-bottom: 0.15rem;
+ }
+
+ p {
+ font-size: 0.8rem;
+ color: var(--text-muted);
+ }
+ }
+}
+</style>
diff --git a/frontend/app/styles/components/page-components.scss b/frontend/app/styles/components/page-components.scss
index adebd109..8e905457 100644
--- a/frontend/app/styles/components/page-components.scss
+++ b/frontend/app/styles/components/page-components.scss
@@ -34,6 +34,9 @@
.page-title {
font-size: 1.7rem;
font-weight: bold;
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
}
.page-subtitle {
diff --git a/frontend/app/sw.ts b/frontend/app/sw.ts
new file mode 100644
index 00000000..1fa55153
--- /dev/null
+++ b/frontend/app/sw.ts
@@ -0,0 +1,84 @@
+/// <reference lib="webworker" />
+import { precacheAndRoute, cleanupOutdatedCaches } from 'workbox-precaching';
+import { registerRoute, NavigationRoute } from 'workbox-routing';
+import { NetworkFirst } from 'workbox-strategies';
+import { clientsClaim } from 'workbox-core';
+
+declare let self: ServiceWorkerGlobalScope;
+
+// Auto-update: take control immediately
+self.skipWaiting();
+clientsClaim();
+
+// Precache all assets generated by the build
+cleanupOutdatedCaches();
+precacheAndRoute(self.__WB_MANIFEST);
+
+// ─── Navigation (HTML pages) ─────────────────────────────────────────────────
+registerRoute(
+ new NavigationRoute(
+ new NetworkFirst({ networkTimeoutSeconds: 3 }),
+ { denylist: [/^\/api\//] },
+ ),
+);
+
+// ─── API cache ───────────────────────────────────────────────────────────────
+registerRoute(
+ ({ url }) => url.pathname.startsWith('/api/') && !url.pathname.startsWith('/api/backup/'),
+ new NetworkFirst({ cacheName: 'api-cache' }),
+);
+
+// ─── Share Target API handler ────────────────────────────────────────────────
+// When the PWA receives a share via the Share Target API (POST with form data),
+// the service worker intercepts it, caches the form data, and redirects
+// to the share-target page which reads from the cache.
+
+self.addEventListener('fetch', (event: FetchEvent) => {
+ const url = new URL(event.request.url);
+
+ if (
+ url.pathname === '/dashboard/share-target' &&
+ event.request.method === 'POST'
+ ) {
+ event.respondWith(handleShareTarget(event.request));
+ }
+});
+
+async function handleShareTarget(request: Request): Promise<Response> {
+ try {
+ // Clone formData from the incoming POST request
+ const formData = await request.formData();
+
+ // Store the shared data in the Cache API so the page can read it
+ const cache = await caches.open('share-target-cache');
+
+ // Create a synthetic response from the form data to store in cache
+ // We need to reconstruct a new FormData-based response
+ const newFormData = new FormData();
+
+ const title = formData.get('title');
+ const text = formData.get('text');
+ const url = formData.get('url');
+
+ if (title) newFormData.append('title', title);
+ if (text) newFormData.append('text', text);
+ if (url) newFormData.append('url', url);
+
+ // Handle shared files
+ const files = formData.getAll('files');
+ for (const file of files) {
+ if (file instanceof File && file.size > 0) {
+ newFormData.append('files', file, file.name);
+ }
+ }
+
+ // Store as a Response with the form data
+ const response = new Response(newFormData);
+ await cache.put('/share-target-data', response);
+ } catch (error) {
+ console.error('[SW] Error handling share target:', error);
+ }
+
+ // Redirect to the share target page (GET)
+ return Response.redirect('/dashboard/share-target', 303);
+}
diff --git a/frontend/nuxt.config.ts b/frontend/nuxt.config.ts
index 43a69aa6..730023b8 100644
--- a/frontend/nuxt.config.ts
+++ b/frontend/nuxt.config.ts
@@ -102,6 +102,22 @@ export default defineNuxtConfig({
purpose: 'any',
},
],
+ share_target: {
+ action: '/dashboard/share-target',
+ method: 'POST',
+ enctype: 'multipart/form-data',
+ params: {
+ title: 'title',
+ text: 'text',
+ url: 'url',
+ files: [
+ {
+ name: 'files',
+ accept: ['image/*', 'application/pdf', 'text/*', 'application/json', '.md', '.txt', '.json', '.csv'],
+ },
+ ],
+ },
+ },
screenshots: [
{
src: '/screenshots/mock/1.png',
@@ -133,31 +149,13 @@ export default defineNuxtConfig({
},
],
},
+ strategies: 'injectManifest',
+ srcDir: '.',
+ filename: 'sw.ts',
base: '/',
- workbox: {
+ injectManifest: {
maximumFileSizeToCacheInBytes: 3000000,
- navigateFallback: null,
globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
- runtimeCaching: [
- // Pages HTML (navigation)
- {
- urlPattern: ({ request }) => request.mode === 'navigate',
- handler: 'NetworkFirst',
- options: {
- networkTimeoutSeconds: 3,
- },
- },
- {
- // Api cache: match /api calls
- urlPattern: ({ url }) => {
- return url.pathname.startsWith('/api/') && !url.pathname.startsWith('/api/backup/');
- },
- handler: 'NetworkFirst',
- options: {
- cacheName: 'api-cache',
- },
- },
- ],
},
},
diff --git a/frontend/public/app-icons/share.svg b/frontend/public/app-icons/share.svg
new file mode 100644
index 00000000..c39ffc76
--- /dev/null
+++ b/frontend/public/app-icons/share.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -960 960 960"><path d="M680-80q-50 0-85-35t-35-85q0-6 3-28L282-392q-16 15-37 23.5t-45 8.5q-50 0-85-35t-35-85q0-50 35-85t85-35q24 0 45 8.5t37 23.5l281-164q-2-7-2.5-13.5T560-760q0-50 35-85t85-35q50 0 85 35t35 85q0 50-35 85t-85 35q-24 0-45-8.5T598-672L317-508q2 7 2.5 13.5t.5 14.5q0 8-.5 14.5T317-452l281 164q16-15 37-23.5t45-8.5q50 0 85 35t35 85q0 50-35 85t-85 35Zm0-80q17 0 28.5-11.5T720-200q0-17-11.5-28.5T680-240q-17 0-28.5 11.5T640-200q0 17 11.5 28.5T680-160ZM200-440q17 0 28.5-11.5T240-480q0-17-11.5-28.5T200-520q-17 0-28.5 11.5T160-480q0 17 11.5 28.5T200-440Zm508.5-291.5Q720-743 720-760t-11.5-28.5Q697-800 680-800t-28.5 11.5Q640-777 640-760t11.5 28.5Q663-720 680-720t28.5-11.5ZM680-200ZM200-480Zm480-280Z"/></svg>
\ No newline at end of file