Skip to content

Added the sync site export behind the selfServeArchives flag - #30054

Merged
sagzy merged 6 commits into
generalize-export-filenamefrom
sync-site-export
Aug 20, 2026
Merged

sagzy merged 6 commits into
generalize-export-filenamefrom
sync-site-export

Conversation

@sagzy

@sagzy sagzy commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

closes https://linear.app/ghost/issue/GVA-917

Implements the sync delivery mode of the one-click data export, building on the mockup that landed in #29915 and the four behaviour-preserving refactors below this PR in the stack. With the selfServeArchives labs flag on, "Export data" now really downloads a full site archive: GET /ghost/api/admin/exports/download/ streams one zip composed of content JSON, members CSV, post analytics CSV, per-theme zips, and routes/redirects — everything except media, which stays reserved for the host (async) mode that isn't part of this PR (its dialog branch remains mocked).

How the zip is composed

The orchestrator calls the same services the five standalone export endpoints call — no HTTP self-calls, no background jobs, no duplicated controller logic:

flowchart LR
    UI["Export data dialog"] -- "GET /exports/download/?components=…" --> C["exports controller"]
    C --> SE["SiteExporter (services/exports)"]
    SE -- "membersService.export({limit:'all'})" --> M["members.csv"]
    SE -- "postsService.export({limit:'all'})" --> A["post-analytics.csv"]
    SE -- "doExport()" --> J["export.json"]
    SE -- "themeStorage.zipToFile()" --> T["themes/{name}.zip"]
    SE -- "routeSettings / customRedirects" --> R["routes.yaml + redirects.yaml"]
    M & A & J & T & R --> Z["archiver zip → streamed response"]
Loading

Decisions worth reviewing:

  • Streamed, not staged. The zip pipes to the response while it's built, so memory stays flat and the download starts immediately. The price is failure semantics: once headers are sent, a component that fails to acquire can only be skipped (it's logged server-side and simply absent from the bundle). A mid-stream failure of a CSV source deliberately destroys the archive — a visibly broken download beats a silently incomplete one — and stream lifecycles are tied together in both directions so a dropped DB connection can't hang the response and a client disconnect can't pin a DB connection or leak staged temp files.
  • Restorable artifacts. export.json is byte-identical to the /db/ download and themes are the exact zips the theme upload accepts, so every piece of the bundle restores through existing import surfaces — proven by a round-trip e2e test that re-imports each artifact through the real import endpoints.
  • Permissions reuse db.exportContent (Owner/Administrator only) instead of minting a new permission + migration: a site export contains everything a database export contains, so the same gate applies — and it's a superset of every composed component's own requirement.
  • Flag-only gating. The feature stays behind the selfServeArchives labs flag, and that flag is the whole gate — no config capability signal for deploy skew at this stage. If the flag graduates, feature detection can come back with the GA work.
  • The dialog downloads through the fetch-based blob helper rather than a plain navigation: a navigation download is unobservable from the page, which would leave the dialog stuck on "Preparing your export…" forever and swallow errors. The blob approach gives a real "Export downloaded" state, error feedback with retry, and a working Cancel (AbortController). Browsers back large blobs with disk, so the zip doesn't have to fit in tab memory.
  • archiver becomes a direct dependency of ghost/core, but adds no new code to the tree: @tryghost/zip already pins the same [email protected] internally, and its own file-based compress/extract API can't stream a zip into an HTTP response.

Testing it locally

  1. pnpm dev, then in Ghost Admin enable Settings → Labs → Private features → Self-serve archives (developer experiments must be on).
  2. Go to Settings → Import/Export → Export — the individual export buttons are replaced by one Export data button.
  3. Pick components and hit Export: the dialog shows "Preparing your export…" with a working Cancel, and flips to "Export downloaded" when the zip lands in your downloads.
  4. Restore-compatibility: the zip's export.json imports via the universal importer, members.csv via the members importer, themes/*.zip via theme upload, routes.yaml/redirects.yaml via their uploads.
  5. With the flag off, the Export tab is byte-identical to main.

Automated tests

  • SiteExporter unit tests cover the failure paths: component skipping, partial themes, mid-stream teardown, client-abort cleanup.
  • E2E tests are split across two files by necessity: the 4xx cases (validation, labs gate, permissions) use the in-process agent, while the actual downloads run over real HTTP like the theme download tests — the in-process agent's mock socket never signals drain, deadlocking any streamed body larger than the write buffer.
  • The download test seeds more posts than the posts exporter's default page cap, guarding against silent truncation (an unlimited export once defaulted to 15 posts).
  • A round-trip e2e test re-imports every artifact through the real import endpoints, so format drift fails CI instead of surfacing as a broken restore.
  • Admin acceptance tests cover both dialog modes, component selection, and the download-complete and download-failed states.

@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: QUIET

Plan: Pro Plus

Run ID: 528cc40f-63fc-4542-a25b-24f620640cb4

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nx-cloud

