Changeset e0a1ec1 in Klonkt for src/routes/posts.js
- Timestamp:
- 06/30/2026 02:27:57 AM (2 months ago)
- Branches:
- main
- Children:
- d3b9f68
- Parents:
- 084d1c0
- File:
-
- 1 edited
-
src/routes/posts.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/routes/posts.js
r084d1c0 re0a1ec1 169 169 170 170 // ==================== CREATE POST ==================== 171 // ── Per-post audio federation ────────────────────────────────────────────── 172 // "Share audio on the fediverse" is a per-post choice in the editor, but the underlying 173 // flag is per track (audio_tracks.fedi_open — it gates the file + drives the AS2 Audio 174 // attachment). NB: the file gate is per file, so opening a track in one post makes its file 175 // fetchable for every post that reuses it. 176 function setAudioFediOpen(siteId, content, open) { 177 const val = open ? 1 : 0; 178 const c = content || ''; 179 try { 180 for (const m of c.matchAll(/\[\[track:([A-Za-z0-9_-]+)\]\]/g)) db.prepare('UPDATE audio_tracks SET fedi_open = ? WHERE id = ? AND site_id = ?').run(val, m[1], siteId); 181 for (const m of c.matchAll(/\[\[album:([^\]]+)\]\]/g)) db.prepare('UPDATE audio_tracks SET fedi_open = ? WHERE site_id = ? AND album = ?').run(val, siteId, m[1].trim()); 182 for (const m of c.matchAll(/\[\[playlist:([A-Za-z0-9_-]+)\]\]/g)) db.prepare('UPDATE audio_tracks SET fedi_open = ? WHERE id IN (SELECT track_id FROM playlist_tracks WHERE playlist_id = ?)').run(val, m[1]); 183 } catch { /* non-fatal */ } 184 } 185 // True when the post references hosted audio AND all of it is currently fedi_open (drives the 186 // editor checkbox's initial state). 187 function postAudioFediOpen(siteId, content) { 188 const c = content || ''; 189 if (!/\[\[(track|album|playlist):/i.test(c)) return false; 190 let total = 0, open = 0; 191 const tally = (r) => { if (r && r.media_id) { total++; if (r.fedi_open) open++; } }; 192 try { 193 for (const m of c.matchAll(/\[\[track:([A-Za-z0-9_-]+)\]\]/g)) tally(db.prepare('SELECT fedi_open, media_id FROM audio_tracks WHERE id = ? AND site_id = ?').get(m[1], siteId)); 194 for (const m of c.matchAll(/\[\[album:([^\]]+)\]\]/g)) for (const r of db.prepare('SELECT fedi_open, media_id FROM audio_tracks WHERE site_id = ? AND album = ? AND media_id IS NOT NULL').all(siteId, m[1].trim())) tally(r); 195 for (const m of c.matchAll(/\[\[playlist:([A-Za-z0-9_-]+)\]\]/g)) for (const r of db.prepare('SELECT t.fedi_open, t.media_id FROM playlist_tracks pt JOIN audio_tracks t ON t.id = pt.track_id WHERE pt.playlist_id = ? AND t.media_id IS NOT NULL').all(m[1])) tally(r); 196 } catch { /* non-fatal */ } 197 return total > 0 && open === total; 198 } 199 171 200 router.post('/posts/create', requireAuth, (req, res) => { 172 201 const site = res.locals.site; … … 228 257 ); 229 258 259 // Per-post "share audio on the fediverse" → set fedi_open on this post's hosted tracks 260 // BEFORE federating, so the Create note carries the right Audio attachments. 261 setAudioFediOpen(site.id, cleanContent, req.body.fedi_open_audio); 262 230 263 if (finalStatus === 'published') { 231 264 try { … … 278 311 post, 279 312 isNew: false, 313 fediOpenAudio: postAudioFediOpen(site.id, post.content), 280 314 pageTitle: 'Edit: ' + (post.title || 'Untitled'), 281 315 bodyClass: 'on-special', … … 349 383 finalSlug, publishedAt, now, post.id 350 384 ); 385 386 // Per-post "share audio on the fediverse" → set fedi_open on this post's hosted tracks 387 // BEFORE federating, so the Update/Create note carries the right Audio attachments. 388 setAudioFediOpen(site.id, cleanContent, req.body.fedi_open_audio); 351 389 352 390 // Update FTS
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)