wiki-plugin-rcntimeline 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/client/rcntimeline.js +60 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,4 +50,4 @@ Marc Pierson and Claude Opus 5.5 · September 2026
|
|
|
50
50
|
|
|
51
51
|
**Walks** (0.3.0). A timeline made in the full tool can carry `walks`: readings that play one step at a time. **▶ Walk** under the timeline redraws each step's years, fades the other bars, and reads the words aloud with a caption; Space, ← →, Esc. Open in RCN Timeline and Save to wiki carry the walks both ways.
|
|
52
52
|
|
|
53
|
-
**Recorded voices** (0.3.1). A step may carry `voices`, people's own recordings of its words, made with ● Record in the timeline's walk editor: `{"<name>": {audio, say}}`. The walk plays a step's recording when it has one and the computer voice otherwise; a chooser in the walk bar picks whose, or the computer voice only (kept in `rcnWalkPrefs.speaker`).
|
|
53
|
+
**Recorded voices** (0.3.1). A step may carry `voices`, people's own recordings of its words, made with ● Record in the timeline's walk editor: `{"<name>": {audio, say}}`. The walk plays a step's recording when it has one and the computer voice otherwise; a chooser in the walk bar picks whose, or the computer voice only (kept in `rcnWalkPrefs.speaker`). On Save to wiki the plugin moves each recording into the site's assets, `assets/voice-files/<content hash>.webm`, uploaded once however often the page is saved, and the step keeps only the file's full address, so pages and their history never hold audio and a forked page still plays from the original site. If the upload fails (not signed in), the recording stays inside the walk until the next save that can upload it.
|
package/client/rcntimeline.js
CHANGED
|
@@ -581,19 +581,73 @@
|
|
|
581
581
|
emit($item, item)
|
|
582
582
|
}
|
|
583
583
|
|
|
584
|
+
// Recordings live as files in this site's assets (assets/voice-files), one file per
|
|
585
|
+
// recording, named by its content. On save, any recording still held inside a walk
|
|
586
|
+
// (a data: URL from a walk editor) is uploaded there and replaced by the file's full
|
|
587
|
+
// address, so a page and its history keep only addresses, a recording is never
|
|
588
|
+
// stored twice, and a forked page still plays from the site that has the file.
|
|
589
|
+
// If the upload fails (not signed in, say) the recording stays inside the walk, so
|
|
590
|
+
// nothing is lost, and the next save that can upload moves it out.
|
|
591
|
+
const VOICE_FOLDER = 'voice-files'
|
|
592
|
+
function voiceSteps (walks) {
|
|
593
|
+
const out = []
|
|
594
|
+
for (const w of walks || []) for (const st of (w && w.steps) || []) {
|
|
595
|
+
for (const n of Object.keys((st && st.voices) || {})) {
|
|
596
|
+
const v = st.voices[n]
|
|
597
|
+
if (v && typeof v.audio === 'string' && /^data:audio\//.test(v.audio)) out.push(v)
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
return out
|
|
601
|
+
}
|
|
602
|
+
async function voiceFile (dataUrl) {
|
|
603
|
+
const blob = await (await fetch(dataUrl)).blob()
|
|
604
|
+
const sum = new Uint8Array(await crypto.subtle.digest('SHA-256', await blob.arrayBuffer()))
|
|
605
|
+
const hex = [...sum.slice(0, 12)].map(b => b.toString(16).padStart(2, '0')).join('')
|
|
606
|
+
const ext = /mp4|m4a|aac/.test(blob.type) ? 'm4a' : /wav/.test(blob.type) ? 'wav' : /ogg/.test(blob.type) ? 'ogg' : 'webm'
|
|
607
|
+
const name = hex + '.' + ext
|
|
608
|
+
const url = location.origin + '/assets/' + VOICE_FOLDER + '/' + name
|
|
609
|
+
const have = await fetch(url, { method: 'HEAD', cache: 'no-store' }).then(r => r.ok, () => false)
|
|
610
|
+
if (!have) {
|
|
611
|
+
const form = new FormData()
|
|
612
|
+
form.append('assets', VOICE_FOLDER) // before the file: the server reads the folder first
|
|
613
|
+
form.append('uploads[]', blob, name)
|
|
614
|
+
const r = await fetch('/plugin/assets/upload', { method: 'POST', body: form, credentials: 'same-origin' })
|
|
615
|
+
if (!r.ok) throw new Error(r.status === 401 ? 'sign in to this wiki to save recordings as files' : 'upload failed (' + r.status + ')')
|
|
616
|
+
}
|
|
617
|
+
return url
|
|
618
|
+
}
|
|
619
|
+
// Move every embedded recording in these walks to a file; resolves to a note
|
|
620
|
+
// for the reader when some could not be moved, else ''.
|
|
621
|
+
async function voicesToFiles (walks) {
|
|
622
|
+
const vs = voiceSteps(walks)
|
|
623
|
+
let failed = '', n = 0
|
|
624
|
+
for (const v of vs) {
|
|
625
|
+
try { v.audio = await voiceFile(v.audio); n++ } catch (e) { failed = e.message || String(e) }
|
|
626
|
+
}
|
|
627
|
+
if (n) console.log('voice files: ' + n + ' recording' + (n === 1 ? '' : 's') + ' now point to assets/' + VOICE_FOLDER + ' (each file is uploaded once)')
|
|
628
|
+
return failed ? 'Recordings were kept inside the page: ' + failed + '.' : ''
|
|
629
|
+
}
|
|
630
|
+
function voiceNotice ($item, msg) {
|
|
631
|
+
$item.find('.voice-note').remove()
|
|
632
|
+
if (msg) $item.append($('<div class="voice-note" style="font-size:12px;color:#92400e;padding:4px 0"></div>').text(msg))
|
|
633
|
+
}
|
|
634
|
+
|
|
584
635
|
// Save-back from the full tool. Only the window this page opened is heard,
|
|
585
636
|
// and it saves into the item opened last.
|
|
586
637
|
function toolListener (event) {
|
|
587
638
|
if (!pending || !event.data || event.data.toolType !== 'rcn-timeline') return
|
|
588
639
|
if (pending.win && event.source !== pending.win) return
|
|
589
640
|
if (event.data.action !== 'saveTimeline' || !event.data.timeline) return
|
|
590
|
-
const { item, $item } = pending
|
|
641
|
+
const { item, $item } = pending, src = event.source
|
|
591
642
|
const tl = event.data.timeline
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
643
|
+
voicesToFiles(tl.walks).then(note => {
|
|
644
|
+
item.timeline = Object.assign({ intervals: tl.intervals || [], links: tl.links || [] }, Array.isArray(tl.walks) && tl.walks.length ? { walks: tl.walks } : {})
|
|
645
|
+
delete item.frozen // what was frozen is now in the item's own timeline
|
|
646
|
+
item.text = words(item, item.timeline)
|
|
647
|
+
save($item, item)
|
|
648
|
+
voiceNotice($item, note)
|
|
649
|
+
try { src.postMessage({ toolType: 'rcn-timeline', action: 'saved', page: $item.parents('.page:first').data('data').title }, '*') } catch (e) {}
|
|
650
|
+
})
|
|
597
651
|
}
|
|
598
652
|
|
|
599
653
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wiki-plugin-rcntimeline",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Federated Wiki plugin: a small RCN timeline on a page — intervals with fuzzy edges, the links between them, a date axis; each bar opens its page",
|
|
5
5
|
"keywords": ["wiki", "federated wiki", "plugin", "rcn", "timeline"],
|
|
6
6
|
"author": "RCN Network <rcn@relocalizecreativity.net>",
|