Skip to content
This repository was archived by the owner on Feb 27, 2026. It is now read-only.

Add preview feature for social media sharing#293

Merged
danielalves96 merged 6 commits intonextfrom
copilot/add-social-media-preview
Oct 20, 2025
Merged

Add preview feature for social media sharing#293
danielalves96 merged 6 commits intonextfrom
copilot/add-social-media-preview

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 9, 2025

🎨 Add Social Media Preview with Open Graph Metadata

This PR implements Open Graph and Twitter Card metadata for share links, making them more friendly and less intimidating when shared on social media platforms.

📸 Preview

✨ Features

  • Dynamic Open Graph meta tags based on share content
  • Twitter Card support for better Twitter sharing
  • Displays share name, description, and file count
  • Uses app logo as preview image
  • Supports both regular shares (/s/[alias]) and reverse shares (/r/[alias])
  • Graceful fallback when metadata fetch fails
  • Server-side rendering for optimal social media crawler support
  • Dynamic base URL construction from request headers - No environment variable configuration needed
  • Full internationalization support - Metadata available in all 15 supported languages

🔧 Changes

Backend (Server)

  • Added GET /shares/alias/:alias/metadata endpoint for lightweight share metadata
  • Added GET /reverse-shares/alias/:alias/metadata endpoint for reverse share metadata
  • Added service methods to fetch metadata without authentication
  • Added repository method to find shares by alias

Frontend (Web)

  • Updated /s/[alias]/layout.tsx with dynamic generateMetadata function
  • Updated /r/[alias]/layout.tsx with dynamic generateMetadata function
  • Added translation keys for metadata descriptions in all 15 supported languages:
    • 🇸🇦 Arabic (ar-SA)
    • 🇩🇪 German (de-DE)
    • 🇺🇸 English (en-US)
    • 🇪🇸 Spanish (es-ES)
    • 🇫🇷 French (fr-FR)
    • 🇮🇳 Hindi (hi-IN)
    • 🇮🇹 Italian (it-IT)
    • 🇯🇵 Japanese (ja-JP)
    • 🇰🇷 Korean (ko-KR)
    • 🇳🇱 Dutch (nl-NL)
    • 🇵🇱 Polish (pl-PL)
    • 🇧🇷 Portuguese (pt-BR)
    • 🇷🇺 Russian (ru-RU)
    • 🇹🇷 Turkish (tr-TR)
    • 🇨🇳 Chinese (zh-CN)
  • Base URL dynamically constructed from request headers (x-forwarded-proto, x-forwarded-host, host) similar to email link generation

Generated Meta Tags Example

For a share with 5 files named "Project Files - December 2024":

<meta property="og:title" content="Project Files - December 2024" />
<meta property="og:description" content="5 files shared" />
<meta property="og:url" content="https://palmr.example.com/s/myshare" />
<meta property="og:site_name" content="Palmr" />
<meta property="og:type" content="website" />
<meta property="og:image" content="https://palmr.example.com/logo.png" />
<meta name="twitter:card" content="summary_large_image" />

📝 Configuration

Only the API base URL is needed in your .env file:

# API base URL for server-side metadata fetching  
API_BASE_URL=http://localhost:3333

No additional configuration required! The base URL for Open Graph metadata is automatically constructed from incoming request headers, ensuring it works correctly across all environments (localhost, staging, production) without manual configuration.

🧪 Testing

Test your share links on social media platforms using:

🔒 Privacy & Security

  • Metadata endpoints are public but only return basic information (name, description, file count)
  • Password-protected shares don't expose passwords in metadata
  • File contents and detailed information are never exposed
  • Expired/inactive shares are properly indicated

📦 Files Changed

Server:

  • apps/server/src/modules/share/controller.ts
  • apps/server/src/modules/share/service.ts
  • apps/server/src/modules/share/repository.ts
  • apps/server/src/modules/share/routes.ts
  • apps/server/src/modules/reverse-share/controller.ts
  • apps/server/src/modules/reverse-share/service.ts
  • apps/server/src/modules/reverse-share/routes.ts

Web:

  • apps/web/src/app/(shares)/s/[alias]/layout.tsx
  • apps/web/src/app/(shares)/r/[alias]/layout.tsx
  • apps/web/messages/*.json (all 15 language files)

✅ Validation

  • TypeScript type checking passes
  • ESLint validation passes
  • Code formatted with Prettier
  • Server builds successfully
  • Web app validates successfully
  • Works across all environments without manual URL configuration
  • All JSON translation files are valid
  • Translations available in all 15 supported languages

Resolves the feature request for social media preview when sharing links on platforms like Twitter, Facebook, LinkedIn, WhatsApp, etc.

Fixes #242

Original prompt

This section details on the original issue you should resolve

<issue_title>[Feature] Add preview when sharing on social media platforms</issue_title>
<issue_description>It think a preview when sharing a link on social media would make it more friendly and less intimidating to click on. The preview could include the app name, the app description, the app logo or the number of file shared (if not protected).

For exemple: https://www.opengraph.xyz/url/https%3A%2F%2Fgithub.com</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #242


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 3 commits October 9, 2025 19:43
Co-authored-by: danielalves96 <62755605+danielalves96@users.noreply.github.com>
Co-authored-by: danielalves96 <62755605+danielalves96@users.noreply.github.com>
Co-authored-by: danielalves96 <62755605+danielalves96@users.noreply.github.com>
@danielalves96
Copy link
Copy Markdown
Contributor

@copilot we cant add an env var called NEXT_PUBLIC_BASE_URL, we have to get from current browser. like some email do.

…pen Graph metadata

Co-authored-by: danielalves96 <62755605+danielalves96@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 10, 2025

@copilot we cant add an env var called NEXT_PUBLIC_BASE_URL, we have to get from current browser. like some email do.

Fixed in commit b7c8e9a. The base URL is now dynamically constructed from request headers (x-forwarded-proto, x-forwarded-host, host) using Next.js headers() function, similar to how the auth provider callbacks work. No environment variable needed.

Copilot AI changed the title [WIP] Add preview feature for social media sharing Add preview feature for social media sharing Oct 10, 2025
@danielalves96
Copy link
Copy Markdown
Contributor

@copilot add translations for all languages

Co-authored-by: danielalves96 <62755605+danielalves96@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 10, 2025

@copilot add translations for all languages

Added in commit 0c5f1e2. Translations now available in all 15 supported languages (Arabic, German, English, Spanish, French, Hindi, Italian, Japanese, Korean, Dutch, Polish, Portuguese, Russian, Turkish, Chinese).

@danielalves96
Copy link
Copy Markdown
Contributor

@copilot if the s/[shareAlias] has an image and its public, this image turns the og:image? or just the app logo?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 10, 2025

@copilot if the s/[shareAlias] has an image and its public, this image turns the og:image? or just the app logo?

Currently, it only uses the app logo. The metadata endpoint returns basic info (name, description, file count) but doesn't include file images. To use a share's image as og:image, we'd need to:

  1. Add image info to the metadata endpoint
  2. Check if share has public images
  3. Use first image as og:image, fallback to app logo

Would you like me to implement this enhancement?

@danielalves96 danielalves96 marked this pull request as ready for review October 20, 2025 13:55
@danielalves96 danielalves96 merged commit cce9847 into next Oct 20, 2025
1 check passed
@danielalves96 danielalves96 deleted the copilot/add-social-media-preview branch October 21, 2025 17:11
anthony0030 pushed a commit to anthony0030/Palmr that referenced this pull request Jan 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants