Changeset 928d1c7 in Klonkt for src/routes
- Timestamp:
- 07/21/2026 01:06:47 AM (7 weeks ago)
- Branches:
- main
- Children:
- 9e9e6f9
- Parents:
- 61e3daf
- git-author:
- Robin <roboburr@…> (07/21/2026 01:06:45 AM)
- git-committer:
- Robin <roboburr@…> (07/21/2026 01:06:47 AM)
- File:
-
- 1 edited
-
src/routes/posts.js (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/posts.js
r61e3daf r928d1c7 20 20 import VideoCoverService from '../services/VideoCoverService.js'; 21 21 import ActivityPubService from '../services/ActivityPubService.js'; 22 import { premiumUnlocked } from '../services/PatreonService.js'; 23 import { defaultMinCents as paidDefaultMinCents } from '../services/PaidPatreonService.js'; 22 24 import MusicMeta from '../services/MusicMeta.js'; 23 25 … … 327 329 const { title, slug, content, excerpt, status, pinned, cover_image_url, tags, noindex, type } = req.body; 328 330 const fanOnly = req.body.fan_only ? 1 : 0; 331 const paid = (premiumUnlocked() && req.body.paid) ? 1 : 0; // paid posts (klonkt-demo-aki) 332 const paidEur = String(req.body.paid_min_eur || '').replace(',', '.').trim(); 333 const paidMinCents = paid && paidEur ? Math.round(parseFloat(paidEur) * 100) : null; 329 334 const nsfw = req.body.nsfw ? 1 : 0; 330 335 const cw = (req.body.content_warning || '').trim().slice(0, 200); … … 381 386 ); 382 387 cacheRenderedContent(postId, cleanContent); // bake display HTML (ActivityPub `source` model) 388 db.prepare('UPDATE posts SET paid = ?, paid_min_cents = ? WHERE id = ?').run(paid, paidMinCents, postId); 383 389 384 390 // Per-post "share audio on the fediverse" → set fedi_open on this post's hosted tracks … … 399 405 id: postId, slug: finalSlug, title: title || finalSlug, 400 406 content: cleanContent, cover_image_url: cover_image_url || null, cover_video_url: req.body.cover_video_url || null, cover_alt: coverAlt, language, 401 published_at: publishedAt, created_at: now, fan_only: fanOnly, nsfw, content_warning: cw, poll_json: pollJson,407 published_at: publishedAt, created_at: now, fan_only: fanOnly, paid, paid_min_cents: paidMinCents, excerpt: excerpt || '', nsfw, content_warning: cw, poll_json: pollJson, 402 408 }).catch(() => { /* best-effort */ }); 403 409 } … … 463 469 const { title, content, excerpt, status, pinned, cover_image_url, tags, noindex, type } = req.body; 464 470 const fanOnly = req.body.fan_only ? 1 : 0; 471 const paid = (premiumUnlocked() && req.body.paid) ? 1 : 0; // paid posts (klonkt-demo-aki) 472 const paidEur = String(req.body.paid_min_eur || '').replace(',', '.').trim(); 473 const paidMinCents = paid && paidEur ? Math.round(parseFloat(paidEur) * 100) : null; 465 474 const nsfw = req.body.nsfw ? 1 : 0; 466 475 const cw = (req.body.content_warning || '').trim().slice(0, 200); … … 522 531 ); 523 532 cacheRenderedContent(post.id, cleanContent); // re-bake display HTML on edit (ActivityPub `source` model) 533 db.prepare('UPDATE posts SET paid = ?, paid_min_cents = ? WHERE id = ?').run(paid, paidMinCents, post.id); 524 534 525 535 // Per-post "share audio on the fediverse" → set fedi_open on this post's hosted tracks … … 544 554 id: post.id, slug: finalSlug, title: title || finalSlug, 545 555 content: cleanContent, cover_image_url: cover_image_url || null, cover_video_url: req.body.cover_video_url || null, cover_alt: coverAlt, language, 546 published_at: publishedAt, created_at: post.created_at, fan_only: fanOnly, nsfw, content_warning: cw, poll_json: pollJson,556 published_at: publishedAt, created_at: post.created_at, fan_only: fanOnly, paid, paid_min_cents: paidMinCents, excerpt: excerpt || '', nsfw, content_warning: cw, poll_json: pollJson, 547 557 }; 548 558 if (post.status !== 'published') ActivityPubService.deliverCreate(site, apPost).catch(() => { /* best-effort */ }); … … 638 648 // post render and the fan gate (premium fan_only) so navigation is consistent 639 649 // everywhere. Solo: within the site (pinned first, then date). Hub: globally by date. 650 // A short public teaser for a paid post: its excerpt, else the first ~280 chars 651 // of the (stripped) content. Shared by the web gate and federation. 652 function paidTeaser(post, max = 280) { 653 if (post && post.excerpt && String(post.excerpt).trim()) return String(post.excerpt).trim(); 654 // Only the FIRST paragraph: a paid teaser must never spill later content. 655 const html = String((post && post.content) || ''); 656 const firstP = (html.match(/<p[^>]*>([\s\S]*?)<\/p>/i) || [null, html])[1] || ''; 657 const text = firstP.replace(/<[^>]+>/g, ' ').replace(/&[a-z#0-9]+;/gi, ' ').replace(/\s+/g, ' ').trim(); 658 return text.length > max ? text.slice(0, max).replace(/\s+\S*$/, '') + '…' : text; 659 } 660 640 661 function postNeighbors(site, post, isHub) { 641 662 const urlBaseFor = (p) => (isHub && p && p.site_slug) ? `/user/${p.site_slug}` : ''; … … 1120 1141 fgTitle: post.title || '', 1121 1142 fgNext: (res.locals.siteUrlBase || '') + '/' + post.slug, 1143 newerPost, 1144 olderPost, 1145 }); 1146 } 1147 1148 // Paid gate (klonkt-demo-aki): a paid post shows only a teaser to anyone who 1149 // is not the owner/editor. The passkey unlock arrives in slices 3-4; for now 1150 // the owner previews the full post, everyone else sees the teaser + notice. 1151 const canEditThis = req.session?.user && PermissionsService.canEditPost(req.session.user, post, site); 1152 if (post.paid && !canEditThis) { 1153 const { newerPost, olderPost } = postNeighbors(site, post, res.locals.tenancy === 'hub'); 1154 return renderPage(req, res, 'pages/paid-gate', { 1155 pageTitle: post.title || 'Voor supporters', 1156 bodyClass: 'on-special', 1157 pgTitle: post.title || '', 1158 pgTeaser: paidTeaser(post), 1159 pgCents: post.paid_min_cents || paidDefaultMinCents(site.id), 1160 pgSlug: post.slug, 1122 1161 newerPost, 1123 1162 olderPost,
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)