Add a "force import from foundry" context button #77

Closed
opened 2026-10-15 16:47:13 +00:00 by Syndria98 · 5 comments
Owner

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.

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.
Syndria98 added the ai-ready label 2026-10-15 16:47:13 +00:00
Agent added the working label 2026-10-15 17:36:58 +00:00
Collaborator

Now let me implement the backend. First, export the shared writers from the sync route:

Now let me implement the backend. First, export the shared writers from the sync route:
Collaborator

Now the sidebar context menu:

Now the sidebar context menu:
Collaborator

Now the test file:

Now the test file:
Collaborator

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" (with import.svg), above Move to folder. Maps keep their menu as-is. Clicking it posts /foundry/import for the section's whole list (kind: 'actors' | 'items'), then:

  • green confirmation toast saying how the world landed — "Imported from Foundry: {imported} new, {updated} updated." — and re-reads the list so what arrived is on screen;
  • red toast with what the backend said when it could not (same t(response.data.msg || fallback) shape the other windows use);
  • a guard so clicking another row while the world is on its way does not start a second import.

The backend

backend/src/routes/foundry.js gets POST /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.js only grew: its two writers now report created (so new rows count apart from written-over ones) and are exported for routes/foundry.js to reuse.

Strings were added to all three locales (campaigns.foundry-import.*, foundry.errors.import-*), and the foundry API-surface lines in AGENTS.md mention 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.

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"** (with `import.svg`), above *Move to folder*. Maps keep their menu as-is. Clicking it posts `/foundry/import` for the section's whole list (`kind: 'actors' | 'items'`), then: - **green confirmation toast** saying how the world landed — *"Imported from Foundry: {imported} new, {updated} updated."* — and re-reads the list so what arrived is on screen; - **red toast** with what the backend said when it could not (same `t(response.data.msg || fallback)` shape the other windows use); - a guard so clicking another row while the world is on its way does not start a second import. ## The backend `backend/src/routes/foundry.js` gets `POST /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.js` only grew: its two writers now report `created` (so new rows count apart from written-over ones) and are exported for `routes/foundry.js` to reuse. Strings were added to **all three locales** (`campaigns.foundry-import.*`, `foundry.errors.import-*`), and the `foundry` API-surface lines in `AGENTS.md` mention 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.
Collaborator

Implementation is ready for review: #80

Implementation is ready for review: https://git.aranroig.com/Syndria98/dragonroll/pulls/80
Agent added help wanted and removed working labels 2026-10-15 18:16:48 +00:00
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Syndria98/dragonroll#77