Sync notes from dragonroll to foundry #98
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Make that each dragonroll is a page in foundry of the same journal called Dragonroll. Make it also sync
Now let me read the backend sync route:
Now let me look at the Note model, the note routes, and the existing tests:
Now let me look at the backend index.js, note.js rest, and check the docs for foundry content:
I have the full picture now. Let me implement. Starting with the backend model and sync routes:
Now add the two note endpoints to
foundry-link.js:Now the Foundry module. I'll add the notes sync section between the character sync and the bridge publishing:
Now update the existing test harnesses that load
foundry-link.jsso they stub the newNotemodel require:Now the new test file:
Let me fix a shared-state hazard in the test fixtures (the map-note fetch stub mutates note objects, so shared constants would leak state between tests):
Now let's run the full test suite:
Two fixes needed. Let me look at the force-import harness and fix both:
The repo is squashed, but a version bump for a new module feature follows Foundry convention. Now the documentation updates — module README, user docs, and AGENTS.md:
All tests pass. Let me do a final review of the complete diff:
Implemented issue #98: every Dragonroll note now stands as a page of one Foundry journal called Dragonroll, kept in sync. All 361 tests pass (12 of them new).
How it works — it follows the existing character/item sync patterns end to end:
Backend (
backend/src/routes/foundry-link.js,backend/src/models/Note.js)GET /api/foundry/sync/notesanswers with every note of the campaign — title, markdown content, and thefoundryPageIdit already stands as.POST /api/foundry/sync/map-noterecords the page the module created for a note (world-checked, campaign-scoped, refuses a page already mapped to another note, likemap-item).NotegainedfoundryPageIdwith the same campaign-scoped partial unique indexfoundryItemId/foundryFolderIduse.Foundry module (
dragonroll-foundry/scripts/api.js, v0.5.0)reconcileDragonrollNotes()loop reads the campaign's notes every 5 s (same rhythm as the characters/items reconcile, gated by the sync token and the Auto-sync setting) and writes each note as a page of oneJournalEntrynamed Dragonroll — creating the journal, or adopting and flagging one the GM already made under that name.TextEditor._getMarkdown), with escaped paragraphs as a fallback.dragonroll-foundry.noteIdflag: editing a note rewrites its page, deleting one drops the page, and the GM's own pages in that journal are never touched. A page mapped byfoundryPageIdbut whose flag was lost is claimed instead of doubled. Pages already in step are not rewritten. The copy runs one way — notes are written in Dragonroll — so nothing in the journal travels back.Tests (
tests/foundry-note-journal.test.js): the backend pairing routes, and the module side in the usualnode:vmstubbed-Foundry harness — journal creation/adoption, rendering, edit/delete propagation, no-rewrite churn, orphan-page claiming, fallback renderer, and autosync-off. The three existing harnesses that loadfoundry-link.jsgained the one-lineNotemodel stub.Docs: the Foundry docs page's "What syncs" table plus a one-way-sync paragraph, the module README's routes table and a "Notes" section, and the AGENTS.md sync rules.
Implementation is ready for review: #103