@jant/core 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/commands/db/execute-file.js +1 -1
- package/bin/commands/db/export.js +1 -1
- package/bin/commands/migrate.js +4 -4
- package/bin/commands/posts/rebuild-html.js +1 -1
- package/bin/commands/reset-password.js +1 -1
- package/bin/commands/search/reindex.js +1 -1
- package/bin/commands/setup.js +4 -2
- package/bin/commands/site/export.js +3 -0
- package/bin/commands/site/import.js +178 -91
- package/bin/commands/site/pull-media.js +3 -2
- package/bin/commands/site/snapshot/export.js +3 -1
- package/bin/commands/site/snapshot/import.js +3 -2
- package/bin/commands/start.js +44 -0
- package/bin/commands/telegram/register-webhooks.js +1 -1
- package/bin/commands/uploads/cleanup.js +48 -9
- package/bin/jant.js +39 -4
- package/bin/lib/import-sources.js +151 -0
- package/bin/lib/node-env.js +14 -9
- package/bin/lib/runtime-target.js +1 -1
- package/bin/lib/site-pull-media.js +56 -4
- package/bin/lib/site-snapshot.js +39 -2
- package/bin/lib/sql-export.js +66 -10
- package/dist/{app-DIVtyB4m.js → app-jQI4OPRe.js} +5055 -4448
- package/dist/client/.vite/manifest.json +38 -38
- package/dist/client/_assets/chunks/{create-editor-B-m7X7S5.js → create-editor-5Y49x7h5.js} +2 -2
- package/dist/client/_assets/chunks/{footnote-rail-CmeoVtnU.js → footnote-rail-BJwswtVQ.js} +1 -1
- package/dist/client/_assets/chunks/{settings-paths-C-ZZBTau.js → settings-paths-h6RjIe3C.js} +2 -2
- package/dist/client/_assets/chunks/{slug-format-BcIsNKz-.js → slug-format-Dsi0e9Xn.js} +1 -1
- package/dist/client/_assets/chunks/{slugify-373citbs.js → slugify-DlHLyUHS.js} +1 -1
- package/dist/client/_assets/chunks/sortable-list-DYMcJrlS.js +2 -0
- package/dist/client/_assets/chunks/unsafe-svg-DxrzM_Gb.js +2 -0
- package/dist/client/_assets/client-52vQhZAv.js +296 -0
- package/dist/client/_assets/client-BaqmpPQ-.css +2 -0
- package/dist/client/_assets/{client-auth-BpkkKTsV.js → client-auth-BDcCR6u1.js} +2 -2
- package/dist/client/_assets/client-author-CGVvrNZ8.css +2 -0
- package/dist/client/_assets/{client-compose-C-DXzcFR.js → client-compose-CzEwT5qX.js} +4 -4
- package/dist/client/_assets/{client-manage-BfT7ht4M.js → client-manage-CF7x21L4.js} +37 -37
- package/dist/client/_assets/{client-settings-CGR_nZ78.js → client-settings-DIM44Zqh.js} +2 -2
- package/dist/{url-CKlGzvdN.js → constants-DEgyqWDl.js} +340 -1
- package/dist/index.d.ts +44 -0
- package/dist/index.js +33 -1
- package/dist/node.js +57 -13
- package/package.json +13 -18
- package/src/__tests__/api-docs.test.ts +168 -1
- package/src/__tests__/bin/import-sources.test.ts +85 -0
- package/src/__tests__/bin/uploads-cleanup.test.ts +66 -26
- package/src/__tests__/cli-commands.test.ts +40 -0
- package/src/__tests__/config-docs.test.ts +119 -16
- package/src/__tests__/custom-url-redirects.test.ts +108 -0
- package/src/__tests__/export-collection-custom-urls.test.ts +69 -0
- package/src/__tests__/export-docs.test.ts +113 -41
- package/src/__tests__/export-feed-ids.test.ts +1 -0
- package/src/__tests__/export-format-version.test.ts +88 -0
- package/src/__tests__/export-hugo-build.test.ts +139 -4
- package/src/__tests__/export-import-roundtrip.test.ts +2 -1
- package/src/__tests__/export-service.test.ts +42 -13
- package/src/__tests__/export-smart-collection.test.ts +1 -1
- package/src/__tests__/feed-docs.test.ts +287 -21
- package/src/__tests__/feed-reply-addresses.test.ts +100 -0
- package/src/__tests__/feeds-disabled.test.ts +98 -0
- package/src/__tests__/fixtures/export-format/1.json +76 -0
- package/src/__tests__/fixtures/export-format/2.json +80 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/README.md +130 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/2thjq/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/2u5e5/_index.md +35 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/0x4nv/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/_index.md +44 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/faqyt/index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/41q27/the-potting-mix-guide-i-keep-rereading/index.md +20 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/5kayp/_index.md +23 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/5ynfs/_index.md +31 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/5ynfs/hu597/index.md +21 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/_index.md +5 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/a-night-heron-field-guide-for-my-walk-folder/_index.md +31 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/a-quiet-saturday-after-a-busy-week/_index.md +36 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/archive/_index.md +8 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/are-na-is-the-only-bookmark-pile-i-still-revisit/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/bought-too-many-lemons-again/_index.md +37 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/city-walks/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/cleanshot-for-screenshots-ocr-and-screen-recording-on-the-mac/_index.md +33 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/cleanshotmac-shang-de-jie-tu-ocr-lu-ping-gong-ju/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/co344/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/collections/_index.md +5 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/current-tea-rotation/_index.md +34 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/derek-sivers-still-writes-the-kind-of-internet-i-want-more-of/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/desk-but-better/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/e0kcg/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/egi3c/_index.md +24 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/evf9j/_index.md +152 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/featured/_index.md +8 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-basho/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-epictetus/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-marcus-aurelius/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-seneca/_index.md +26 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/from-thoreau/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/2cl6d/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/3zqv7/index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/5oxsv/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gkbvv/_index.md +39 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/gwob9/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/home-cooking/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/hz729/_index.md +24 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/inaturalist-ai-zi-ran-she-qu/_index.md +44 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/j4v0q/_index.md +35 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k278t/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k4eee/_index.md +22 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/a-reading-log-idea-i-might-steal/index.md +20 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/a83qu/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/k5vh8/from-seneca-5hibo/index.md +21 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/kan-qi-lai-bi-jiao-ku-de-gong-si-men/_index.md +41 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/l2m7y/_index.md +29 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/lan-ya-yao-kong-qi-chuang-shang-yue-du-de-fan-ye-shen-qi/_index.md +57 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/mynoise-for-rainy-afternoons/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/n09le/_index.md +23 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/ni-fu-jin-de-wei-ji-bai-ke-tiao-mu/_index.md +42 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/nts-archives-are-good-cleaning-music/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/c91j0/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/qyucy/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/qgfcu/wsgck/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/rain-makes-my-neighborhood-look-better/_index.md +46 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/reading-notes/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/s4r3e/_index.md +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/serious-eats-on-tomato-and-egg-soup/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/_index.md +44 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/cxiu6/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/t77ms/index.md +18 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/te812/the-soup-trick-i-always-forget/index.md +20 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/telk3/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/telk3/from-thoreau-pawt2/index.md +21 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/the-five-minute-reset-is-still-the-best-habit-i-have/_index.md +36 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/the-hallway-light-took-12-minutes-and-3-months/_index.md +32 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/the-recurse-center-manual-is-weirdly-calming/_index.md +30 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/tiny-projects/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/tong-wang-xing-fu-zhi-lu/_index.md +68 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/tou-ma-yan-jiang-ju-le-bu-chu-ti-yan/_index.md +62 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/useful-links/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/weekend-notes/_index.md +12 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/content/what-i-actually-use-my-notebook-for/_index.md +52 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/data/jant.toml +124 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/hugo.toml +45 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/_redirects +25 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/40bc6cd1f12e-med_01kn8jtq3penf98tfq4gzmh9g9.png +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jtx8qenf98tm9ahxr48sw.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jv0jdenf98tp6qr9zgjjc.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jv452enf98trbkwrvhvgd.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jvb16enf98txp7p0pf5ge.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jve5nenf98tzap11gpxzr.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jvq58enf98v538w5vsqp4.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jvsaeenf98v6ct4gjzppc.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01kn8jw26cenf98vc7k0ppz5k8.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q1hme4e8cmby77dn66yy.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q2w7e4e8cmc20036yh66.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q7d2e4e8cmdeqjmyafby.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m313q887e4e8cmdjssych7yh.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167jx2f6ct88pkz45j3ycp.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167mbdf6ct88pr4ga1b9kf.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167nsvf6ct88q1anhz4svb.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83-poster.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167qaxf6ct88qfndwzxx83.mp4 +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167sm0f6ct88qw5brtsgcw.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167tf8f6ct88r169s51j49.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167vaaf6ct88rbx5ztenwb.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167w51f6ct88rp19pybkw1.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167x0nf6ct88rzajb84tw3.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167xxbf6ct88s5t2300bjk.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167yq5f6ct88s9pjwt5fxg.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/static/media/med_01m3167zg4f6ct88sge8jp28ja.webp +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/themes/jant/static/apple-touch-icon.png +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/themes/jant/static/custom.css +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/themes/jant/static/favicon.ico +0 -0
- package/src/__tests__/fixtures/releases/0.10.0/site-export/wrangler.jsonc +24 -0
- package/src/__tests__/fixtures/releases/0.10.0/snapshot/db.sql +322 -0
- package/src/__tests__/fixtures/releases/0.10.0/snapshot/meta.json +11 -0
- package/src/__tests__/helpers/app.ts +6 -1
- package/src/__tests__/helpers/export-fixtures.ts +1 -0
- package/src/__tests__/import-refused-aliases.test.ts +98 -0
- package/src/__tests__/import-site-command.test.ts +73 -8
- package/src/__tests__/public-types.test.ts +64 -0
- package/src/__tests__/release-fixtures.test.ts +79 -24
- package/src/__tests__/release-version.test.ts +84 -0
- package/src/__tests__/site-pull-media.test.ts +48 -0
- package/src/__tests__/snapshot-tables.test.ts +37 -0
- package/src/__tests__/sql-export.test.ts +21 -1
- package/src/__tests__/stored-file-headers.test.ts +94 -0
- package/src/__tests__/template-deploy-workflow.test.ts +101 -0
- package/src/__tests__/theme-docs.test.ts +113 -24
- package/src/__tests__/toolchain-versions.test.ts +54 -0
- package/src/__tests__/trailing-slash-redirect.test.ts +61 -0
- package/src/__tests__/vite-config-graph.test.ts +98 -0
- package/src/app.tsx +89 -66
- package/src/client/__tests__/compose-bridge-image-upload.test.ts +1 -0
- package/src/client/__tests__/compose-bridge.test.ts +87 -0
- package/src/client/__tests__/compose-shortcuts.test.ts +4 -4
- package/src/client/__tests__/footnote-rail.test.ts +1 -1
- package/src/client/__tests__/lazy-entries.test.ts +1 -1
- package/src/client/__tests__/media-scroll-hint.test.ts +2 -2
- package/src/client/avatar-upload.ts +10 -10
- package/src/client/components/__tests__/jant-compose-dialog.test.ts +295 -4
- package/src/client/components/__tests__/jant-compose-editor.test.ts +34 -0
- package/src/client/components/__tests__/jant-settings-general.test.ts +0 -32
- package/src/client/components/compose-types.ts +14 -0
- package/src/client/components/jant-compose-dialog.ts +96 -41
- package/src/client/components/jant-compose-editor.ts +21 -4
- package/src/client/components/jant-config-editor.ts +4 -6
- package/src/client/components/jant-media-lightbox.ts +4 -4
- package/src/client/components/jant-settings-general.ts +0 -4
- package/src/client/components/nav-manager-types.ts +6 -5
- package/src/client/compose-bridge.ts +15 -4
- package/src/client/compose-launch.ts +4 -6
- package/src/client/compose-shortcuts.ts +1 -1
- package/src/client/footnote-rail.ts +1 -1
- package/src/client/lazy-entries.ts +1 -1
- package/src/client/media-scroll-hint.ts +2 -2
- package/src/client/tiptap/__tests__/markdown-clipboard.test.ts +55 -0
- package/src/client/tiptap/markdown-clipboard.ts +50 -2
- package/src/client/upload-session.ts +7 -6
- package/src/db/__tests__/backfill-external-redirects.test.ts +59 -0
- package/src/db/__tests__/backfill-featured-discover.test.ts +56 -0
- package/src/db/backfills/0007_restore_external_redirect_scheme.sql +20 -0
- package/src/db/backfills/0008_turn_off_featured_only_discover.sql +11 -0
- package/src/i18n/locales/public/en.po +46 -48
- package/src/i18n/locales/public/en.ts +1 -1
- package/src/i18n/locales/public/zh-Hans.po +45 -46
- package/src/i18n/locales/public/zh-Hans.ts +1 -1
- package/src/i18n/locales/public/zh-Hant.po +45 -46
- package/src/i18n/locales/public/zh-Hant.ts +1 -1
- package/src/i18n/locales/settings/en.po +15 -29
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +15 -29
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +15 -29
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/index.ts +43 -2
- package/src/lib/__tests__/api-settings.test.ts +3 -3
- package/src/lib/__tests__/constants.test.ts +10 -0
- package/src/lib/__tests__/discover.test.ts +8 -9
- package/src/lib/__tests__/env-values.test.ts +125 -0
- package/src/lib/__tests__/feed-path.test.ts +29 -0
- package/src/lib/__tests__/feed.test.ts +50 -22
- package/src/lib/__tests__/filter-dimensions.test.ts +22 -8
- package/src/lib/__tests__/post-list-cursor.test.ts +0 -10
- package/src/lib/__tests__/rate-limit.test.ts +22 -7
- package/src/lib/__tests__/resolve-config.test.ts +5 -3
- package/src/lib/__tests__/schemas.test.ts +72 -23
- package/src/lib/__tests__/slugify.test.ts +9 -0
- package/src/lib/__tests__/startup-config.test.ts +12 -0
- package/src/lib/__tests__/storage-s3.test.ts +214 -0
- package/src/lib/__tests__/theme.test.ts +20 -1
- package/src/lib/__tests__/time.test.ts +56 -0
- package/src/lib/__tests__/timeline.test.ts +46 -0
- package/src/lib/__tests__/url-fetch.test.ts +65 -1
- package/src/lib/__tests__/url.test.ts +60 -1
- package/src/lib/api-nav-items.ts +16 -20
- package/src/lib/api-post-input.ts +34 -1
- package/src/lib/api-posts.ts +125 -23
- package/src/lib/api-public-posts.ts +28 -37
- package/src/lib/api-search.ts +49 -2
- package/src/lib/api-settings.ts +159 -54
- package/src/lib/api-threads.ts +34 -11
- package/src/lib/constants.ts +6 -0
- package/src/lib/discover.ts +7 -23
- package/src/lib/env-values.ts +140 -0
- package/src/lib/env.ts +203 -12
- package/src/lib/feed-path.ts +8 -2
- package/src/lib/feed-policy.ts +110 -7
- package/src/lib/feed.ts +69 -25
- package/src/lib/filter-dimensions.ts +17 -10
- package/src/lib/github-sync-site-config.ts +1 -0
- package/src/lib/hugo-markdown.ts +5 -6
- package/src/lib/navigation.ts +4 -1
- package/src/lib/post-list-cursor.ts +33 -29
- package/src/lib/public-storage.ts +43 -0
- package/src/lib/rate-limit.ts +31 -16
- package/src/lib/render.tsx +5 -0
- package/src/lib/resolve-config.ts +16 -19
- package/src/lib/schemas.ts +248 -180
- package/src/lib/slugify.ts +6 -1
- package/src/lib/sse.ts +1 -1
- package/src/lib/startup-config.ts +20 -1
- package/src/lib/theme.ts +8 -5
- package/src/lib/thread-fold.ts +6 -0
- package/src/lib/thread-query.ts +19 -24
- package/src/lib/time.ts +137 -17
- package/src/lib/timeline.ts +56 -13
- package/src/lib/url-fetch.ts +141 -40
- package/src/lib/url.ts +86 -1
- package/src/middleware/__tests__/auth.test.ts +27 -0
- package/src/middleware/__tests__/cors.test.ts +54 -0
- package/src/middleware/__tests__/cross-origin.test.ts +149 -0
- package/src/middleware/__tests__/public-content-access.test.ts +2 -42
- package/src/middleware/auth.ts +34 -3
- package/src/middleware/cors.ts +4 -4
- package/src/middleware/cross-origin.ts +124 -0
- package/src/middleware/error-handler.ts +7 -0
- package/src/middleware/public-content-access.ts +3 -26
- package/src/middleware/secure-headers.ts +8 -2
- package/src/node/__tests__/cli-migrate.test.ts +2 -2
- package/src/node/__tests__/cli-runtime-target.test.ts +13 -2
- package/src/node/__tests__/cli-site-snapshot.test.ts +57 -0
- package/src/node/__tests__/cli-snapshot-meta.test.ts +11 -1
- package/src/node/__tests__/cli-sql-export.test.ts +25 -1
- package/src/node/__tests__/cli-start.test.ts +66 -0
- package/src/node/__tests__/request-handler.test.ts +37 -0
- package/src/node/__tests__/runtime.test.ts +56 -1
- package/src/node/request-handler.ts +58 -5
- package/src/node/runtime.ts +37 -11
- package/src/preset.css +3 -3
- package/src/routes/__tests__/compose.test.ts +84 -0
- package/src/routes/api/__tests__/collections.test.ts +68 -0
- package/src/routes/api/__tests__/mcp.test.ts +164 -9
- package/src/routes/api/__tests__/media.test.ts +9 -1
- package/src/routes/api/__tests__/nav-items.test.ts +27 -1
- package/src/routes/api/__tests__/posts.test.ts +269 -78
- package/src/routes/api/__tests__/search.test.ts +17 -4
- package/src/routes/api/__tests__/settings.test.ts +119 -85
- package/src/routes/api/__tests__/telegram.test.ts +11 -6
- package/src/routes/api/__tests__/threads.test.ts +11 -0
- package/src/routes/api/__tests__/upload-response.test.ts +48 -0
- package/src/routes/api/__tests__/uploads.test.ts +35 -2
- package/src/routes/api/collections.ts +3 -3
- package/src/routes/api/custom-urls.ts +2 -1
- package/src/routes/api/export.ts +1 -0
- package/src/routes/api/internal/__tests__/post-body-html.test.ts +19 -0
- package/src/routes/api/internal/__tests__/uploads.test.ts +2 -0
- package/src/routes/api/internal/sites.ts +16 -4
- package/src/routes/api/mcp.ts +1 -0
- package/src/routes/api/media.ts +7 -8
- package/src/routes/api/nav-items.ts +2 -1
- package/src/routes/api/posts.ts +18 -24
- package/src/routes/api/public/__tests__/posts.test.ts +15 -0
- package/src/routes/api/public/__tests__/threads-collections.test.ts +12 -45
- package/src/routes/api/public/__tests__/threads.test.ts +41 -9
- package/src/routes/api/public/posts.ts +2 -2
- package/src/routes/api/public/threads.ts +16 -26
- package/src/routes/api/search.ts +7 -41
- package/src/routes/api/settings.ts +32 -28
- package/src/routes/api/smart-collections.ts +6 -1
- package/src/routes/api/threads.ts +25 -26
- package/src/routes/api/upload.ts +6 -21
- package/src/routes/api/uploads.ts +14 -20
- package/src/routes/auth/__tests__/dev.test.ts +16 -13
- package/src/routes/auth/__tests__/hosted-sso.test.ts +51 -0
- package/src/routes/auth/__tests__/setup-auth.test.ts +2 -0
- package/src/routes/auth/__tests__/setup-discover.test.ts +2 -0
- package/src/routes/auth/__tests__/setup-flow.test.ts +32 -0
- package/src/routes/auth/__tests__/setup-rate-limit.test.ts +72 -0
- package/src/routes/auth/__tests__/setup-steps.test.ts +2 -0
- package/src/routes/auth/__tests__/signin.test.ts +167 -2
- package/src/routes/auth/dev.ts +4 -6
- package/src/routes/auth/hosted-sso.ts +9 -6
- package/src/routes/auth/setup.tsx +35 -5
- package/src/routes/auth/signin.tsx +96 -1
- package/src/routes/compose.tsx +47 -47
- package/src/routes/dash/__tests__/settings-avatar.test.ts +59 -4
- package/src/routes/dash/__tests__/settings-demo-locks.test.ts +147 -0
- package/src/routes/dash/custom-urls.tsx +2 -0
- package/src/routes/dash/settings.tsx +79 -32
- package/src/routes/feed/__tests__/feed.test.ts +93 -3
- package/src/routes/feed/__tests__/sitemap.test.ts +42 -0
- package/src/routes/feed/feed.ts +128 -175
- package/src/routes/feed/sitemap.ts +9 -7
- package/src/routes/pages/__tests__/archive-years.test.ts +45 -0
- package/src/routes/pages/__tests__/collection-routing.test.ts +40 -0
- package/src/routes/pages/__tests__/collections.test.ts +3 -0
- package/src/routes/pages/__tests__/language-routing.test.ts +31 -0
- package/src/routes/pages/__tests__/post-page-round-trips.test.ts +34 -2
- package/src/routes/pages/__tests__/search.test.ts +5 -2
- package/src/routes/pages/__tests__/thread-gap.test.ts +207 -0
- package/src/routes/pages/archive.tsx +33 -94
- package/src/routes/pages/brand.tsx +1 -0
- package/src/routes/pages/collection.tsx +13 -84
- package/src/routes/pages/collections.tsx +2 -0
- package/src/routes/pages/featured.tsx +7 -2
- package/src/routes/pages/home.tsx +1 -0
- package/src/routes/pages/latest.tsx +6 -2
- package/src/routes/pages/new.tsx +1 -0
- package/src/routes/pages/page.tsx +73 -47
- package/src/routes/pages/search.tsx +5 -3
- package/src/routes/pages/smart-collection.tsx +11 -70
- package/src/routes/pages/subscribe.tsx +1 -0
- package/src/routes/pages/theme-sample.tsx +1 -0
- package/src/runtime/__tests__/readiness.test.ts +16 -0
- package/src/runtime/cloudflare.ts +2 -3
- package/src/runtime/index.ts +3 -1
- package/src/runtime/node.ts +3 -5
- package/src/runtime/readiness.ts +5 -0
- package/src/services/__tests__/auth.test.ts +115 -0
- package/src/services/__tests__/collection.test.ts +9 -0
- package/src/services/__tests__/github-sync-webhook.test.ts +78 -0
- package/src/services/__tests__/hosted-handoff.test.ts +208 -1
- package/src/services/__tests__/media.test.ts +47 -27
- package/src/services/__tests__/navigation.test.ts +67 -15
- package/src/services/__tests__/post.test.ts +103 -56
- package/src/services/__tests__/search.test.ts +38 -0
- package/src/services/__tests__/settings.test.ts +2 -14
- package/src/services/__tests__/smart-collection.test.ts +2 -2
- package/src/services/__tests__/telegram-ingest.test.ts +113 -0
- package/src/services/__tests__/thread.test.ts +26 -11
- package/src/services/auth.ts +36 -4
- package/src/services/collection.ts +46 -5
- package/src/services/custom-url.ts +11 -4
- package/src/services/export-theme/assets/client-site.css +1 -1
- package/src/services/export-theme/assets/client-site.js +2 -2
- package/src/services/export-theme/layouts/_default/baseof.html +1 -1
- package/src/services/export-theme/layouts/collection/single.html +1 -1
- package/src/services/export-theme/layouts/partials/featured-thread.html +8 -1
- package/src/services/export-theme/layouts/partials/head.html +1 -1
- package/src/services/export-theme/layouts/partials/media-gallery.html +6 -3
- package/src/services/export-theme/layouts/smart_collection/list.html +1 -1
- package/src/services/export-theme/styles/main.css +3 -3
- package/src/services/export.ts +68 -19
- package/src/services/github-sync.ts +10 -10
- package/src/services/hosted-handoff.ts +106 -6
- package/src/services/index.ts +3 -1
- package/src/services/language.ts +33 -0
- package/src/services/mcp.ts +176 -438
- package/src/services/media.ts +69 -21
- package/src/services/navigation.ts +19 -4
- package/src/services/path.ts +45 -3
- package/src/services/post.ts +329 -214
- package/src/services/search.ts +22 -3
- package/src/services/settings.ts +36 -3
- package/src/services/site-admin.ts +1 -0
- package/src/services/smart-collection.ts +10 -3
- package/src/services/telegram.ts +23 -6
- package/src/services/thread.ts +11 -3
- package/src/services/upload-session.ts +14 -15
- package/src/styles/components.css +2 -2
- package/src/styles/site-media.css +2 -2
- package/src/styles/tokens.css +19 -22
- package/src/styles/ui-author.css +73 -94
- package/src/styles/ui.css +62 -62
- package/src/types/app-context.ts +5 -1
- package/src/types/bindings.ts +11 -0
- package/src/types/config.ts +4 -4
- package/src/types/constants.ts +20 -0
- package/src/types/props.ts +34 -8
- package/src/types/views.ts +28 -13
- package/src/ui/color-themes.ts +6 -5
- package/src/ui/dash/settings/GeneralContent.tsx +0 -22
- package/src/ui/dash/settings/__tests__/GeneralContent.test.tsx +0 -21
- package/src/ui/feed/CuratedThreadPreview.tsx +7 -2
- package/src/ui/feed/LinkCard.tsx +1 -2
- package/src/ui/feed/NoteCard.tsx +1 -2
- package/src/ui/feed/QuoteCard.tsx +2 -2
- package/src/ui/feed/ThreadPreview.tsx +6 -6
- package/src/ui/feed/TimelineFeed.tsx +1 -7
- package/src/ui/feed/__tests__/thread-preview.test.ts +123 -10
- package/src/ui/feed/__tests__/timeline-cards.test.ts +18 -1
- package/src/ui/layouts/BaseLayout.tsx +5 -0
- package/src/ui/pages/ArchivePage.tsx +1 -1
- package/src/ui/pages/BrandPage.tsx +1 -1
- package/src/ui/pages/CollectionPage.tsx +0 -1
- package/src/ui/pages/CollectionsPage.tsx +2 -2
- package/src/ui/pages/ComposePage.tsx +1 -1
- package/src/ui/pages/FeaturedPage.tsx +1 -1
- package/src/ui/pages/HomePage.tsx +1 -1
- package/src/ui/pages/PostPage.tsx +1 -1
- package/src/ui/pages/SearchPage.tsx +1 -1
- package/src/ui/pages/SmartCollectionPage.tsx +2 -3
- package/src/ui/pages/SubscribePage.tsx +1 -1
- package/src/ui/pages/ThemeSamplePage.tsx +1 -1
- package/src/ui/shared/MediaGallery.tsx +1 -1
- package/src/vendor/datastar.js +9 -1956
- package/src/vendor/datastar.js.map +4 -4
- package/dist/client/_assets/chunks/sortable-list-BJyd-LXE.js +0 -2
- package/dist/client/_assets/chunks/unsafe-svg-DU_DNMy5.js +0 -2
- package/dist/client/_assets/client-D4AT9Iqr.js +0 -295
- package/dist/client/_assets/client-DRuw7XCt.css +0 -2
- package/dist/client/_assets/client-author-DQ8R-8KR.css +0 -2
|
@@ -453,6 +453,17 @@ describe("PostService", () => {
|
|
|
453
453
|
).rejects.toThrow('Path "skill.md" is reserved and cannot be used');
|
|
454
454
|
});
|
|
455
455
|
|
|
456
|
+
// A custom URL could never start with `_` or `.`, but a post's own `path`
|
|
457
|
+
// could, and took an address in Jant's namespace.
|
|
458
|
+
it.each(["_x", ".well-known/x"])(
|
|
459
|
+
"rejects a path in Jant's namespace (%s)",
|
|
460
|
+
async (path) => {
|
|
461
|
+
await expect(
|
|
462
|
+
postService.create({ format: "note", bodyMarkdown: "x", path }),
|
|
463
|
+
).rejects.toThrow(`Path "${path}" is reserved and cannot be used`);
|
|
464
|
+
},
|
|
465
|
+
);
|
|
466
|
+
|
|
456
467
|
it("rolls back the post insert when slug persistence fails inside the batch", async () => {
|
|
457
468
|
await postService.create({
|
|
458
469
|
format: "note",
|
|
@@ -1357,57 +1368,12 @@ describe("PostService", () => {
|
|
|
1357
1368
|
expect(page.posts).toHaveLength(2);
|
|
1358
1369
|
});
|
|
1359
1370
|
|
|
1360
|
-
it("
|
|
1361
|
-
const created = await publishSeries(
|
|
1362
|
-
const third = created[2];
|
|
1363
|
-
|
|
1364
|
-
const page = await postService.listPage(
|
|
1365
|
-
{},
|
|
1366
|
-
{ cursor: third?.id, limit: 10 },
|
|
1367
|
-
);
|
|
1368
|
-
expect(page.posts.map((post) => post.id)).toEqual([
|
|
1369
|
-
created[1]?.id,
|
|
1370
|
-
created[0]?.id,
|
|
1371
|
-
]);
|
|
1372
|
-
});
|
|
1373
|
-
|
|
1374
|
-
it("rejects a bare post ID the caller can't see, whatever the reason", async () => {
|
|
1375
|
-
const [visible] = await publishSeries(1);
|
|
1376
|
-
const draft = await postService.create({
|
|
1377
|
-
format: "note",
|
|
1378
|
-
bodyMarkdown: "draft",
|
|
1379
|
-
status: "draft",
|
|
1380
|
-
});
|
|
1381
|
-
const hidden = await postService.create({
|
|
1382
|
-
format: "note",
|
|
1383
|
-
bodyMarkdown: "private",
|
|
1384
|
-
visibility: "private",
|
|
1385
|
-
});
|
|
1386
|
-
const deleted = await postService.create({
|
|
1387
|
-
format: "note",
|
|
1388
|
-
bodyMarkdown: "deleted",
|
|
1389
|
-
});
|
|
1390
|
-
await postService.delete(deleted.id);
|
|
1391
|
-
const publicFilters = {
|
|
1392
|
-
status: "published" as const,
|
|
1393
|
-
excludePrivate: true,
|
|
1394
|
-
};
|
|
1395
|
-
|
|
1396
|
-
const errors = [];
|
|
1397
|
-
for (const cursor of [draft.id, hidden.id, deleted.id]) {
|
|
1398
|
-
const error = await postService
|
|
1399
|
-
.listPage(publicFilters, { cursor, limit: 5 })
|
|
1400
|
-
.catch((caught: unknown) => caught);
|
|
1401
|
-
expect(error).toBeInstanceOf(ValidationError);
|
|
1402
|
-
errors.push((error as ValidationError).message);
|
|
1403
|
-
}
|
|
1404
|
-
// One message for all three, so the answer says nothing about the post.
|
|
1405
|
-
expect(new Set(errors).size).toBe(1);
|
|
1371
|
+
it("rejects a post ID as a cursor", async () => {
|
|
1372
|
+
const created = await publishSeries(3);
|
|
1406
1373
|
|
|
1407
|
-
// A post the caller can see still resumes.
|
|
1408
1374
|
await expect(
|
|
1409
|
-
postService.listPage(
|
|
1410
|
-
).
|
|
1375
|
+
postService.listPage({}, { cursor: created[1]?.id, limit: 5 }),
|
|
1376
|
+
).rejects.toBeInstanceOf(ValidationError);
|
|
1411
1377
|
});
|
|
1412
1378
|
|
|
1413
1379
|
it("rejects a cursor taken in another sort mode", async () => {
|
|
@@ -1608,10 +1574,13 @@ describe("PostService", () => {
|
|
|
1608
1574
|
publishedAt: 1706745600, // Feb 1, 2024
|
|
1609
1575
|
});
|
|
1610
1576
|
|
|
1611
|
-
const counts = await postService.countByYearMonth(
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1577
|
+
const counts = await postService.countByYearMonth(
|
|
1578
|
+
{
|
|
1579
|
+
status: "published",
|
|
1580
|
+
excludeReplies: true,
|
|
1581
|
+
},
|
|
1582
|
+
"UTC",
|
|
1583
|
+
);
|
|
1615
1584
|
|
|
1616
1585
|
expect(counts).toEqual([
|
|
1617
1586
|
{ yearMonth: "2024-02", count: 1 },
|
|
@@ -1638,12 +1607,54 @@ describe("PostService", () => {
|
|
|
1638
1607
|
publishedAt: 1706745600,
|
|
1639
1608
|
});
|
|
1640
1609
|
|
|
1641
|
-
const counts = await postService.countByYearMonth(
|
|
1610
|
+
const counts = await postService.countByYearMonth(
|
|
1611
|
+
{
|
|
1612
|
+
format: "note",
|
|
1613
|
+
visibility: "private",
|
|
1614
|
+
},
|
|
1615
|
+
"UTC",
|
|
1616
|
+
);
|
|
1617
|
+
|
|
1618
|
+
expect(counts).toEqual([{ yearMonth: "2024-01", count: 1 }]);
|
|
1619
|
+
});
|
|
1620
|
+
|
|
1621
|
+
// 2024-12-31T17:00:00Z is 01:00 on New Year's Day in Shanghai.
|
|
1622
|
+
it("buckets months and years on the site's calendar", async () => {
|
|
1623
|
+
await postService.create({
|
|
1642
1624
|
format: "note",
|
|
1643
|
-
|
|
1625
|
+
bodyMarkdown: "new year",
|
|
1626
|
+
publishedAt: 1735664400,
|
|
1627
|
+
});
|
|
1628
|
+
await postService.create({
|
|
1629
|
+
format: "note",
|
|
1630
|
+
bodyMarkdown: "december",
|
|
1631
|
+
publishedAt: 1733011200, // 2024-12-01T00:00:00Z
|
|
1644
1632
|
});
|
|
1633
|
+
const filters = {
|
|
1634
|
+
status: "published" as const,
|
|
1635
|
+
sortBy: "published" as const,
|
|
1636
|
+
};
|
|
1645
1637
|
|
|
1646
|
-
expect(
|
|
1638
|
+
expect(
|
|
1639
|
+
await postService.countByYearMonth(filters, "Asia/Shanghai"),
|
|
1640
|
+
).toEqual([
|
|
1641
|
+
{ yearMonth: "2025-01", count: 1 },
|
|
1642
|
+
{ yearMonth: "2024-12", count: 1 },
|
|
1643
|
+
]);
|
|
1644
|
+
expect(await postService.countByYearMonth(filters, "UTC")).toEqual([
|
|
1645
|
+
{ yearMonth: "2024-12", count: 2 },
|
|
1646
|
+
]);
|
|
1647
|
+
expect(
|
|
1648
|
+
await postService.getDistinctYears(filters, "Asia/Shanghai"),
|
|
1649
|
+
).toEqual([2025, 2024]);
|
|
1650
|
+
expect(await postService.getDistinctYears(filters, "UTC")).toEqual([
|
|
1651
|
+
2024,
|
|
1652
|
+
]);
|
|
1653
|
+
});
|
|
1654
|
+
|
|
1655
|
+
it("finds no periods when nothing matches", async () => {
|
|
1656
|
+
expect(await postService.countByYearMonth({}, "UTC")).toEqual([]);
|
|
1657
|
+
expect(await postService.getDistinctYears({}, "UTC")).toEqual([]);
|
|
1647
1658
|
});
|
|
1648
1659
|
});
|
|
1649
1660
|
|
|
@@ -2284,6 +2295,42 @@ describe("PostService", () => {
|
|
|
2284
2295
|
typeof postService.createThreadWithAttachments
|
|
2285
2296
|
>[1];
|
|
2286
2297
|
|
|
2298
|
+
// The composer keeps its uploads in a local draft when a save fails, and
|
|
2299
|
+
// a retry sends them again by ID.
|
|
2300
|
+
it("keeps the uploads when a later post fails and the thread rolls back", async () => {
|
|
2301
|
+
const mediaService = createMediaService(db, DEFAULT_TEST_SITE_ID);
|
|
2302
|
+
const storage = createMockStorage();
|
|
2303
|
+
await storage.put("media/first.jpg", new Uint8Array([1]));
|
|
2304
|
+
const upload = await mediaService.create({
|
|
2305
|
+
filename: "first.jpg",
|
|
2306
|
+
originalName: "first.jpg",
|
|
2307
|
+
mimeType: "image/jpeg",
|
|
2308
|
+
size: 1,
|
|
2309
|
+
storageKey: "media/first.jpg",
|
|
2310
|
+
});
|
|
2311
|
+
|
|
2312
|
+
await expect(
|
|
2313
|
+
postService.createThreadWithAttachments(
|
|
2314
|
+
[
|
|
2315
|
+
{
|
|
2316
|
+
data: { format: "note", bodyMarkdown: "Root" },
|
|
2317
|
+
attachments: [{ type: "media", mediaId: upload.id }],
|
|
2318
|
+
},
|
|
2319
|
+
{
|
|
2320
|
+
data: { format: "link", bodyMarkdown: "No URL" },
|
|
2321
|
+
attachments: [],
|
|
2322
|
+
},
|
|
2323
|
+
],
|
|
2324
|
+
{ media: mediaService, storage, storageDriver: "r2" },
|
|
2325
|
+
),
|
|
2326
|
+
).rejects.toThrow();
|
|
2327
|
+
|
|
2328
|
+
expect(await postService.list()).toHaveLength(0);
|
|
2329
|
+
const kept = await mediaService.getById(upload.id);
|
|
2330
|
+
expect(kept?.postId).toBeNull();
|
|
2331
|
+
expect(storage.files.has("media/first.jpg")).toBe(true);
|
|
2332
|
+
});
|
|
2333
|
+
|
|
2287
2334
|
it("dates every reply from the root when the root is backdated", async () => {
|
|
2288
2335
|
const backdated = 1710000000; // 2024-03-09
|
|
2289
2336
|
|
|
@@ -567,6 +567,44 @@ describe("SearchService", () => {
|
|
|
567
567
|
expect(calls[0]?.params[0]).toBe("jant:*");
|
|
568
568
|
});
|
|
569
569
|
|
|
570
|
+
// tsquery syntax treats `'`, `&`, `|`, `!`, `(` and `:` as operators, so a
|
|
571
|
+
// query with no word in it failed to parse and the search answered 500.
|
|
572
|
+
it("sends a Postgres query with no letter or digit to the LIKE search", async () => {
|
|
573
|
+
const calls: { params: unknown[]; query: string }[] = [];
|
|
574
|
+
const rawQuery: RawQueryClient = {
|
|
575
|
+
prepare(query) {
|
|
576
|
+
const call = { params: [], query };
|
|
577
|
+
calls.push(call);
|
|
578
|
+
return {
|
|
579
|
+
bind(...params: unknown[]) {
|
|
580
|
+
call.params = params;
|
|
581
|
+
return this;
|
|
582
|
+
},
|
|
583
|
+
async all() {
|
|
584
|
+
return { results: [] };
|
|
585
|
+
},
|
|
586
|
+
};
|
|
587
|
+
},
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
const searchService = createSearchService(
|
|
591
|
+
rawQuery,
|
|
592
|
+
DEFAULT_TEST_SITE_ID,
|
|
593
|
+
"pg",
|
|
594
|
+
);
|
|
595
|
+
for (const query of ["'''", "&|!():"]) {
|
|
596
|
+
calls.length = 0;
|
|
597
|
+
await searchService.search(query);
|
|
598
|
+
expect(calls, query).toHaveLength(1);
|
|
599
|
+
expect(calls[0]?.query, query).toContain("search_text ILIKE");
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
calls.length = 0;
|
|
603
|
+
await searchService.search("it's (fine)");
|
|
604
|
+
expect(calls[0]?.query).toContain("to_tsquery");
|
|
605
|
+
expect(calls[0]?.params[0]).toBe("it:* & s:* & fine:*");
|
|
606
|
+
});
|
|
607
|
+
|
|
570
608
|
it("keeps Postgres searches on the LIKE path for short queries", async () => {
|
|
571
609
|
const calls: string[] = [];
|
|
572
610
|
const rawQuery: RawQueryClient = {
|
|
@@ -570,10 +570,10 @@ describe("SettingsService", () => {
|
|
|
570
570
|
await settingsService.updateDiscoverSetting("off", { demoMode: false });
|
|
571
571
|
expect(await settingsService.get("DISCOVER")).toBe("off");
|
|
572
572
|
|
|
573
|
-
await settingsService.updateDiscoverSetting("
|
|
573
|
+
await settingsService.updateDiscoverSetting("latest", {
|
|
574
574
|
demoMode: false,
|
|
575
575
|
});
|
|
576
|
-
expect(await settingsService.get("DISCOVER")).toBe("
|
|
576
|
+
expect(await settingsService.get("DISCOVER")).toBe("latest");
|
|
577
577
|
});
|
|
578
578
|
|
|
579
579
|
// A site that has never used the control has never told anyone it exists,
|
|
@@ -594,18 +594,6 @@ describe("SettingsService", () => {
|
|
|
594
594
|
expect(result.shouldAnnounce).toBe(true);
|
|
595
595
|
});
|
|
596
596
|
|
|
597
|
-
// The directory already knows about a listed site; which of its posts it
|
|
598
|
-
// draws from is not news.
|
|
599
|
-
it("says nothing when an enrolled site changes which posts it offers", async () => {
|
|
600
|
-
await settingsService.updateDiscoverSetting("latest", {
|
|
601
|
-
demoMode: false,
|
|
602
|
-
});
|
|
603
|
-
const result = await settingsService.updateDiscoverSetting("featured", {
|
|
604
|
-
demoMode: false,
|
|
605
|
-
});
|
|
606
|
-
expect(result.shouldAnnounce).toBe(false);
|
|
607
|
-
});
|
|
608
|
-
|
|
609
597
|
// The half that used to be missing. A directory that is not told keeps the
|
|
610
598
|
// blog until its next scheduled read of the feed, and the owner watches
|
|
611
599
|
// something they just removed sit there for another hour.
|
|
@@ -67,8 +67,8 @@ describe("SmartCollectionService", () => {
|
|
|
67
67
|
);
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
const anonymous = { isAuthenticated: false };
|
|
71
|
-
const author = { isAuthenticated: true };
|
|
70
|
+
const anonymous = { isAuthenticated: false, timeZone: "UTC" };
|
|
71
|
+
const author = { isAuthenticated: true, timeZone: "UTC" };
|
|
72
72
|
|
|
73
73
|
describe("create", () => {
|
|
74
74
|
it("stores conditions and reads them back in the shared vocabulary", async () => {
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A file sent to the Telegram bot arrives with whatever MIME type the sender's
|
|
3
|
+
* client claimed. Ingesting it must follow the browser upload rules, or an
|
|
4
|
+
* `.html` or `.svg` file forwarded to the bot ends up served inline on the
|
|
5
|
+
* site's own origin.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
9
|
+
import {
|
|
10
|
+
createTestDatabase,
|
|
11
|
+
DEFAULT_TEST_SITE_ID,
|
|
12
|
+
} from "../../__tests__/helpers/db.js";
|
|
13
|
+
import type { Database } from "../../db/index.js";
|
|
14
|
+
import type { StorageDriver } from "../../lib/storage.js";
|
|
15
|
+
import type { MediaService } from "../media.js";
|
|
16
|
+
import { createTelegramService } from "../telegram.js";
|
|
17
|
+
|
|
18
|
+
const PNG_BYTES = new Uint8Array([
|
|
19
|
+
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0, 0, 0, 0,
|
|
20
|
+
]);
|
|
21
|
+
const HTML_BYTES = new TextEncoder().encode("<script>alert(1)</script>");
|
|
22
|
+
|
|
23
|
+
function stubTelegram(bytes: Uint8Array) {
|
|
24
|
+
vi.stubGlobal(
|
|
25
|
+
"fetch",
|
|
26
|
+
vi.fn(async (url: string) => {
|
|
27
|
+
if (url.endsWith("/getFile")) {
|
|
28
|
+
return Response.json({
|
|
29
|
+
ok: true,
|
|
30
|
+
result: { file_id: "f", file_path: "documents/file" },
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return new Response(bytes);
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function ingest(mimeType: string, bytes: Uint8Array) {
|
|
39
|
+
stubTelegram(bytes);
|
|
40
|
+
const { db } = createTestDatabase();
|
|
41
|
+
const service = createTelegramService(
|
|
42
|
+
db as unknown as Database,
|
|
43
|
+
DEFAULT_TEST_SITE_ID,
|
|
44
|
+
);
|
|
45
|
+
const put = vi.fn(async () => {});
|
|
46
|
+
const media = {
|
|
47
|
+
assertCanWriteBytes: vi.fn(async () => {}),
|
|
48
|
+
create: vi.fn(async (input: Record<string, unknown>) => input),
|
|
49
|
+
} as unknown as MediaService;
|
|
50
|
+
|
|
51
|
+
const result = service.ingestMediaFile(
|
|
52
|
+
{
|
|
53
|
+
botToken: "1:secret",
|
|
54
|
+
fileId: "f",
|
|
55
|
+
originalName: "file",
|
|
56
|
+
mimeType,
|
|
57
|
+
mediaKind: mimeType.startsWith("image/") ? "image" : "text",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
storage: { put } as unknown as StorageDriver,
|
|
61
|
+
storageDriver: "local",
|
|
62
|
+
maxFileSizeMB: 10,
|
|
63
|
+
media,
|
|
64
|
+
},
|
|
65
|
+
);
|
|
66
|
+
return { result, put };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
afterEach(() => {
|
|
70
|
+
vi.unstubAllGlobals();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("ingesting a file sent to the Telegram bot", () => {
|
|
74
|
+
it("stores an HTML file as a download", async () => {
|
|
75
|
+
const { result, put } = ingest("text/html", HTML_BYTES);
|
|
76
|
+
await result;
|
|
77
|
+
|
|
78
|
+
expect(put).toHaveBeenCalledWith(
|
|
79
|
+
expect.any(String),
|
|
80
|
+
HTML_BYTES,
|
|
81
|
+
expect.objectContaining({ contentDisposition: "attachment" }),
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("stores an SVG as a download", async () => {
|
|
86
|
+
const { result, put } = ingest("image/svg+xml", HTML_BYTES);
|
|
87
|
+
await result;
|
|
88
|
+
|
|
89
|
+
expect(put).toHaveBeenCalledWith(
|
|
90
|
+
expect.any(String),
|
|
91
|
+
HTML_BYTES,
|
|
92
|
+
expect.objectContaining({ contentDisposition: "attachment" }),
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("shows a real PNG inline", async () => {
|
|
97
|
+
const { result, put } = ingest("image/png", PNG_BYTES);
|
|
98
|
+
await result;
|
|
99
|
+
|
|
100
|
+
expect(put).toHaveBeenCalledWith(
|
|
101
|
+
expect.any(String),
|
|
102
|
+
PNG_BYTES,
|
|
103
|
+
expect.objectContaining({ contentDisposition: "inline" }),
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("refuses a file that claims to be a PNG but isn't", async () => {
|
|
108
|
+
const { result, put } = ingest("image/png", HTML_BYTES);
|
|
109
|
+
|
|
110
|
+
await expect(result).rejects.toThrow("PNG");
|
|
111
|
+
expect(put).not.toHaveBeenCalled();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { createTestApp } from "../../__tests__/helpers/app.js";
|
|
3
3
|
import { ValidationError } from "../../lib/errors.js";
|
|
4
|
+
import { encodeThreadPostsCursorAfter } from "../../lib/post-list-cursor.js";
|
|
4
5
|
import type { CreatePost, Post } from "../../types.js";
|
|
5
6
|
import type { ThreadListQuery } from "../thread.js";
|
|
6
7
|
|
|
@@ -19,7 +20,7 @@ function setup() {
|
|
|
19
20
|
limit = 50,
|
|
20
21
|
): Promise<string[]> => {
|
|
21
22
|
const page = await services.threads.listThreads(
|
|
22
|
-
{ audience: "reader", selection: {}, ...query },
|
|
23
|
+
{ audience: "reader", selection: {}, timeZone: "UTC", ...query },
|
|
23
24
|
{ limit },
|
|
24
25
|
);
|
|
25
26
|
return page.threads.map((thread) => thread.root.id);
|
|
@@ -109,6 +110,7 @@ describe("ThreadService.listThreads", () => {
|
|
|
109
110
|
await expect(
|
|
110
111
|
services.threads.listThreads(
|
|
111
112
|
{
|
|
113
|
+
timeZone: "UTC",
|
|
112
114
|
audience: "reader",
|
|
113
115
|
selection: { visibility: "featured" },
|
|
114
116
|
sort: "activity",
|
|
@@ -219,14 +221,14 @@ describe("ThreadService.listThreads", () => {
|
|
|
219
221
|
];
|
|
220
222
|
for (const query of cases) {
|
|
221
223
|
const full = await services.threads.listThreads(
|
|
222
|
-
{ audience: "reader", selection: {}, ...query },
|
|
224
|
+
{ audience: "reader", selection: {}, timeZone: "UTC", ...query },
|
|
223
225
|
{ limit: 50 },
|
|
224
226
|
);
|
|
225
227
|
const walked: string[] = [];
|
|
226
228
|
let cursor: string | undefined;
|
|
227
229
|
for (let page = 0; page < 10; page++) {
|
|
228
230
|
const result = await services.threads.listThreads(
|
|
229
|
-
{ audience: "reader", selection: {}, ...query },
|
|
231
|
+
{ audience: "reader", selection: {}, timeZone: "UTC", ...query },
|
|
230
232
|
{ limit: 1, cursor },
|
|
231
233
|
);
|
|
232
234
|
walked.push(...result.threads.map((thread) => thread.root.id));
|
|
@@ -247,7 +249,7 @@ describe("ThreadService.listThreads", () => {
|
|
|
247
249
|
const draft = await post({ status: "draft" });
|
|
248
250
|
|
|
249
251
|
const published = await services.threads.listThreads(
|
|
250
|
-
{ audience: "author", selection: {} },
|
|
252
|
+
{ audience: "author", selection: {}, timeZone: "UTC" },
|
|
251
253
|
{ limit: 10 },
|
|
252
254
|
);
|
|
253
255
|
expect(published.threads.map((thread) => thread.root.id)).toEqual([
|
|
@@ -255,7 +257,7 @@ describe("ThreadService.listThreads", () => {
|
|
|
255
257
|
hidden.id,
|
|
256
258
|
]);
|
|
257
259
|
const drafts = await services.threads.listThreads(
|
|
258
|
-
{ audience: "author", status: "draft", selection: {} },
|
|
260
|
+
{ audience: "author", status: "draft", selection: {}, timeZone: "UTC" },
|
|
259
261
|
{ limit: 10 },
|
|
260
262
|
);
|
|
261
263
|
expect(drafts.threads.map((thread) => thread.root.id)).toEqual([draft.id]);
|
|
@@ -265,7 +267,11 @@ describe("ThreadService.listThreads", () => {
|
|
|
265
267
|
const { services } = setup();
|
|
266
268
|
await expect(
|
|
267
269
|
services.threads.listThreads(
|
|
268
|
-
{
|
|
270
|
+
{
|
|
271
|
+
audience: "reader",
|
|
272
|
+
selection: { visibility: "private" },
|
|
273
|
+
timeZone: "UTC",
|
|
274
|
+
},
|
|
269
275
|
{ limit: 10 },
|
|
270
276
|
),
|
|
271
277
|
).rejects.toBeInstanceOf(ValidationError);
|
|
@@ -405,17 +411,26 @@ describe("posts.listThreadPostsPage", () => {
|
|
|
405
411
|
expect(rest.posts.map((p) => p.id)).toEqual([all[2]?.id, added.id]);
|
|
406
412
|
});
|
|
407
413
|
|
|
408
|
-
|
|
414
|
+
// A fold's gap hands this cursor out before any page has been read.
|
|
415
|
+
it("resumes after a Post from a cursor built for it", async () => {
|
|
409
416
|
const { services, root, all } = await thread(6);
|
|
417
|
+
const first = await services.posts.listThreadPostsPage(
|
|
418
|
+
root.id,
|
|
419
|
+
{},
|
|
420
|
+
{ limit: 3 },
|
|
421
|
+
);
|
|
422
|
+
expect(encodeThreadPostsCursorAfter(all[2] as Post)).toBe(first.nextCursor);
|
|
423
|
+
expect(encodeThreadPostsCursorAfter(root)).not.toBe(first.nextCursor);
|
|
424
|
+
|
|
410
425
|
const page = await services.posts.listThreadPostsPage(
|
|
411
426
|
root.id,
|
|
412
427
|
{},
|
|
413
|
-
{ limit: 2, cursor:
|
|
428
|
+
{ limit: 2, cursor: encodeThreadPostsCursorAfter(root) },
|
|
414
429
|
);
|
|
415
|
-
expect(page.posts.map((p) => p.id)).toEqual([all[
|
|
430
|
+
expect(page.posts.map((p) => p.id)).toEqual([all[1]?.id, all[2]?.id]);
|
|
416
431
|
});
|
|
417
432
|
|
|
418
|
-
it("refuses
|
|
433
|
+
it("refuses a post ID as a cursor, from this Thread or another", async () => {
|
|
419
434
|
const { services, root, all } = await thread(2);
|
|
420
435
|
const other = await services.posts.create({
|
|
421
436
|
format: "note",
|
|
@@ -427,7 +442,7 @@ describe("posts.listThreadPostsPage", () => {
|
|
|
427
442
|
replyToId: all[1]?.id,
|
|
428
443
|
status: "draft",
|
|
429
444
|
});
|
|
430
|
-
for (const cursor of [other.id, unsent.id, "not-a-cursor"]) {
|
|
445
|
+
for (const cursor of [all[0]?.id, other.id, unsent.id, "not-a-cursor"]) {
|
|
431
446
|
await expect(
|
|
432
447
|
services.posts.listThreadPostsPage(root.id, {}, { limit: 5, cursor }),
|
|
433
448
|
).rejects.toBeInstanceOf(ValidationError);
|
package/src/services/auth.ts
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
ConfigurationError,
|
|
27
27
|
ValidationError,
|
|
28
28
|
NotFoundError,
|
|
29
|
+
ForbiddenError,
|
|
29
30
|
} from "../lib/errors.js";
|
|
30
31
|
import { hashPassword } from "../lib/password.js";
|
|
31
32
|
|
|
@@ -100,6 +101,13 @@ export function createAuthService(
|
|
|
100
101
|
databaseDialect?: DatabaseDialect;
|
|
101
102
|
/** Signing key for derived tokens. Absent only where no route needs one. */
|
|
102
103
|
authSecret?: string;
|
|
104
|
+
/** The site whose owner a password reset applies to. */
|
|
105
|
+
siteId?: string;
|
|
106
|
+
/**
|
|
107
|
+
* `host-based` when one database holds many sites. A factory reset wipes
|
|
108
|
+
* every table, so it is refused there.
|
|
109
|
+
*/
|
|
110
|
+
siteResolutionMode?: "single-site" | "host-based";
|
|
103
111
|
},
|
|
104
112
|
databaseSchema: DatabaseSchema = sqliteSchemaBundle,
|
|
105
113
|
): AuthService {
|
|
@@ -223,12 +231,28 @@ export function createAuthService(
|
|
|
223
231
|
|
|
224
232
|
const hashedPw = await hashPassword(newPassword);
|
|
225
233
|
|
|
226
|
-
//
|
|
227
|
-
|
|
228
|
-
|
|
234
|
+
// The reset token belongs to this site, so it resets this site's owner.
|
|
235
|
+
// The user table is shared by every site in a host-based database, so
|
|
236
|
+
// "the first user" could be someone else's account.
|
|
237
|
+
if (!config?.siteId) {
|
|
238
|
+
throw new ConfigurationError(
|
|
239
|
+
"A password reset needs the current site.",
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
const owners = await db
|
|
243
|
+
.select({ id: siteMembers.userId })
|
|
244
|
+
.from(siteMembers)
|
|
245
|
+
.where(
|
|
246
|
+
and(
|
|
247
|
+
eq(siteMembers.siteId, config.siteId),
|
|
248
|
+
eq(siteMembers.role, "owner"),
|
|
249
|
+
),
|
|
250
|
+
)
|
|
251
|
+
.limit(1);
|
|
252
|
+
if (!owners[0]) {
|
|
229
253
|
throw new NotFoundError("User account");
|
|
230
254
|
}
|
|
231
|
-
const userId =
|
|
255
|
+
const userId = owners[0].id;
|
|
232
256
|
|
|
233
257
|
// Update password
|
|
234
258
|
await db
|
|
@@ -255,6 +279,14 @@ export function createAuthService(
|
|
|
255
279
|
},
|
|
256
280
|
|
|
257
281
|
async deleteAllData(deps) {
|
|
282
|
+
// Every delete below is table-wide. In a host-based database that is
|
|
283
|
+
// every site's data, so deleting a site belongs to the control plane.
|
|
284
|
+
if (config?.siteResolutionMode === "host-based") {
|
|
285
|
+
throw new ForbiddenError(
|
|
286
|
+
"This server hosts more than one site, so a site can't be deleted from its own settings.",
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
258
290
|
// 1. Collect all storage keys for cleanup before deleting DB records
|
|
259
291
|
if (deps?.storage) {
|
|
260
292
|
const mediaRows = await db
|