nx-cloud Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 52d81a3

Command Status Duration Result
nx run @tryghost/admin:test:acceptance ✅ Succeeded 7m 21s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-08-20 11:32:41 UTC

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31b9f21aa7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codecov

codecov Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.31051% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.56%. Comparing base (28a1fdf) to head (52d81a3).

Files with missing lines Patch % Lines
ghost/core/core/server/api/endpoints/exports.js 92.80% 10 Missing ⚠️
...core/core/server/services/exports/site-exporter.ts 99.50% 1 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                       @@
##           generalize-export-filename   #30054      +/-   ##
==============================================================
+ Coverage                       75.31%   75.56%   +0.25%     
==============================================================
  Files                            1625     1630       +5     
  Lines                          145064   145473     +409     
  Branches                        17985    18142     +157     
==============================================================
+ Hits                           109248   109928     +680     
+ Misses                          34814    34517     -297     
- Partials                         1002     1028      +26     
Flag Coverage Δ
e2e-tests 77.42% <97.31%> (+0.27%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

9larsons added a commit that referenced this pull request Aug 19, 2026
no ref

The settings shell and the shared `components/`, `hooks/`, `utils/`,
`data/`, `assets/` and `providers/` now live directly under `settings/`,
leaving only `advanced/` in `settings/app/` until the PRs touching it
land (#30018, #30019, #29916, #30054, #30099, #30110, #28368). Big diff,
but ~300 of the 325 files are import-line rewrites; the substantive
changes are the lint-debt fixes the move surfaces:

- shell files grouped in `settings/layout/`: `app.tsx` (provider tree),
`main-content.tsx`, `sidebar.tsx`, `settings-sections.tsx` (was
`components/settings.tsx`); root `settings.tsx` route entry unchanged
- contexts split the way admin's other contexts are — hooks + context in
`*-context.ts`, provider component in its own file — for global data,
settings app, confirmations, scroll sections; `withErrorBoundary` →
`with-error-boundary.tsx`
- `loadKoenig` → `components/koenig-loader.ts`; the untyped
`@tryghost/koenig-lexical` bundle gets a minimal `KoenigLexicalModule`
type instead of `any`
- `@tryghost/limit-service` and `@tryghost/nql` get typed ambient
declarations in `vite-env.d.ts` (clears ~25 `no-unsafe-*` in
`use-limiter`)
- `iframe-buffering` reuses `utils/debounce`; `TopLevelGroup.saveState`
uses the framework's `SaveState`; the usual `void`-wrapping of async
handlers
Comment thread pnpm-workspace.yaml Resolved
Comment thread ghost/core/package.json Resolved
Comment thread ghost/core/types/archiver.d.ts Resolved
@sagzy
sagzy force-pushed the sync-site-export branch from 0619b5b to 285c158 Compare August 20, 2026 09:44
sagzy added 4 commits August 20, 2026 11:58
ref https://linear.app/ghost/issue/GVA-921/1-click-export-uxui

With the selfServeArchives flag on, "Export data" now really
downloads a full site archive: GET /ghost/api/admin/exports/download/
streams one zip composed in-process from the same services the five
standalone export endpoints call — content JSON, members CSV, post
analytics CSV, per-theme zips, routes and redirects. Everything
except media, which stays reserved for the host (async) mode. Every
artifact restores through an existing import surface, proven by a
round-trip e2e test against the real import endpoints.

The zip streams while it is built, so memory stays flat and the
download starts immediately; a component that fails to acquire is
skipped and logged, since headers are already on the wire. Streaming
entries tie their lifecycle to the archive in both directions so a
dropped DB connection cannot hang the response and a client
disconnect cannot pin a DB connection or leak staged temp files. The
dialog downloads through the fetch-based blob helper so it can show
a real downloaded state, surface errors, and cancel.
The catalog convention is exact pins, and pinning to 8.0.0 keeps a
single archiver copy in the tree, deduped with the same version
@tryghost/zip already depends on. A caret range could drift to a
newer 8.x on a future install, splitting the tree into two copies and
drifting from the hand-written type declarations in ghost/core.
The done state fires once the zip blob has been handed to the
browser's download manager, but users with 'Ask where to save each
file' enabled still see the save dialog after that point — so 'Export
downloaded' could appear before (or without) the file landing
anywhere. 'Export complete' stays truthful in both cases: the export
and transfer really are finished, only the save location may still be
pending.
ghost/core is the only workspace consumer, so declaring the exact
version directly keeps the catalog for genuinely shared dependencies.
The resolved version is unchanged and stays deduped with the copy
@tryghost/zip depends on.
@sagzy
sagzy force-pushed the sync-site-export branch from 285c158 to 4c50013 Compare August 20, 2026 09:58
@sagzy
sagzy merged commit 2a36710 into main Aug 20, 2026
101 of 105 checks passed
@sagzy
sagzy deleted the sync-site-export branch August 20, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants