feat: inject Open Graph meta tags into share page for social previews
- Add buildShareOpenGraphPage() to server/routes/share.js - Reads share.html template and injects OG/Twitter meta tags - og:image + summary_large_image for image files (jpg/jpeg/png/gif/webp/avif/bmp) - 'Link Expired' title/description for expired tokens - 'Link Not Found' for unknown tokens - og:description includes file type and remaining validity - Update GET /share/:token in server/index.js to use the new function - Works for all visitors: crawlers get OG data, browsers get full interactive page - Browser tab title now shows filename instead of generic 'Shared file' - Add 11 tests covering all scenarios in share.routes.test.js - Update technical-reference.md and tests.md
@@ -3,6 +3,7 @@
3
3
## server/index.js
4
4
- start() - Initialises DB/keys, starts HTTP/HTTPS servers, and starts the background thumbnail cache loop.
5
5
- shutdown(opts, ...servers) - Graceful teardown: stops thumbnail loop, closes DB/servers, exits with configurable code after drain/timeout.
6
- GET /share/:token - Calls buildShareOpenGraphPage to serve share.html with injected OG meta tags for all visitors; social media crawlers see rich preview data, browsers get the full interactive page.
6
7
7
8
## server/thumbnail-cache.js
8
9
- syncThumbnailCacheOnce() - Mirrors configured roots into public/thumbs and generates 99x99-max WebP thumbnails for image files; removes stale thumbnails and updates manifest hashes while preserving prior cache entries for temporarily unavailable roots (e.g. removable mounts).
@@ -68,6 +69,7 @@
68
69
- GET /api/share/preview/:token - Public. Streams file content inline for preview (files only, max 50 MB); 400 for directories, 410 expired.
69
70
- GET /api/share/download/:token - Public. Downloads the file or a zip of the directory for a valid token; 410 expired.
70
71
- GET /api/share/video-stream/:token - Public. Creates a short-lived HLS session for a shared video and returns playlistUrl, durationSeconds, subtitleTracks, and subtitleSummary ({total, converted, skipped}).
72
- buildShareOpenGraphPage(token, req) - Reads share.html, injects OG meta tags (<og:title>, <og:description>, <og:image> for image files, twitter:card) based on DB lookup of token, and returns the full HTML string. Handles expired and not-found tokens. Exported and used by the /share/:token route in server/index.js.
71
73
- buildZip(dirPath, cacheKey) - Creates (or returns cached) zip in zip-cache/; prunes stale zips before building; exported for reuse in files.js.
72
74
- pruneZipCache() - Deletes zip files in zip-cache/ older than 1 day; called automatically before each zip build.
73
75
- ZIP_CACHE_DIR - Absolute path to the zip-cache/ directory (project root).
@@ -3,6 +3,7 @@3
## server/index.js
3
## server/index.js
4
- start() - Initialises DB/keys, starts HTTP/HTTPS servers, and starts the background thumbnail cache loop.
4
- start() - Initialises DB/keys, starts HTTP/HTTPS servers, and starts the background thumbnail cache loop.
5
- shutdown(opts, ...servers) - Graceful teardown: stops thumbnail loop, closes DB/servers, exits with configurable code after drain/timeout.
5
- shutdown(opts, ...servers) - Graceful teardown: stops thumbnail loop, closes DB/servers, exits with configurable code after drain/timeout.
6
- GET /share/:token - Calls buildShareOpenGraphPage to serve share.html with injected OG meta tags for all visitors; social media crawlers see rich preview data, browsers get the full interactive page.
6
7
7
## server/thumbnail-cache.js
8
## server/thumbnail-cache.js
8
- syncThumbnailCacheOnce() - Mirrors configured roots into public/thumbs and generates 99x99-max WebP thumbnails for image files; removes stale thumbnails and updates manifest hashes while preserving prior cache entries for temporarily unavailable roots (e.g. removable mounts).
9
- syncThumbnailCacheOnce() - Mirrors configured roots into public/thumbs and generates 99x99-max WebP thumbnails for image files; removes stale thumbnails and updates manifest hashes while preserving prior cache entries for temporarily unavailable roots (e.g. removable mounts).
@@ -68,6 +69,7 @@68
- GET /api/share/preview/:token - Public. Streams file content inline for preview (files only, max 50 MB); 400 for directories, 410 expired.
69
- GET /api/share/preview/:token - Public. Streams file content inline for preview (files only, max 50 MB); 400 for directories, 410 expired.
69
- GET /api/share/download/:token - Public. Downloads the file or a zip of the directory for a valid token; 410 expired.
70
- GET /api/share/download/:token - Public. Downloads the file or a zip of the directory for a valid token; 410 expired.
70
- GET /api/share/video-stream/:token - Public. Creates a short-lived HLS session for a shared video and returns playlistUrl, durationSeconds, subtitleTracks, and subtitleSummary ({total, converted, skipped}).
71
- GET /api/share/video-stream/:token - Public. Creates a short-lived HLS session for a shared video and returns playlistUrl, durationSeconds, subtitleTracks, and subtitleSummary ({total, converted, skipped}).
72
- buildShareOpenGraphPage(token, req) - Reads share.html, injects OG meta tags (<og:title>, <og:description>, <og:image> for image files, twitter:card) based on DB lookup of token, and returns the full HTML string. Handles expired and not-found tokens. Exported and used by the /share/:token route in server/index.js.
71
- buildZip(dirPath, cacheKey) - Creates (or returns cached) zip in zip-cache/; prunes stale zips before building; exported for reuse in files.js.
73
- buildZip(dirPath, cacheKey) - Creates (or returns cached) zip in zip-cache/; prunes stale zips before building; exported for reuse in files.js.
72
- pruneZipCache() - Deletes zip files in zip-cache/ older than 1 day; called automatically before each zip build.
74
- pruneZipCache() - Deletes zip files in zip-cache/ older than 1 day; called automatically before each zip build.
73
- ZIP_CACHE_DIR - Absolute path to the zip-cache/ directory (project root).
75
- ZIP_CACHE_DIR - Absolute path to the zip-cache/ directory (project root).
@@ -65,6 +65,7 @@
65
65
- `GET /api/share/video-stream/:token`
66
66
- `GET /api/share/download/:token`
67
67
- `pruneZipCache`
68
- `buildShareOpenGraphPage`
68
69
69
70
---
70
71
@@ -65,6 +65,7 @@65
- `GET /api/share/video-stream/:token`65
- `GET /api/share/video-stream/:token`66
- `GET /api/share/download/:token`66
- `GET /api/share/download/:token`67
- `pruneZipCache`67
- `pruneZipCache`68
- `buildShareOpenGraphPage`68
69
69
---70
---70
71
@@ -25,10 +25,14 @@ app.use('/api/files', filesRoutes);
25
25
app.use('/api/admin', adminRoutes);
26
26
app.use('/api/share', shareRoutes);
27
27
28
// Share page — served without authentication.
28
// Share page — served without authentication. OG meta tags are injected
29
// server-side so social media crawlers (Discord, WhatsApp, Telegram, etc.)
30
// can display rich previews.
29
31
app.get('/share/:token', (req, res) =>
30
32
{
31
res.sendFile(path.join(__dirname, '../public/share.html'));
33
const token = String(req.params.token || '').trim();
34
const page = shareRoutes.buildShareOpenGraphPage(token, req);
35
res.type('html').send(page);
32
36
});
33
37
34
38
// SPA catch-all (only for non-API routes)
@@ -25,10 +25,14 @@ app.use('/api/files', filesRoutes);25
app.use('/api/admin', adminRoutes);25
app.use('/api/admin', adminRoutes);26
app.use('/api/share', shareRoutes);26
app.use('/api/share', shareRoutes);27
27
28
// Share page — served without authentication.28
// Share page — served without authentication. OG meta tags are injected29
// server-side so social media crawlers (Discord, WhatsApp, Telegram, etc.)30
// can display rich previews.29
app.get('/share/:token', (req, res) =>31
app.get('/share/:token', (req, res) =>30
{32
{31
res.sendFile(path.join(__dirname, '../public/share.html'));33
const token = String(req.params.token || '').trim();34
const page = shareRoutes.buildShareOpenGraphPage(token, req);35
res.type('html').send(page);32
});36
});33
37
34
// SPA catch-all (only for non-API routes)38
// SPA catch-all (only for non-API routes)