Skip to content

feat(chrome-extension): refresh Batch Download tree from a Feishu wiki - #148

Open
StrivingLee wants to merge 2 commits into
whale4113:mainfrom
StrivingLee:feat/wiki-hierarchy-refresh
Open

StrivingLee wants to merge 2 commits into
whale4113:mainfrom
StrivingLee:feat/wiki-hierarchy-refresh

Conversation

@StrivingLee

Copy link
Copy Markdown

What

An optional Refresh from Feishu wiki card on the Batch Download page. Paste a wiki page URL, and it rebuilds the tree from that page and everything under it, in sidebar order:

  • each page becomes NNN - title (numbering can be turned off), and a page with children is followed by a same-name folder
  • non-document nodes (uploaded files) are skipped, and listed with links
  • you see a preview of added, removed, renamed and moved pages, and the tree changes only when you click Apply
  • Refresh before each export (off by default): when the wiki is unchanged, the export starts at once. When it changed, you choose Apply and export, Export current tree or Cancel
  • pages are matched by wiki token, so documents already extracted in this session keep their result and status

Advanced options are stored per wiki: pages to place before the root, title overrides, and a top-level section filter (numbers stay as in the full tree).

Why

Large wikis drift: pages get added, renamed and reordered. Manual capture and Import State then go stale, and keeping them in sync by hand is error-prone.

How

  • wiki-hierarchy.ts: pure walk/build/diff/carry-over with no imports, unit-tested.
  • wiki-fetch.ts: credentialed fetch from the extension page. If the session cookie isn't sent, it falls back to the same fetch inside a Feishu tab via chrome.scripting.
  • Uses the web app's own tree endpoints (/space/api/wiki/v2/tree/get_info, get_node_child), throttled and retried. A failed walk leaves the tree untouched.
  • No new permissions. The URL is limited to the hosts already in host_permissions.

Also: the log is now cleared at the start of an export, so refresh messages stay visible. README (EN and ZH) now describes Batch Download and the wiki refresh.

Notes

  • vue-i18n can't compile {placeholders} at runtime under the extension CSP, so the card fills placeholders itself.
  • The tree endpoints are internal. If they change, the refresh fails loudly and nothing else is affected.

Tests

  • tests/wiki-hierarchy.test.ts: 12 unit tests (walk order and retry, abort, build, subsets, numbering width, diff, carry-over, URL host checks)
  • apps/chrome-extension-e2e/tests/batch-download-wiki-refresh.e2e.test.ts: 5 Playwright journeys on the built extension against a stubbed Feishu API (no account needed)
  • Checked against a real 361-page wiki: output identical to the previously hand-verified tree
  • lint, format-check, type-check, vitest and build all pass

Add an optional "Refresh from Feishu wiki" card to the Batch Download page.
Given a wiki page URL, it walks the page and everything under it in sidebar
order (the same tree API the web app's sidebar uses) and rebuilds the tree:
each page as "NNN - title" (numbering optional), a page with children
followed by a same-name folder, non-document nodes dropped and reported.

- Preview before replace: added / removed / renamed / moved pages.
- "Refresh before each export" (off by default) gates Export/Resume:
  unchanged wikis start at once; changes wait for Apply and export,
  Export current tree, or Cancel. A failed walk never exports a stale tree.
- Atomic: any failed request leaves the current tree untouched.
- Pages are matched by wiki token, so in-session extractions and statuses
  carry over; ZIP paths follow the new names.
- Per-wiki options: pages before the root, title overrides, top-level
  section filter (keeps full-tree numbering).
- Auth: direct credentialed fetch, falling back to an in-tab fetch via
  chrome.scripting. No new permissions; URLs limited to manifest hosts.

Also clear the log at the start of an export so refresh messages stay
visible, and add unit tests plus a hermetic Playwright e2e suite.
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.

1 participant