PB + Writer (#287)

* add pb models

* api rules has updated to view public

* pb setup is completed

* add migrate script

* add pb migrations

* ignore storage

* add pocketbase SDK dependency

* change Tag.id and PageCardDto.id to string for PocketBase

* add DocV1 content block types

* add PB client singleton and PB record types

* rewrite factory for PocketBase record types

* rewrite api.ts for PocketBase SDK

* remove unused Strapi files, add PB to config

* mark Task 7 complete in plan

* feat: verify build, tests, and lint pass with PocketBase API layer

* move completed plan: 2026-04-06-pocketbase-api-layer.md

* scaffold hudozka-writer with Vite 8, React 19, TS 5.9, Tiptap

* add PocketBase client and DocV1 types to writer

* add Login component for PocketBase superuser auth

* add App shell with auth gate and page loader

* add DocV1 <-> Tiptap serialization layer

* mark Task 5 complete in writer redesign plan

* add custom Tiptap nodes for DocV1 block types

* add Tiptap editor with toolbar and save to PocketBase

* add image picker with browse and upload

* feat: verify writer build and complete integration task

* move completed plan: 2026-04-06-hudozka-writer-redesign.md

* add local env

* rm textblock from writer

* add writer editor improvements design spec

* add writer editor improvements implementation plan

* feat: use @tiptap/markdown for text block serialization

* feat: add global markdown/rendered toggle

* feat: add BlockMenu component for block type selection

* feat: add hover + button for block insertion

* feat: add slash commands for block insertion

* feat: add interactive file block editor with FilePicker

* feat: show resolved page titles in card grid block

* move completed plan: 2026-04-07-writer-editor-improvements.md

* writer ui improved

* pages migration

* spec: draft/publish workflow for hudozka-writer

* spec: rename draft_doc to draft in spec

* plan: writer draft/publish implementation

* plan has moved

* gitignores

* plans upd

* feat(writer): update PbPage type for draft/publish workflow

* feat(writer): add save/publish/discard handlers with dirty tracking

* feat(writer): add DraftBanner component

* feat(writer): add Publish button and update toolbar layout

* feat(writer): add published toggle and update duplicate for new schema

* docs: mark manual verification steps as skipped in writer draft/publish plan

* move completed plan: 20260407-writer-draft-publish.md

* feat(writer): add BlockActions component for inline block menus

* feat(writer): add draggable NodeViews for text blocks

* feat(writer): use BlockActions in custom block NodeViews

* feat(writer): replace floating BlockInsert with inline BlockActions

* fix(writer): ensure all block wrappers have position: relative for BlockActions

* chore: mark manual verification tasks as skipped in writer block actions plan

* move completed plan: 20260408-writer-block-actions.md

* writer update

* refactor(writer): simplify BlockActions to always-visible delete + drag handle

* feat(writer): add BlockInsert component for inserting blocks between nodes

* feat(writer): redesign block sidebar with always-visible actions and insert button

* move completed plan: 20260408-writer-block-actions-redesign.md

* add spec: textblock container redesign for writer editor

* feat(writer): add TextBlock container node definition

* feat(writer): replace DraggableXxx wrappers with TextBlock container

* feat(writer): update Editor extensions for TextBlock container

* feat(writer): add split button to BlockActions for text blocks

* feat(writer): update serialization for TextBlock container

* feat(writer): update BlockMenu and SlashCommands for TextBlock

* fix(writer): use Fragment.from() for replaceWith calls in BlockActions and SlashCommands

* move completed plan: 20260408-textblock-container.md

* add air
This commit is contained in:
tmshv authored and GitHub committed 2026-04-12 19:02:03 +03:00
1 parent 907298779c
commit ed3f93de53
109 files changed
+40520 -427

No files matched your search

@@ -0,0 +1,4 @@
STRAPI_URL=https://hudozka.tmshv.com
POCKETBASE_URL=http://127.0.0.1:8090
POCKETBASE_EMAIL=admin@example.com
POCKETBASE_PASSWORD=changeme
+3
View File
@@ -0,0 +1,3 @@
node_modules
.env
.migrate-state.json
+18
View File
@@ -0,0 +1,18 @@
# migrate-to-pocketbase
One-shot Strapi → PocketBase migration.
## Usage
```
cp .env.example .env
# fill in credentials
npm install
npm run migrate
```
Requires Node 24+ (uses `--experimental-strip-types`).
Assumes all 5 PocketBase collections already exist
(see `docs/plans/completed/20260403-pocketbase-setup-guide.md`).
Assumes collections are empty — script does not upsert.
+535
View File
@@ -0,0 +1,535 @@
{
"name": "migrate-to-pocketbase",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "migrate-to-pocketbase",
"version": "1.0.0",
"dependencies": {
"nanoid": "^5.0.0",
"pocketbase": "^0.26.0",
"sharp": "^0.33.0"
}
},
"node_modules/@emnapi/runtime": {
"version": "1.9.2",
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.9.2.tgz",
"integrity": "sha512-3U4+MIWHImeyu1wnmVygh5WlgfYDtyf0k8AbLhMFxOipihf6nrWC4syIm/SwEeec0mNSafiiNnMJwbza/Is6Lw==",
"license": "MIT",
"optional": true,
"dependencies": {
"tslib": "^2.4.0"
}
},
"node_modules/@img/sharp-darwin-arm64": {
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/@img/sharp-darwin-arm64/-/sharp-darwin-arm64-0.33.5.tgz",
"integrity": "sha512-UT4p+iz/2H4twwAoLCqfA9UH5pI6DggwKEGuaPy7nCVQ8ZsiY5PIcrRvD1DzuY3qYL07NtIQcWnBSY/heikIFQ==",
"cpu": [
"arm64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"funding": {
"url": "https://opencollective.com/libvips"
},
"optionalDependencies": {
"@img/sharp-libvips-darwin-arm64": "1.0.4"
}
},
"node_modules/@img/sharp-darwin-x64": {
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/@img/sharp-darwin-x64/-/sharp-darwin-x64-0.33.5.tgz",
"integrity": "sha512-fyHac4jIc1ANYGRDxtiqelIbdWkIuQaI84Mv45KvGRRxSAa7o7d1ZKAOBaYbnepLC1WqxfpimdeWfvqqSGwR2Q==",
"cpu": [
"x64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"funding": {
"url": "https://opencollective.com/libvips"
},
"optionalDependencies": {
"@img/sharp-libvips-darwin-x64": "1.0.4"
}
},
"node_modules/@img/sharp-libvips-darwin-arm64": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-arm64/-/sharp-libvips-darwin-arm64-1.0.4.tgz",
"integrity": "sha512-XblONe153h0O2zuFfTAbQYAX2JhYmDHeWikp1LM9Hul9gVPjFY427k6dFEcOL72O01QxQsWi761svJ/ev9xEDg==",
"cpu": [
"arm64"
],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
"darwin"
],
"funding": {
"url": "https://opencollective.com/libvips"
}
},
"node_modules/@img/sharp-libvips-darwin-x64": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-darwin-x64/-/sharp-libvips-darwin-x64-1.0.4.tgz",
"integrity": "sha512-xnGR8YuZYfJGmWPvmlunFaWJsb9T/AO2ykoP3Fz/0X5XV2aoYBPkX6xqCQvUTKKiLddarLaxpzNe+b1hjeWHAQ==",
"cpu": [
"x64"
],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
"darwin"
],
"funding": {
"url": "https://opencollective.com/libvips"
}
},
"node_modules/@img/sharp-libvips-linux-arm": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm/-/sharp-libvips-linux-arm-1.0.5.tgz",
"integrity": "sha512-gvcC4ACAOPRNATg/ov8/MnbxFDJqf/pDePbBnuBDcjsI8PssmjoKMAz4LtLaVi+OnSb5FK/yIOamqDwGmXW32g==",
"cpu": [
"arm"
],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
"linux"
],
"funding": {
"url": "https://opencollective.com/libvips"
}
},
"node_modules/@img/sharp-libvips-linux-arm64": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-arm64/-/sharp-libvips-linux-arm64-1.0.4.tgz",
"integrity": "sha512-9B+taZ8DlyyqzZQnoeIvDVR/2F4EbMepXMc/NdVbkzsJbzkUjhXv/70GQJ7tdLA4YJgNP25zukcxpX2/SueNrA==",
"cpu": [
"arm64"
],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
"linux"
],
"funding": {
"url": "https://opencollective.com/libvips"
}
},
"node_modules/@img/sharp-libvips-linux-s390x": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-s390x/-/sharp-libvips-linux-s390x-1.0.4.tgz",
"integrity": "sha512-u7Wz6ntiSSgGSGcjZ55im6uvTrOxSIS8/dgoVMoiGE9I6JAfU50yH5BoDlYA1tcuGS7g/QNtetJnxA6QEsCVTA==",
"cpu": [
"s390x"
],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
"linux"
],
"funding": {
"url": "https://opencollective.com/libvips"
}
},
"node_modules/@img/sharp-libvips-linux-x64": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linux-x64/-/sharp-libvips-linux-x64-1.0.4.tgz",
"integrity": "sha512-MmWmQ3iPFZr0Iev+BAgVMb3ZyC4KeFc3jFxnNbEPas60e1cIfevbtuyf9nDGIzOaW9PdnDciJm+wFFaTlj5xYw==",
"cpu": [
"x64"
],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
"linux"
],
"funding": {
"url": "https://opencollective.com/libvips"
}
},
"node_modules/@img/sharp-libvips-linuxmusl-arm64": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-arm64/-/sharp-libvips-linuxmusl-arm64-1.0.4.tgz",
"integrity": "sha512-9Ti+BbTYDcsbp4wfYib8Ctm1ilkugkA/uscUn6UXK1ldpC1JjiXbLfFZtRlBhjPZ5o1NCLiDbg8fhUPKStHoTA==",
"cpu": [
"arm64"
],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
"linux"
],
"funding": {
"url": "https://opencollective.com/libvips"
}
},
"node_modules/@img/sharp-libvips-linuxmusl-x64": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/@img/sharp-libvips-linuxmusl-x64/-/sharp-libvips-linuxmusl-x64-1.0.4.tgz",
"integrity": "sha512-viYN1KX9m+/hGkJtvYYp+CCLgnJXwiQB39damAO7WMdKWlIhmYTfHjwSbQeUK/20vY154mwezd9HflVFM1wVSw==",
"cpu": [
"x64"
],
"license": "LGPL-3.0-or-later",
"optional": true,
"os": [
"linux"
],
"funding": {
"url": "https://opencollective.com/libvips"
}
},
"node_modules/@img/sharp-linux-arm": {
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/@img/sharp-linux-arm/-/sharp-linux-arm-0.33.5.tgz",
"integrity": "sha512-JTS1eldqZbJxjvKaAkxhZmBqPRGmxgu+qFKSInv8moZ2AmT5Yib3EQ1c6gp493HvrvV8QgdOXdyaIBrhvFhBMQ==",
"cpu": [
"arm"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"funding": {
"url": "https://opencollective.com/libvips"
},
"optionalDependencies": {
"@img/sharp-libvips-linux-arm": "1.0.5"
}
},
"node_modules/@img/sharp-linux-arm64": {
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/@img/sharp-linux-arm64/-/sharp-linux-arm64-0.33.5.tgz",
"integrity": "sha512-JMVv+AMRyGOHtO1RFBiJy/MBsgz0x4AWrT6QoEVVTyh1E39TrCUpTRI7mx9VksGX4awWASxqCYLCV4wBZHAYxA==",
"cpu": [
"arm64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"funding": {
"url": "https://opencollective.com/libvips"
},
"optionalDependencies": {
"@img/sharp-libvips-linux-arm64": "1.0.4"
}
},
"node_modules/@img/sharp-linux-s390x": {
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/@img/sharp-linux-s390x/-/sharp-linux-s390x-0.33.5.tgz",
"integrity": "sha512-y/5PCd+mP4CA/sPDKl2961b+C9d+vPAveS33s6Z3zfASk2j5upL6fXVPZi7ztePZ5CuH+1kW8JtvxgbuXHRa4Q==",
"cpu": [
"s390x"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"funding": {
"url": "https://opencollective.com/libvips"
},
"optionalDependencies": {
"@img/sharp-libvips-linux-s390x": "1.0.4"
}
},
"node_modules/@img/sharp-linux-x64": {
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/@img/sharp-linux-x64/-/sharp-linux-x64-0.33.5.tgz",
"integrity": "sha512-opC+Ok5pRNAzuvq1AG0ar+1owsu842/Ab+4qvU879ippJBHvyY5n2mxF1izXqkPYlGuP/M556uh53jRLJmzTWA==",
"cpu": [
"x64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"funding": {
"url": "https://opencollective.com/libvips"
},
"optionalDependencies": {
"@img/sharp-libvips-linux-x64": "1.0.4"
}
},
"node_modules/@img/sharp-linuxmusl-arm64": {
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-arm64/-/sharp-linuxmusl-arm64-0.33.5.tgz",
"integrity": "sha512-XrHMZwGQGvJg2V/oRSUfSAfjfPxO+4DkiRh6p2AFjLQztWUuY/o8Mq0eMQVIY7HJ1CDQUJlxGGZRw1a5bqmd1g==",
"cpu": [
"arm64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"funding": {
"url": "https://opencollective.com/libvips"
},
"optionalDependencies": {
"@img/sharp-libvips-linuxmusl-arm64": "1.0.4"
}
},
"node_modules/@img/sharp-linuxmusl-x64": {
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/@img/sharp-linuxmusl-x64/-/sharp-linuxmusl-x64-0.33.5.tgz",
"integrity": "sha512-WT+d/cgqKkkKySYmqoZ8y3pxx7lx9vVejxW/W4DOFMYVSkErR+w7mf2u8m/y4+xHe7yY9DAXQMWQhpnMuFfScw==",
"cpu": [
"x64"
],
"license": "Apache-2.0",
"optional": true,
"os": [
"linux"
],
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"funding": {
"url": "https://opencollective.com/libvips"
},
"optionalDependencies": {
"@img/sharp-libvips-linuxmusl-x64": "1.0.4"
}
},
"node_modules/@img/sharp-wasm32": {
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/@img/sharp-wasm32/-/sharp-wasm32-0.33.5.tgz",
"integrity": "sha512-ykUW4LVGaMcU9lu9thv85CbRMAwfeadCJHRsg2GmeRa/cJxsVY9Rbd57JcMxBkKHag5U/x7TSBpScF4U8ElVzg==",
"cpu": [
"wasm32"
],
"license": "Apache-2.0 AND LGPL-3.0-or-later AND MIT",
"optional": true,
"dependencies": {
"@emnapi/runtime": "^1.2.0"
},
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"funding": {
"url": "https://opencollective.com/libvips"
}
},
"node_modules/@img/sharp-win32-ia32": {
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/@img/sharp-win32-ia32/-/sharp-win32-ia32-0.33.5.tgz",
"integrity": "sha512-T36PblLaTwuVJ/zw/LaH0PdZkRz5rd3SmMHX8GSmR7vtNSP5Z6bQkExdSK7xGWyxLw4sUknBuugTelgw2faBbQ==",
"cpu": [
"ia32"
],
"license": "Apache-2.0 AND LGPL-3.0-or-later",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"funding": {
"url": "https://opencollective.com/libvips"
}
},
"node_modules/@img/sharp-win32-x64": {
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/@img/sharp-win32-x64/-/sharp-win32-x64-0.33.5.tgz",
"integrity": "sha512-MpY/o8/8kj+EcnxwvrP4aTJSWw/aZ7JIGR4aBeZkZw5B7/Jn+tY9/VNwtcoGmdT7GfggGIU4kygOMSbYnOrAbg==",
"cpu": [
"x64"
],
"license": "Apache-2.0 AND LGPL-3.0-or-later",
"optional": true,
"os": [
"win32"
],
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"funding": {
"url": "https://opencollective.com/libvips"
}
},
"node_modules/color": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/color/-/color-4.2.3.tgz",
"integrity": "sha512-1rXeuUUiGGrykh+CeBdu5Ie7OJwinCgQY0bc7GCRxy5xVHy+moaqkpL/jqQq0MtQOeYcrqEz4abc5f0KtU7W4A==",
"license": "MIT",
"dependencies": {
"color-convert": "^2.0.1",
"color-string": "^1.9.0"
},
"engines": {
"node": ">=12.5.0"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"license": "MIT",
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"license": "MIT"
},
"node_modules/color-string": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/color-string/-/color-string-1.9.1.tgz",
"integrity": "sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==",
"license": "MIT",
"dependencies": {
"color-name": "^1.0.0",
"simple-swizzle": "^0.2.2"
}
},
"node_modules/detect-libc": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
"integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
"license": "Apache-2.0",
"engines": {
"node": ">=8"
}
},
"node_modules/is-arrayish": {
"version": "0.3.4",
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.4.tgz",
"integrity": "sha512-m6UrgzFVUYawGBh1dUsWR5M2Clqic9RVXC/9f8ceNlv2IcO9j9J/z8UoCLPqtsPBFNzEpfR3xftohbfqDx8EQA==",
"license": "MIT"
},
"node_modules/nanoid": {
"version": "5.1.7",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.1.7.tgz",
"integrity": "sha512-ua3NDgISf6jdwezAheMOk4mbE1LXjm1DfMUDMuJf4AqxLFK3ccGpgWizwa5YV7Yz9EpXwEaWoRXSb/BnV0t5dQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/ai"
}
],
"license": "MIT",
"bin": {
"nanoid": "bin/nanoid.js"
},
"engines": {
"node": "^18 || >=20"
}
},
"node_modules/pocketbase": {
"version": "0.26.8",
"resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.26.8.tgz",
"integrity": "sha512-aQ/ewvS7ncvAE8wxoW10iAZu6ElgbeFpBhKPnCfvRovNzm2gW8u/sQNPGN6vNgVEagz44kK//C61oKjfa+7Low==",
"license": "MIT"
},
"node_modules/semver": {
"version": "7.7.4",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz",
"integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==",
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/sharp": {
"version": "0.33.5",
"resolved": "https://registry.npmjs.org/sharp/-/sharp-0.33.5.tgz",
"integrity": "sha512-haPVm1EkS9pgvHrQ/F3Xy+hgcuMV0Wm9vfIBSiwZ05k+xgb0PkBQpGsAA/oWdDobNaZTH5ppvHtzCFbnSEwHVw==",
"hasInstallScript": true,
"license": "Apache-2.0",
"dependencies": {
"color": "^4.2.3",
"detect-libc": "^2.0.3",
"semver": "^7.6.3"
},
"engines": {
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
},
"funding": {
"url": "https://opencollective.com/libvips"
},
"optionalDependencies": {
"@img/sharp-darwin-arm64": "0.33.5",
"@img/sharp-darwin-x64": "0.33.5",
"@img/sharp-libvips-darwin-arm64": "1.0.4",
"@img/sharp-libvips-darwin-x64": "1.0.4",
"@img/sharp-libvips-linux-arm": "1.0.5",
"@img/sharp-libvips-linux-arm64": "1.0.4",
"@img/sharp-libvips-linux-s390x": "1.0.4",
"@img/sharp-libvips-linux-x64": "1.0.4",
"@img/sharp-libvips-linuxmusl-arm64": "1.0.4",
"@img/sharp-libvips-linuxmusl-x64": "1.0.4",
"@img/sharp-linux-arm": "0.33.5",
"@img/sharp-linux-arm64": "0.33.5",
"@img/sharp-linux-s390x": "0.33.5",
"@img/sharp-linux-x64": "0.33.5",
"@img/sharp-linuxmusl-arm64": "0.33.5",
"@img/sharp-linuxmusl-x64": "0.33.5",
"@img/sharp-wasm32": "0.33.5",
"@img/sharp-win32-ia32": "0.33.5",
"@img/sharp-win32-x64": "0.33.5"
}
},
"node_modules/simple-swizzle": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.4.tgz",
"integrity": "sha512-nAu1WFPQSMNr2Zn9PGSZK9AGn4t/y97lEm+MXTtUDwfP0ksAIX4nO+6ruD9Jwut4C49SB1Ws+fbXsm/yScWOHw==",
"license": "MIT",
"dependencies": {
"is-arrayish": "^0.3.1"
}
},
"node_modules/tslib": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD",
"optional": true
}
}
}
@@ -0,0 +1,15 @@
{
"name": "migrate-to-pocketbase",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"migrate": "node --env-file=.env --experimental-strip-types --no-warnings=ExperimentalWarning src/index.ts",
"wipe": "node --env-file=.env --experimental-strip-types --no-warnings=ExperimentalWarning src/wipe.ts"
},
"dependencies": {
"nanoid": "^5.0.0",
"pocketbase": "^0.26.0",
"sharp": "^0.33.0"
}
}
@@ -0,0 +1,27 @@
import sharp from "sharp"
// Tiny jpeg base64 data URL for blur placeholder (matches src/remote/image.ts semantics).
export async function encodeBlur(buffer: Buffer): Promise<string | undefined> {
try {
const data = await sharp(buffer)
.resize(8, 8, { fit: "inside" })
.jpeg({ quality: 50 })
.toBuffer()
return `data:image/jpeg;base64,${data.toString("base64")}`
} catch (e) {
console.warn("blur failed:", (e as Error).message)
return undefined
}
}
export async function imageDims(buffer: Buffer): Promise<{ width: number, height: number } | undefined> {
try {
const meta = await sharp(buffer).metadata()
if (meta.width && meta.height) {
return { width: meta.width, height: meta.height }
}
} catch (e) {
console.warn("dims failed:", (e as Error).message)
}
return undefined
}
@@ -0,0 +1,19 @@
export async function download(url: string): Promise<Buffer> {
const res = await fetch(url)
if (!res.ok) {
throw new Error(`download ${url} -> ${res.status}`)
}
const buf = await res.arrayBuffer()
return Buffer.from(buf)
}
export function basenameFromUrl(url: string): string {
try {
const u = new URL(url)
const parts = u.pathname.split("/")
const last = parts[parts.length - 1]
return decodeURIComponent(last) || "file"
} catch {
return "file"
}
}
@@ -0,0 +1,5 @@
import { createHash } from "node:crypto"
export function sha256(buffer: Buffer): string {
return createHash("sha256").update(buffer).digest("hex")
}
+469
View File
@@ -0,0 +1,469 @@
import PocketBase from "pocketbase"
import { customAlphabet } from "nanoid"
const nanoid = customAlphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 10)
import { readFileSync, writeFileSync, existsSync } from "node:fs"
import type {
StrapiComponent,
StrapiMedia,
StrapiPageCard,
} from "./strapi.ts"
import {
fetchAllPages,
fetchHome,
fetchMenu,
fetchTags,
} from "./strapi.ts"
import { download, basenameFromUrl } from "./download.ts"
import { encodeBlur, imageDims } from "./blurhash.ts"
import { sha256 } from "./hash.ts"
const STRAPI_URL = process.env.STRAPI_URL ?? "https://hudozka.tmshv.com"
const POCKETBASE_URL = required("POCKETBASE_URL")
const POCKETBASE_EMAIL = required("POCKETBASE_EMAIL")
const POCKETBASE_PASSWORD = required("POCKETBASE_PASSWORD")
const STATE_FILE = new URL("../.migrate-state.json", import.meta.url).pathname
const PHASES = ["tags", "images", "files", "pages", "rewrite", "kv"] as const
type Phase = typeof PHASES[number]
function required(name: string): string {
const v = process.env[name]
if (!v) {
throw new Error(`missing env ${name}`)
}
return v
}
// Content blocks written to pages.doc JSON. During pages phase, image/file/page refs
// are strapi numeric ids; rewrite phase remaps them to PB string ids.
type Ref = string | number
type BlockBase = { id: string }
type BlockText = BlockBase & { type: "text", text: string }
type BlockImage = BlockBase & { type: "image", image: Ref, wide: boolean, caption: string }
type BlockDocument = BlockBase & { type: "document", file: Ref, title: string }
type BlockEmbed = BlockBase & { type: "embed", src: string }
type CardRef = { page: Ref, layout: "small" | "medium" | "big" }
type BlockCardGrid = BlockBase & { type: "card-grid", items: CardRef[] }
type Block = BlockText | BlockImage | BlockDocument | BlockEmbed | BlockCardGrid
type DocContent = { version: 1, blocks: Block[] }
type State = {
tagMap: Record<string, string>,
imageMap: Record<string, string>,
fileMap: Record<string, string>,
pageMap: Record<string, string>,
}
function loadState(): State {
if (existsSync(STATE_FILE)) {
const raw = readFileSync(STATE_FILE, "utf-8")
return JSON.parse(raw) as State
}
return { tagMap: {}, imageMap: {}, fileMap: {}, pageMap: {} }
}
function saveState(s: State) {
writeFileSync(STATE_FILE, JSON.stringify(s, null, 2))
}
function mapFromState(r: Record<string, string>): Map<number, string> {
const m = new Map<number, string>()
for (const [k, v] of Object.entries(r)) {
m.set(Number(k), v)
}
return m
}
function mapToState(m: Map<number, string>): Record<string, string> {
const r: Record<string, string> = {}
for (const [k, v] of m) {
r[String(k)] = v
}
return r
}
function parsePhases(args: string[]): Phase[] {
if (args.length === 0) return [...PHASES]
const unknown = args.filter(a => !PHASES.includes(a as Phase))
if (unknown.length > 0) {
console.error(`unknown phase(s): ${unknown.join(", ")}`)
console.error(`known phases: ${PHASES.join(", ")}`)
process.exit(1)
}
return args as Phase[]
}
async function main() {
const phases = parsePhases(process.argv.slice(2))
console.log(`phases: ${phases.join(", ")}`)
const pb = new PocketBase(POCKETBASE_URL)
await pb.collection("_superusers").authWithPassword(POCKETBASE_EMAIL, POCKETBASE_PASSWORD)
console.log("authed to pb")
const state = loadState()
const tagMap = mapFromState(state.tagMap)
const imageMap = mapFromState(state.imageMap)
const fileMap = mapFromState(state.fileMap)
const pageMap = mapFromState(state.pageMap)
console.log(`state: tags=${tagMap.size} images=${imageMap.size} files=${fileMap.size} pages=${pageMap.size}`)
console.log("\nfetching strapi...")
const [strapiPages, strapiTags, strapiHome, strapiMenu] = await Promise.all([
fetchAllPages(STRAPI_URL),
fetchTags(STRAPI_URL),
fetchHome(STRAPI_URL),
fetchMenu(STRAPI_URL),
])
console.log(`strapi: pages=${strapiPages.length} tags=${strapiTags.length} home.cards=${strapiHome.cards.length} menu.items=${strapiMenu.menu.items.length}`)
// phase: tags
if (phases.includes("tags")) {
console.log(`\n[tags] creating ${strapiTags.length}...`)
let ti = 0
for (const t of strapiTags) {
ti++
const payload = { label: t.name, slug: t.slug }
try {
const rec = await pb.collection("tags").create(payload)
tagMap.set(t.id, rec.id)
console.log(` [${ti}/${strapiTags.length}] ${t.slug} -> ${rec.id}`)
} catch (e) {
console.error(` [${ti}/${strapiTags.length}] tag ${t.id} (${t.slug}) failed:`)
printErr(e, payload)
throw e
}
}
state.tagMap = mapToState(tagMap)
saveState(state)
console.log(`[tags] done: ${tagMap.size}`)
}
// phase: images
if (phases.includes("images")) {
const imageMedia = new Map<number, StrapiMedia>()
for (const p of strapiPages) {
if (p.cover) {
imageMedia.set(p.cover.id, p.cover)
}
for (const c of p.content) {
if (c.__component === "hudozka.image" && c.media) {
imageMedia.set(c.media.id, c.media)
}
}
}
console.log(`\n[images] uploading ${imageMedia.size}...`)
const imageHashIndex = await buildHashIndex(pb, "images")
console.log(` sha256 index: ${imageHashIndex.size} existing records`)
let ii = 0
for (const [sid, m] of imageMedia) {
ii++
if (imageMap.has(sid)) {
console.log(` [${ii}/${imageMedia.size}] ${m.name} — skip (already uploaded)`)
continue
}
try {
const buf = await download(m.url)
const hash = sha256(buf)
const existingId = imageHashIndex.get(hash)
if (existingId) {
imageMap.set(sid, existingId)
console.log(` [${ii}/${imageMedia.size}] ${m.name} — dedup -> ${existingId}`)
continue
}
const filename = m.name || basenameFromUrl(m.url)
const dims = (m.width && m.height)
? { width: m.width, height: m.height }
: (await imageDims(buf) ?? { width: 0, height: 0 })
const blur = await encodeBlur(buf)
const form = new FormData()
form.append("file", new Blob([buf], { type: m.mime || "application/octet-stream" }), filename)
if (m.alternativeText) form.append("alt", m.alternativeText)
if (m.caption) form.append("caption", m.caption)
form.append("width", String(dims.width))
form.append("height", String(dims.height))
if (blur) {
form.append("blurhash", blur)
} else {
console.warn(` [blur] encode failed or empty`)
}
form.append("filename", filename)
form.append("sha256", hash)
const rec = await pb.collection("images").create(form)
imageMap.set(sid, rec.id)
imageHashIndex.set(hash, rec.id)
console.log(` [${ii}/${imageMedia.size}] ${filename} (${dims.width}x${dims.height}, ${Math.round(buf.byteLength / 1024)}KB, blur=${blur ? blur.length + "ch" : "none"}) -> ${rec.id}`)
} catch (e) {
console.error(` [${ii}/${imageMedia.size}] image ${sid} failed:`)
console.error(` strapi media:`, JSON.stringify({
id: m.id,
name: m.name,
mime: m.mime,
ext: m.ext,
sizeKB: m.size,
width: m.width,
height: m.height,
url: m.url,
}, null, 2))
printErr(e)
}
}
state.imageMap = mapToState(imageMap)
saveState(state)
console.log(`[images] done: ${imageMap.size}/${imageMedia.size}`)
}
// phase: files
if (phases.includes("files")) {
const docMedia = new Map<number, { id: number, url: string, name: string, mime: string, size: number }>()
for (const p of strapiPages) {
for (const c of p.content) {
if (c.__component === "hudozka.document" && c.media) {
docMedia.set(c.media.id, {
id: c.media.id,
url: c.media.url,
name: c.media.name,
mime: c.media.mime,
size: c.media.size,
})
}
}
}
console.log(`\n[files] uploading ${docMedia.size}...`)
const fileHashIndex = await buildHashIndex(pb, "files")
console.log(` sha256 index: ${fileHashIndex.size} existing records`)
let fi = 0
for (const [sid, m] of docMedia) {
fi++
if (fileMap.has(sid)) {
console.log(` [${fi}/${docMedia.size}] ${m.name} — skip (already uploaded)`)
continue
}
try {
const buf = await download(m.url)
const hash = sha256(buf)
const existingId = fileHashIndex.get(hash)
if (existingId) {
fileMap.set(sid, existingId)
console.log(` [${fi}/${docMedia.size}] ${m.name} — dedup -> ${existingId}`)
continue
}
const filename = m.name || basenameFromUrl(m.url)
const bytes = buf.byteLength
const form = new FormData()
form.append("file", new Blob([buf], { type: m.mime || "application/octet-stream" }), filename)
form.append("title", "")
if (m.mime) form.append("mime", m.mime)
form.append("size", String(bytes))
form.append("filename", filename)
form.append("sha256", hash)
const rec = await pb.collection("files").create(form)
fileMap.set(sid, rec.id)
fileHashIndex.set(hash, rec.id)
console.log(` [${fi}/${docMedia.size}] ${filename} (${Math.round(bytes / 1024)}KB) -> ${rec.id}`)
} catch (e) {
console.error(` [${fi}/${docMedia.size}] file ${sid} failed:`)
printErr(e)
}
}
state.fileMap = mapToState(fileMap)
saveState(state)
console.log(`[files] done: ${fileMap.size}/${docMedia.size}`)
}
// phase: pages
if (phases.includes("pages")) {
console.log(`\n[pages] creating ${strapiPages.length}...`)
let pi = 0
for (const p of strapiPages) {
pi++
if (pageMap.has(p.id)) {
console.log(` [${pi}/${strapiPages.length}] ${p.slug} — skip (already created)`)
continue
}
const blocks = p.content.map(toBlock).filter((b): b is Block => b !== null)
const doc: DocContent = { version: 1, blocks }
const coverId = p.cover ? imageMap.get(p.cover.id) : undefined
const tagIds = p.tags.map(t => tagMap.get(t.id)).filter((x): x is string => !!x)
const data: Record<string, unknown> = {
title: p.title,
slug: p.slug,
excerpt: p.excerpt ?? "",
doc,
tags: tagIds,
draft: false,
}
if (p.date) data.date = p.date
if (coverId) data.cover = coverId
try {
const rec = await pb.collection("pages").create(data)
pageMap.set(p.id, rec.id)
console.log(` [${pi}/${strapiPages.length}] ${p.slug} -> ${rec.id} (${blocks.length} blocks, ${tagIds.length} tags${coverId ? ", cover" : ""})`)
} catch (e) {
console.error(` [${pi}/${strapiPages.length}] page ${p.id} (${p.slug}) failed:`)
printErr(e)
}
}
state.pageMap = mapToState(pageMap)
saveState(state)
console.log(`[pages] done: ${pageMap.size}/${strapiPages.length}`)
}
// phase: rewrite. Remaps strapi numeric refs -> PB string ids:
// - doc blocks (image/file/card-grid)
// - tags relation
// Drops blocks with unresolved refs. Preserves nanoid block ids.
if (phases.includes("rewrite")) {
console.log(`\n[rewrite] remapping refs...`)
let rewritten = 0
let dropped = 0
for (const p of strapiPages) {
const pbId = pageMap.get(p.id)
if (!pbId) continue
try {
const rec = await pb.collection("pages").getOne(pbId, { fields: "doc" })
const doc = (rec as unknown as { doc: DocContent }).doc
const before = doc.blocks.length
doc.blocks = doc.blocks.map(b => remapBlock(b, imageMap, fileMap, pageMap)).filter((b): b is Block => b !== null)
dropped += before - doc.blocks.length
const tagIds = p.tags.map(t => tagMap.get(t.id)).filter((x): x is string => !!x)
await pb.collection("pages").update(pbId, { doc, tags: tagIds })
rewritten++
console.log(` rewrote ${p.slug} (${doc.blocks.length}/${before} blocks, ${tagIds.length} tags)`)
} catch (e) {
console.error(` rewrite page ${p.id} failed:`)
printErr(e)
}
}
console.log(`[rewrite] done: ${rewritten} pages, ${dropped} blocks dropped (unresolved refs)`)
}
// phase: kv (home + menu)
if (phases.includes("kv")) {
console.log(`\n[kv] creating home + menu...`)
const homeCards = strapiHome.cards
.map(c => ({ page: pageMap.get(c.page.id), layout: c.layout }))
.filter((c): c is { page: string, layout: "small" | "medium" | "big" } => !!c.page)
await pb.collection("kv").create({
key: "home",
data: { cards: homeCards },
})
console.log(`kv home: ${homeCards.length} cards`)
const menuItems = strapiMenu.menu.items
.map(c => ({ page: pageMap.get(c.page.id) }))
.filter((c): c is { page: string } => !!c.page)
await pb.collection("kv").create({
key: "menu",
data: {
homeLabel: strapiMenu.homeLabel,
items: menuItems,
},
})
console.log(`kv menu: homeLabel="${strapiMenu.homeLabel}" items=${menuItems.length}`)
}
console.log("\ndone.")
}
// Emit blocks with strapi numeric ids for media/page refs.
// The rewrite phase remaps them to PB string ids.
function toBlock(c: StrapiComponent): Block | null {
const id = nanoid()
switch (c.__component) {
case "hudozka.text":
return { id, type: "text", text: c.text }
case "hudozka.image":
if (!c.media) return null
return { id, type: "image", image: c.media.id, wide: !!c.wide, caption: c.caption ?? "" }
case "hudozka.document":
if (!c.media) return null
return { id, type: "document", file: c.media.id, title: c.title ?? "" }
case "hudozka.embed":
return { id, type: "embed", src: c.src }
case "hudozka.card-grid": {
const items: CardRef[] = (c.items ?? [])
.filter((it: StrapiPageCard) => it && it.page)
.map((it: StrapiPageCard) => ({ page: it.page.id, layout: it.layout }))
return { id, type: "card-grid", items }
}
default:
return null
}
}
// Remap strapi numeric refs -> PB string ids. Returns null if ref unresolved.
// If ref is already a string, pass through (already remapped).
function remapBlock(
b: Block,
imageMap: Map<number, string>,
fileMap: Map<number, string>,
pageMap: Map<number, string>,
): Block | null {
switch (b.type) {
case "image": {
if (typeof b.image === "string") return b
const ref = imageMap.get(b.image)
if (!ref) return null
return { ...b, image: ref }
}
case "document": {
if (typeof b.file === "string") return b
const ref = fileMap.get(b.file)
if (!ref) return null
return { ...b, file: ref }
}
case "card-grid": {
const items = b.items
.map(it => {
if (typeof it.page === "string") return it
const mapped = pageMap.get(it.page)
return mapped ? { page: mapped, layout: it.layout } : null
})
.filter((x): x is CardRef => x !== null)
return { ...b, items }
}
default:
return b
}
}
async function buildHashIndex(pb: PocketBase, collection: string): Promise<Map<string, string>> {
const idx = new Map<string, string>()
const recs = await pb.collection(collection).getFullList({ fields: "id,sha256" })
for (const r of recs) {
const h = (r as unknown as { sha256?: string }).sha256
if (h) idx.set(h, r.id)
}
return idx
}
function printErr(e: unknown, input?: unknown) {
const err = e as { message?: string, url?: string, status?: number, response?: { data?: unknown } }
console.error("ERROR:", err.message)
if (err.url) console.error(" url:", err.url, "status:", err.status)
if (input !== undefined) {
console.error(" input:", JSON.stringify(input, null, 2))
}
if (err.response?.data !== undefined) {
console.error(" response:", JSON.stringify(err.response.data, null, 2))
}
}
main().catch(e => {
printErr(e)
process.exit(1)
})
+136
View File
@@ -0,0 +1,136 @@
export type StrapiMediaObject = {
url: string,
name: string,
hash: string,
ext: string,
mime: string,
width: number,
height: number,
size: number,
}
export type StrapiMedia = StrapiMediaObject & {
id: number,
alternativeText: string | null,
caption: string | null,
formats: null | {
thumbnail: StrapiMediaObject,
large: StrapiMediaObject,
medium: StrapiMediaObject,
small: StrapiMediaObject,
},
}
export type StrapiComponentText = {
__component: "hudozka.text",
id: number,
text: string,
}
export type StrapiComponentImage = {
__component: "hudozka.image",
id: number,
wide: boolean,
caption: string,
media: StrapiMedia,
}
export type StrapiComponentDocument = {
__component: "hudozka.document",
id: number,
title: string,
media: StrapiMediaObject & { id: number },
}
export type StrapiComponentEmbed = {
__component: "hudozka.embed",
id: number,
src: string,
}
export type StrapiComponentCardGrid = {
__component: "hudozka.card-grid",
id: number,
items: StrapiPageCard[],
}
export type StrapiComponent =
| StrapiComponentText
| StrapiComponentImage
| StrapiComponentDocument
| StrapiComponentEmbed
| StrapiComponentCardGrid
export type StrapiTag = {
id: number,
slug: string,
name: string,
}
export type StrapiPage = {
id: number,
title: string,
excerpt: string,
slug: string,
date: string | null,
cover?: StrapiMedia,
published_at: string,
created_at: string,
updated_at: string,
content: StrapiComponent[],
tags: StrapiTag[],
}
export type StrapiPageCard = {
__component: "hudozka.page-card",
id: number,
page: StrapiPage,
layout: "small" | "medium" | "big",
}
export type StrapiHome = {
id: number,
title: string,
cards: StrapiPageCard[],
}
export type StrapiMenu = {
id: number,
homeLabel: string,
menu: StrapiComponentCardGrid,
}
async function get<T>(base: string, path: string): Promise<T> {
const res = await fetch(`${base}${path}`)
if (!res.ok) {
throw new Error(`GET ${path} -> ${res.status}`)
}
return await res.json() as T
}
export async function fetchAllPages(base: string): Promise<StrapiPage[]> {
const limit = 100
let start = 0
const all: StrapiPage[] = []
while (true) {
const batch = await get<StrapiPage[]>(base, `/pages?_limit=${limit}&_start=${start}`)
if (batch.length === 0) {
break
}
all.push(...batch)
start += limit
}
return all
}
export async function fetchTags(base: string): Promise<StrapiTag[]> {
return await get<StrapiTag[]>(base, "/tags")
}
export async function fetchHome(base: string): Promise<StrapiHome> {
return await get<StrapiHome>(base, "/home")
}
export async function fetchMenu(base: string): Promise<StrapiMenu> {
return await get<StrapiMenu>(base, "/menu")
}
+90
View File
@@ -0,0 +1,90 @@
import PocketBase from "pocketbase"
import { existsSync, readFileSync, writeFileSync } from "node:fs"
const STATE_FILE = new URL("../.migrate-state.json", import.meta.url).pathname
const POCKETBASE_URL = required("POCKETBASE_URL")
const POCKETBASE_EMAIL = required("POCKETBASE_EMAIL")
const POCKETBASE_PASSWORD = required("POCKETBASE_PASSWORD")
const KNOWN = ["tags", "images", "files", "pages", "kv"] as const
function required(name: string): string {
const v = process.env[name]
if (!v) {
throw new Error(`missing env ${name}`)
}
return v
}
async function wipe(pb: PocketBase, collection: string) {
console.log(`\n[${collection}] wiping...`)
let total = 0
while (true) {
const batch = await pb.collection(collection).getList(1, 200, { fields: "id" })
if (batch.items.length === 0) {
break
}
for (const rec of batch.items) {
await pb.collection(collection).delete(rec.id)
total++
if (total % 20 === 0) {
console.log(` [${collection}] deleted ${total}...`)
}
}
}
console.log(`[${collection}] done: ${total} deleted`)
}
async function main() {
const args = process.argv.slice(2)
const targets = args.length > 0 ? args : [...KNOWN]
const unknown = targets.filter(t => !KNOWN.includes(t as typeof KNOWN[number]))
if (unknown.length > 0) {
console.error(`unknown collections: ${unknown.join(", ")}`)
console.error(`known: ${KNOWN.join(", ")}`)
process.exit(1)
}
const pb = new PocketBase(POCKETBASE_URL)
await pb.collection("_superusers").authWithPassword(POCKETBASE_EMAIL, POCKETBASE_PASSWORD)
console.log("authed to pb")
console.log(`wiping: ${targets.join(", ")}`)
// Wipe pages first (references images/files/tags), then kv, then images/files/tags.
const order = ["pages", "kv", "images", "files", "tags"]
for (const c of order) {
if (targets.includes(c)) {
await wipe(pb, c)
}
}
// Sync state file: drop map for each wiped collection
if (existsSync(STATE_FILE)) {
const state = JSON.parse(readFileSync(STATE_FILE, "utf-8")) as Record<string, Record<string, string>>
const keyFor: Record<string, string> = {
tags: "tagMap",
images: "imageMap",
files: "fileMap",
pages: "pageMap",
}
for (const t of targets) {
const key = keyFor[t]
if (key) state[key] = {}
}
writeFileSync(STATE_FILE, JSON.stringify(state, null, 2))
console.log("\nstate file updated")
}
console.log("\ndone.")
}
main().catch(e => {
const err = e as { message?: string, url?: string, status?: number, response?: { data?: unknown } }
console.error("ERROR:", err.message)
if (err.url) console.error(" url:", err.url, "status:", err.status)
if (err.response?.data !== undefined) {
console.error(" response:", JSON.stringify(err.response.data, null, 2))
}
process.exit(1)
})