Add a "force import from foundry" context button #77
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?
When right clicking on the sidebar on actors or items, add a button called "force import from foundry" that forces the import of all the items or actors from foundry. Make that if there are already existing they only get updated not imported. Also make that it shows a confirmation toast when the process is done.
Now let me implement the backend. First, export the shared writers from the sync route:
Now the sidebar context menu:
Now the test file:
Implemented. Here's what landed:
The button
frontend/app/components/partials/ContentSidebar.vue— right-clicking an actor or item row now offers "Force import from Foundry" (withimport.svg), above Move to folder. Maps keep their menu as-is. Clicking it posts/foundry/importfor the section's whole list (kind: 'actors' | 'items'), then:t(response.data.msg || fallback)shape the other windows use);The backend
backend/src/routes/foundry.jsgetsPOST /import(JWT-protected by its mount position, campaign ownership checked like/icons). It reads the linked world's snapshot off the bridge (api/actors/api/items) and writes every document through the same writers the module's sync pushes use, so "existing rows are only updated, not imported again" comes from the one set of matching rules (Foundry id → Dragonroll flag → a name only one row could mean) rather than a second copy of it. It answers{status:'ok', kind, imported, updated}; documents that map to nothing (non-gear, nameless actor) are skipped like a sync skips them. Nothing is pruned — only a full snapshot from the module sees the whole world, so that stays its job. Guardrails, all in the usual HTTP-200{status,msg}envelope: campaign not yours →errors.notfound, world not linked →foundry.errors.import-not-linked, bridge missing/unreachable/silent →foundry.errors.import-unavailable, and a snapshot of another world is refused (foundry.errors.import-world-mismatch) rather than written into the campaign.backend/src/routes/foundry-link.jsonly grew: its two writers now reportcreated(so new rows count apart from written-over ones) and are exported forroutes/foundry.jsto reuse.Strings were added to all three locales (
campaigns.foundry-import.*,foundry.errors.import-*), and thefoundryAPI-surface lines inAGENTS.mdmention the new route.Tests
tests/foundry-force-import.test.js(15 tests): the route against a fake bridge/fake writers (ownership, kind validation, not-linked, bridge trouble, world mismatch writing nothing, new-vs-updated counts) and the writers against fake models — the issue's core rule, importing a world twice leaves one row per document and the second pass writes the world over it, including a hand-made item folding in instead of doubling. Plus source checks on the sidebar and the three locale files.npm test: 280 tests, 280 pass, 0 fail (265 before). I did not run the app itself — no dependencies are installed here, so the Nuxt build and a live Foundry world were not exercised.Implementation is ready for review: #80