emdash 0.8.0 → 0.10.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/dist/{adapters-BKSf3T9R.d.mts → adapters-BktHA7EO.d.mts} +1 -1
- package/dist/{adapters-BKSf3T9R.d.mts.map → adapters-BktHA7EO.d.mts.map} +1 -1
- package/dist/{apply-x0eMK1lX.mjs → apply-UsrFuO7l.mjs} +207 -355
- package/dist/apply-UsrFuO7l.mjs.map +1 -0
- package/dist/astro/index.d.mts +6 -6
- package/dist/astro/index.d.mts.map +1 -1
- package/dist/astro/index.mjs +118 -4
- package/dist/astro/index.mjs.map +1 -1
- package/dist/astro/middleware/auth.d.mts +6 -7
- package/dist/astro/middleware/auth.d.mts.map +1 -1
- package/dist/astro/middleware/auth.mjs +14 -57
- package/dist/astro/middleware/auth.mjs.map +1 -1
- package/dist/astro/middleware/redirect.d.mts.map +1 -1
- package/dist/astro/middleware/redirect.mjs +15 -10
- package/dist/astro/middleware/redirect.mjs.map +1 -1
- package/dist/astro/middleware/request-context.d.mts.map +1 -1
- package/dist/astro/middleware/request-context.mjs +8 -5
- package/dist/astro/middleware/request-context.mjs.map +1 -1
- package/dist/astro/middleware/setup.mjs +1 -1
- package/dist/astro/middleware.d.mts.map +1 -1
- package/dist/astro/middleware.mjs +70 -121
- package/dist/astro/middleware.mjs.map +1 -1
- package/dist/astro/types.d.mts +25 -10
- package/dist/astro/types.d.mts.map +1 -1
- package/dist/{byline-Chbr2GoP.mjs → byline-C3vnhIpU.mjs} +4 -4
- package/dist/{byline-Chbr2GoP.mjs.map → byline-C3vnhIpU.mjs.map} +1 -1
- package/dist/bylines-esI7ioa9.mjs +113 -0
- package/dist/bylines-esI7ioa9.mjs.map +1 -0
- package/dist/cache-fTzxgMFJ.mjs +65 -0
- package/dist/cache-fTzxgMFJ.mjs.map +1 -0
- package/dist/{chunks-HGz06Soa.mjs → chunks-Da2-b-oA.mjs} +8 -2
- package/dist/{chunks-HGz06Soa.mjs.map → chunks-Da2-b-oA.mjs.map} +1 -1
- package/dist/cli/index.mjs +456 -90
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/cf-access.d.mts +1 -1
- package/dist/client/index.d.mts +1 -1
- package/dist/client/index.mjs +3 -3
- package/dist/client/index.mjs.map +1 -1
- package/dist/{config-BXwuX8Bx.mjs → config-CVssduLe.mjs} +1 -1
- package/dist/{config-BXwuX8Bx.mjs.map → config-CVssduLe.mjs.map} +1 -1
- package/dist/{content-BcQPYxdV.mjs → content-C7G4QXkK.mjs} +42 -14
- package/dist/content-C7G4QXkK.mjs.map +1 -0
- package/dist/db/index.d.mts +3 -3
- package/dist/db/index.mjs +2 -2
- package/dist/db/libsql.d.mts +1 -1
- package/dist/db/libsql.d.mts.map +1 -1
- package/dist/db/libsql.mjs +7 -2
- package/dist/db/libsql.mjs.map +1 -1
- package/dist/db/postgres.d.mts +1 -1
- package/dist/db/sqlite.d.mts +1 -1
- package/dist/db/sqlite.d.mts.map +1 -1
- package/dist/db/sqlite.mjs +8 -3
- package/dist/db/sqlite.mjs.map +1 -1
- package/dist/{db-errors-l1Qh2RPR.mjs → db-errors-B7P2pSCn.mjs} +1 -1
- package/dist/{db-errors-l1Qh2RPR.mjs.map → db-errors-B7P2pSCn.mjs.map} +1 -1
- package/dist/{default-DCVqE5ib.mjs → default-pHuz9WF6.mjs} +1 -1
- package/dist/{default-DCVqE5ib.mjs.map → default-pHuz9WF6.mjs.map} +1 -1
- package/dist/{dialect-helpers-DhTzaUxP.mjs → dialect-helpers-BKCvISIQ.mjs} +19 -2
- package/dist/dialect-helpers-BKCvISIQ.mjs.map +1 -0
- package/dist/{error-zG5T1UGA.mjs → error-DqnRMM5z.mjs} +1 -1
- package/dist/{error-zG5T1UGA.mjs.map → error-DqnRMM5z.mjs.map} +1 -1
- package/dist/{index-DIb-CzNx.d.mts → index-DjPMOfO0.d.mts} +162 -87
- package/dist/index-DjPMOfO0.d.mts.map +1 -0
- package/dist/index.d.mts +11 -11
- package/dist/index.mjs +27 -24
- package/dist/{load-CyEoextb.mjs → load-sXRuM7Us.mjs} +2 -2
- package/dist/{load-CyEoextb.mjs.map → load-sXRuM7Us.mjs.map} +1 -1
- package/dist/{loader-CndGj8kM.mjs → loader-Bx2_9-5e.mjs} +53 -8
- package/dist/loader-Bx2_9-5e.mjs.map +1 -0
- package/dist/{manifest-schema-DH9xhc6t.mjs → manifest-schema-CXAbd1vH.mjs} +33 -3
- package/dist/manifest-schema-CXAbd1vH.mjs.map +1 -0
- package/dist/media/index.d.mts +1 -1
- package/dist/media/index.mjs +1 -1
- package/dist/media/local-runtime.d.mts +7 -7
- package/dist/{mode-BnAOqItE.mjs → mode-YhqNVef_.mjs} +1 -1
- package/dist/{mode-BnAOqItE.mjs.map → mode-YhqNVef_.mjs.map} +1 -1
- package/dist/options-nPxWnrya.mjs +117 -0
- package/dist/options-nPxWnrya.mjs.map +1 -0
- package/dist/page/index.d.mts +2 -2
- package/dist/{patterns-CrCYkMBb.mjs → patterns-DsUZ4uxI.mjs} +1 -1
- package/dist/{patterns-CrCYkMBb.mjs.map → patterns-DsUZ4uxI.mjs.map} +1 -1
- package/dist/{placeholder-D29tWZ7o.d.mts → placeholder-CDPtkelt.d.mts} +1 -1
- package/dist/{placeholder-D29tWZ7o.d.mts.map → placeholder-CDPtkelt.d.mts.map} +1 -1
- package/dist/{placeholder-C-fk5hYI.mjs → placeholder-Ci0RLeCk.mjs} +1 -1
- package/dist/{placeholder-C-fk5hYI.mjs.map → placeholder-Ci0RLeCk.mjs.map} +1 -1
- package/dist/plugins/adapt-sandbox-entry.d.mts +5 -5
- package/dist/plugins/adapt-sandbox-entry.d.mts.map +1 -1
- package/dist/plugins/adapt-sandbox-entry.mjs +6 -5
- package/dist/plugins/adapt-sandbox-entry.mjs.map +1 -1
- package/dist/public-url-B1AxbbbQ.mjs +51 -0
- package/dist/public-url-B1AxbbbQ.mjs.map +1 -0
- package/dist/{query-fqEdLFms.mjs → query-Bo-msrmu.mjs} +114 -16
- package/dist/query-Bo-msrmu.mjs.map +1 -0
- package/dist/{redirect-D_pshWdf.mjs → redirect-C5H7VGIX.mjs} +11 -6
- package/dist/redirect-C5H7VGIX.mjs.map +1 -0
- package/dist/{registry-C3Mr0ODu.mjs → registry-Beb7wxFc.mjs} +39 -5
- package/dist/registry-Beb7wxFc.mjs.map +1 -0
- package/dist/{request-cache-Ci7f5pBb.mjs → request-cache-C-tIpYIw.mjs} +1 -1
- package/dist/{request-cache-Ci7f5pBb.mjs.map → request-cache-C-tIpYIw.mjs.map} +1 -1
- package/dist/runner-Clwe4Mme.d.mts +44 -0
- package/dist/runner-Clwe4Mme.d.mts.map +1 -0
- package/dist/{runner-tQ7BJ4T7.mjs → runner-DMnlIkh4.mjs} +616 -191
- package/dist/runner-DMnlIkh4.mjs.map +1 -0
- package/dist/runtime.d.mts +6 -6
- package/dist/runtime.mjs +2 -2
- package/dist/{search-BoZYFuUk.mjs → search-DkN-BqsS.mjs} +270 -152
- package/dist/search-DkN-BqsS.mjs.map +1 -0
- package/dist/secrets-CZ8rxLX3.mjs +314 -0
- package/dist/secrets-CZ8rxLX3.mjs.map +1 -0
- package/dist/seed/index.d.mts +2 -2
- package/dist/seed/index.mjs +13 -11
- package/dist/seo/index.d.mts +1 -1
- package/dist/storage/local.d.mts +1 -1
- package/dist/storage/local.mjs +1 -1
- package/dist/storage/s3.d.mts +1 -1
- package/dist/storage/s3.mjs +1 -1
- package/dist/taxonomies-CTtewrSQ.mjs +407 -0
- package/dist/taxonomies-CTtewrSQ.mjs.map +1 -0
- package/dist/taxonomy-DSxx2K2L.mjs +218 -0
- package/dist/taxonomy-DSxx2K2L.mjs.map +1 -0
- package/dist/{tokens-D9vnZqYS.mjs → tokens-CyRDPVW2.mjs} +1 -1
- package/dist/{tokens-D9vnZqYS.mjs.map → tokens-CyRDPVW2.mjs.map} +1 -1
- package/dist/{transaction-Cn2rjY78.mjs → transaction-D44LBXvU.mjs} +1 -1
- package/dist/{transaction-Cn2rjY78.mjs.map → transaction-D44LBXvU.mjs.map} +1 -1
- package/dist/{transport-CUnEL3Vs.d.mts → transport-DX_5rpsq.d.mts} +1 -1
- package/dist/{transport-CUnEL3Vs.d.mts.map → transport-DX_5rpsq.d.mts.map} +1 -1
- package/dist/{transport-C9ugt2Nr.mjs → transport-xpzIjCIB.mjs} +6 -5
- package/dist/{transport-C9ugt2Nr.mjs.map → transport-xpzIjCIB.mjs.map} +1 -1
- package/dist/{types-BrA0xf5I.d.mts → types-B_CXXnzh.d.mts} +1 -1
- package/dist/{types-BrA0xf5I.d.mts.map → types-B_CXXnzh.d.mts.map} +1 -1
- package/dist/{types-DIMwPFub.d.mts → types-C-aFbqmA.d.mts} +1 -1
- package/dist/{types-DIMwPFub.d.mts.map → types-C-aFbqmA.d.mts.map} +1 -1
- package/dist/types-CoO6mpV3.mjs +68 -0
- package/dist/types-CoO6mpV3.mjs.map +1 -0
- package/dist/{types-i36XcA_X.d.mts → types-D19uBYWn.d.mts} +83 -7
- package/dist/types-D19uBYWn.d.mts.map +1 -0
- package/dist/{types-BmPPSUEx.d.mts → types-Dl1fgFjn.d.mts} +24 -2
- package/dist/{types-BmPPSUEx.d.mts.map → types-Dl1fgFjn.d.mts.map} +1 -1
- package/dist/{types-CS8FIX7L.d.mts → types-Dtx1mSMX.d.mts} +9 -1
- package/dist/types-Dtx1mSMX.d.mts.map +1 -0
- package/dist/{types-Bm1dn-q3.mjs → types-Eg829jj9.mjs} +1 -1
- package/dist/{types-Bm1dn-q3.mjs.map → types-Eg829jj9.mjs.map} +1 -1
- package/dist/{types-CgqmmMJB.mjs → types-K-EkEQCI.mjs} +1 -1
- package/dist/{types-CgqmmMJB.mjs.map → types-K-EkEQCI.mjs.map} +1 -1
- package/dist/{validate-CxVsLehf.mjs → validate-CBIbxM3L.mjs} +14 -10
- package/dist/validate-CBIbxM3L.mjs.map +1 -0
- package/dist/{validate-DHxmpFJt.d.mts → validate-DHGwADqO.d.mts} +18 -5
- package/dist/validate-DHGwADqO.d.mts.map +1 -0
- package/dist/{validation-C-ZpN2GI.mjs → validation-B1NYiEos.mjs} +6 -6
- package/dist/{validation-C-ZpN2GI.mjs.map → validation-B1NYiEos.mjs.map} +1 -1
- package/dist/version-CMD42IRC.mjs +7 -0
- package/dist/{version-Bbq8TCrz.mjs.map → version-CMD42IRC.mjs.map} +1 -1
- package/dist/{zod-generator-CpwccCIv.mjs → zod-generator-BNJDQBSZ.mjs} +11 -6
- package/dist/{zod-generator-CpwccCIv.mjs.map → zod-generator-BNJDQBSZ.mjs.map} +1 -1
- package/locals.d.ts +1 -6
- package/package.json +9 -8
- package/src/api/handlers/comments.ts +6 -4
- package/src/api/handlers/content.ts +40 -1
- package/src/api/handlers/dashboard.ts +29 -36
- package/src/api/handlers/device-flow.ts +5 -0
- package/src/api/handlers/marketplace.ts +11 -4
- package/src/api/handlers/menus.ts +256 -75
- package/src/api/handlers/oauth-authorization.ts +72 -33
- package/src/api/handlers/revision.ts +23 -14
- package/src/api/handlers/taxonomies.ts +273 -100
- package/src/api/public-url.ts +48 -2
- package/src/api/schemas/comments.ts +2 -2
- package/src/api/schemas/common.ts +7 -0
- package/src/api/schemas/content.ts +17 -0
- package/src/api/schemas/menus.ts +23 -0
- package/src/api/schemas/sections.ts +3 -3
- package/src/api/schemas/taxonomies.ts +39 -0
- package/src/api/schemas/users.ts +1 -1
- package/src/api/types.ts +5 -1
- package/src/astro/integration/index.ts +17 -0
- package/src/astro/integration/routes.ts +10 -0
- package/src/astro/integration/runtime.ts +30 -0
- package/src/astro/integration/virtual-modules.ts +32 -2
- package/src/astro/integration/vite-config.ts +6 -1
- package/src/astro/middleware/auth.ts +13 -6
- package/src/astro/middleware/redirect.ts +29 -16
- package/src/astro/middleware/request-context.ts +15 -5
- package/src/astro/middleware.ts +23 -9
- package/src/astro/routes/api/auth/invite/complete.ts +6 -1
- package/src/astro/routes/api/auth/passkey/register/verify.ts +6 -1
- package/src/astro/routes/api/auth/passkey/verify.ts +6 -1
- package/src/astro/routes/api/auth/signup/complete.ts +6 -1
- package/src/astro/routes/api/comments/[collection]/[contentId]/index.ts +2 -2
- package/src/astro/routes/api/content/[collection]/[id]/discard-draft.ts +4 -2
- package/src/astro/routes/api/content/[collection]/[id]/permanent.ts +1 -1
- package/src/astro/routes/api/content/[collection]/[id]/preview-url.ts +34 -12
- package/src/astro/routes/api/content/[collection]/[id]/publish.ts +32 -2
- package/src/astro/routes/api/content/[collection]/[id]/restore.ts +4 -2
- package/src/astro/routes/api/content/[collection]/[id]/revisions.ts +3 -2
- package/src/astro/routes/api/content/[collection]/[id]/terms/[taxonomy].ts +8 -4
- package/src/astro/routes/api/content/[collection]/[id].ts +12 -0
- package/src/astro/routes/api/import/wordpress/execute.ts +3 -1
- package/src/astro/routes/api/import/wordpress/prepare.ts +7 -8
- package/src/astro/routes/api/import/wordpress/rewrite-url-helpers.ts +196 -0
- package/src/astro/routes/api/import/wordpress/rewrite-urls.ts +9 -177
- package/src/astro/routes/api/import/wordpress-plugin/execute.ts +3 -1
- package/src/astro/routes/api/manifest.ts +62 -45
- package/src/astro/routes/api/media/[id]/confirm.ts +10 -1
- package/src/astro/routes/api/media/providers/[providerId]/index.ts +12 -3
- package/src/astro/routes/api/menus/[name]/items.ts +16 -6
- package/src/astro/routes/api/menus/[name]/reorder.ts +8 -3
- package/src/astro/routes/api/menus/[name]/translations.ts +82 -0
- package/src/astro/routes/api/menus/[name].ts +19 -10
- package/src/astro/routes/api/menus/index.ts +9 -6
- package/src/astro/routes/api/openapi.json.ts +27 -10
- package/src/astro/routes/api/redirects/404s/index.ts +10 -4
- package/src/astro/routes/api/redirects/404s/summary.ts +4 -2
- package/src/astro/routes/api/redirects/[id].ts +10 -4
- package/src/astro/routes/api/redirects/index.ts +7 -3
- package/src/astro/routes/api/revisions/[revisionId]/index.ts +1 -1
- package/src/astro/routes/api/schema/collections/[slug]/fields/[fieldSlug].ts +0 -2
- package/src/astro/routes/api/schema/collections/[slug]/fields/index.ts +0 -1
- package/src/astro/routes/api/schema/collections/[slug]/fields/reorder.ts +0 -1
- package/src/astro/routes/api/schema/collections/[slug]/index.ts +2 -2
- package/src/astro/routes/api/schema/collections/index.ts +1 -1
- package/src/astro/routes/api/search/index.ts +10 -2
- package/src/astro/routes/api/sections/[slug].ts +10 -4
- package/src/astro/routes/api/sections/index.ts +7 -3
- package/src/astro/routes/api/setup/admin-verify.ts +6 -1
- package/src/astro/routes/api/snapshot.ts +44 -18
- package/src/astro/routes/api/taxonomies/[name]/terms/[slug]/translations.ts +89 -0
- package/src/astro/routes/api/taxonomies/[name]/terms/[slug].ts +22 -22
- package/src/astro/routes/api/taxonomies/[name]/terms/index.ts +11 -14
- package/src/astro/routes/api/taxonomies/index.ts +9 -7
- package/src/astro/routes/api/themes/preview.ts +11 -5
- package/src/astro/types.ts +23 -3
- package/src/auth/allowed-origins.ts +168 -0
- package/src/auth/passkey-config.ts +35 -13
- package/src/bylines/index.ts +37 -88
- package/src/cli/commands/auth.ts +28 -6
- package/src/cli/commands/bundle-utils.ts +11 -2
- package/src/cli/commands/bundle.ts +28 -8
- package/src/cli/commands/content.ts +13 -0
- package/src/cli/commands/export-seed.ts +82 -21
- package/src/cli/commands/login.ts +8 -1
- package/src/cli/commands/plugin-init.ts +216 -90
- package/src/cli/commands/publish.ts +24 -0
- package/src/cli/commands/secrets.ts +183 -0
- package/src/cli/credentials.ts +1 -1
- package/src/cli/index.ts +5 -1
- package/src/client/index.ts +4 -4
- package/src/client/transport.ts +17 -7
- package/src/components/Break.astro +2 -2
- package/src/components/EmDashHead.astro +18 -13
- package/src/components/Embed.astro +1 -1
- package/src/components/Gallery.astro +1 -1
- package/src/components/Image.astro +1 -1
- package/src/components/InlinePortableTextEditor.tsx +104 -18
- package/src/config/secrets.ts +528 -0
- package/src/database/dialect-helpers.ts +50 -0
- package/src/database/migrations/034_published_at_index.ts +1 -1
- package/src/database/migrations/035_bounded_404_log.ts +56 -39
- package/src/database/migrations/036_i18n_menus_and_taxonomies.ts +477 -0
- package/src/database/migrations/runner.ts +158 -23
- package/src/database/repositories/content.ts +47 -12
- package/src/database/repositories/redirect.ts +14 -3
- package/src/database/repositories/taxonomy.ts +212 -82
- package/src/database/types.ts +10 -2
- package/src/db/libsql.ts +1 -3
- package/src/db/sqlite.ts +2 -5
- package/src/emdash-runtime.ts +84 -159
- package/src/i18n/resolve.ts +37 -0
- package/src/index.ts +9 -0
- package/src/loader.ts +73 -3
- package/src/mcp/server.ts +180 -54
- package/src/menus/index.ts +143 -124
- package/src/menus/types.ts +15 -1
- package/src/page/site-identity.ts +58 -0
- package/src/plugins/adapt-sandbox-entry.ts +22 -10
- package/src/plugins/context.ts +13 -10
- package/src/plugins/define-plugin.ts +40 -12
- package/src/plugins/hooks.ts +23 -19
- package/src/plugins/index.ts +9 -0
- package/src/plugins/manifest-schema.ts +37 -2
- package/src/plugins/types.ts +151 -11
- package/src/preview/urls.ts +23 -3
- package/src/query.ts +148 -5
- package/src/redirects/cache.ts +38 -18
- package/src/schema/registry.ts +56 -0
- package/src/schema/zod-generator.ts +39 -7
- package/src/seed/apply.ts +142 -54
- package/src/seed/types.ts +14 -1
- package/src/seed/validate.ts +27 -13
- package/src/settings/index.ts +80 -6
- package/src/settings/types.ts +23 -1
- package/src/taxonomies/index.ts +237 -210
- package/src/taxonomies/types.ts +10 -0
- package/dist/apply-x0eMK1lX.mjs.map +0 -1
- package/dist/bylines-CRNsVG88.mjs +0 -157
- package/dist/bylines-CRNsVG88.mjs.map +0 -1
- package/dist/cache-BkKBuIvS.mjs +0 -56
- package/dist/cache-BkKBuIvS.mjs.map +0 -1
- package/dist/chunk-ClPoSABd.mjs +0 -21
- package/dist/content-BcQPYxdV.mjs.map +0 -1
- package/dist/dialect-helpers-DhTzaUxP.mjs.map +0 -1
- package/dist/index-DIb-CzNx.d.mts.map +0 -1
- package/dist/loader-CndGj8kM.mjs.map +0 -1
- package/dist/manifest-schema-DH9xhc6t.mjs.map +0 -1
- package/dist/query-fqEdLFms.mjs.map +0 -1
- package/dist/redirect-D_pshWdf.mjs.map +0 -1
- package/dist/registry-C3Mr0ODu.mjs.map +0 -1
- package/dist/runner-OURCaApa.d.mts +0 -34
- package/dist/runner-OURCaApa.d.mts.map +0 -1
- package/dist/runner-tQ7BJ4T7.mjs.map +0 -1
- package/dist/search-BoZYFuUk.mjs.map +0 -1
- package/dist/taxonomies-B4IAshV8.mjs +0 -308
- package/dist/taxonomies-B4IAshV8.mjs.map +0 -1
- package/dist/types-CS8FIX7L.d.mts.map +0 -1
- package/dist/types-i36XcA_X.d.mts.map +0 -1
- package/dist/validate-CxVsLehf.mjs.map +0 -1
- package/dist/validate-DHxmpFJt.d.mts.map +0 -1
- package/dist/version-Bbq8TCrz.mjs +0 -7
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
const REGEX_SPECIAL_CHARS = /[.*+?^${}()|[\]\\]/g;
|
|
2
|
+
const WORDPRESS_IMAGE_SIZE_SUFFIX = /-\d+x\d+(?=\.[^./?#]+$)/;
|
|
3
|
+
const BASE_URL_EXTENSION = /^(.+)(\.[^./?#]+)$/;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Strip query parameters from a URL for base matching
|
|
7
|
+
*/
|
|
8
|
+
export function getBaseUrl(url: string): string {
|
|
9
|
+
try {
|
|
10
|
+
const parsed = new URL(url);
|
|
11
|
+
return `${parsed.origin}${parsed.pathname}`;
|
|
12
|
+
} catch {
|
|
13
|
+
// If URL parsing fails, try simple string split
|
|
14
|
+
return url.split("?")[0] || url;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Build a map of base URLs to new URLs for flexible matching
|
|
20
|
+
*/
|
|
21
|
+
export function buildBaseUrlMap(urlMap: Record<string, string>): Map<string, string> {
|
|
22
|
+
const baseMap = new Map<string, string>();
|
|
23
|
+
for (const [oldUrl, newUrl] of Object.entries(urlMap)) {
|
|
24
|
+
const baseUrl = getBaseUrl(oldUrl);
|
|
25
|
+
baseMap.set(baseUrl, newUrl);
|
|
26
|
+
}
|
|
27
|
+
return baseMap;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Find matching new URL for a given URL, checking exact, base, and WordPress image-size matches
|
|
32
|
+
*/
|
|
33
|
+
export function findMatchingUrl(
|
|
34
|
+
url: string,
|
|
35
|
+
exactMap: Record<string, string>,
|
|
36
|
+
baseMap: Map<string, string>,
|
|
37
|
+
): string | null {
|
|
38
|
+
if (exactMap[url]) {
|
|
39
|
+
return exactMap[url];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const baseUrl = getBaseUrl(url);
|
|
43
|
+
const baseMatch = baseMap.get(baseUrl);
|
|
44
|
+
if (baseMatch) {
|
|
45
|
+
return baseMatch;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const wordPressImageMatch = baseMap.get(stripWordPressImageSizeSuffix(baseUrl));
|
|
49
|
+
if (wordPressImageMatch) {
|
|
50
|
+
return wordPressImageMatch;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Portable Text block type (simplified for URL rewriting)
|
|
58
|
+
*/
|
|
59
|
+
export interface PortableTextBlock {
|
|
60
|
+
_type: string;
|
|
61
|
+
_key?: string;
|
|
62
|
+
asset?: {
|
|
63
|
+
_type?: string;
|
|
64
|
+
_ref?: string;
|
|
65
|
+
url?: string;
|
|
66
|
+
};
|
|
67
|
+
link?: string;
|
|
68
|
+
// For nested content like galleries
|
|
69
|
+
images?: PortableTextBlock[];
|
|
70
|
+
columns?: Array<{ content?: PortableTextBlock[] }>;
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Rewrite URLs in a Portable Text array, returning whether any changes were made
|
|
76
|
+
*/
|
|
77
|
+
export function rewritePortableTextUrls(
|
|
78
|
+
blocks: PortableTextBlock[],
|
|
79
|
+
exactMap: Record<string, string>,
|
|
80
|
+
baseMap: Map<string, string>,
|
|
81
|
+
): { changed: boolean; urlsRewritten: number } {
|
|
82
|
+
let changed = false;
|
|
83
|
+
let urlsRewritten = 0;
|
|
84
|
+
|
|
85
|
+
for (const block of blocks) {
|
|
86
|
+
// Handle image blocks
|
|
87
|
+
if (block._type === "image" && block.asset?.url) {
|
|
88
|
+
const newUrl = findMatchingUrl(block.asset.url, exactMap, baseMap);
|
|
89
|
+
if (newUrl) {
|
|
90
|
+
block.asset.url = newUrl;
|
|
91
|
+
block.asset._ref = newUrl; // Also update the reference
|
|
92
|
+
changed = true;
|
|
93
|
+
urlsRewritten++;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Handle image link URLs (for linked images)
|
|
98
|
+
if (block._type === "image" && block.link) {
|
|
99
|
+
const newUrl = findMatchingUrl(block.link, exactMap, baseMap);
|
|
100
|
+
if (newUrl) {
|
|
101
|
+
block.link = newUrl;
|
|
102
|
+
changed = true;
|
|
103
|
+
urlsRewritten++;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Handle gallery blocks with nested images
|
|
108
|
+
if (block._type === "gallery" && Array.isArray(block.images)) {
|
|
109
|
+
const result = rewritePortableTextUrls(block.images, exactMap, baseMap);
|
|
110
|
+
if (result.changed) {
|
|
111
|
+
changed = true;
|
|
112
|
+
urlsRewritten += result.urlsRewritten;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Handle columns blocks with nested content
|
|
117
|
+
if (block._type === "columns" && Array.isArray(block.columns)) {
|
|
118
|
+
for (const column of block.columns) {
|
|
119
|
+
if (Array.isArray(column.content)) {
|
|
120
|
+
const result = rewritePortableTextUrls(column.content, exactMap, baseMap);
|
|
121
|
+
if (result.changed) {
|
|
122
|
+
changed = true;
|
|
123
|
+
urlsRewritten += result.urlsRewritten;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return { changed, urlsRewritten };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Rewrite URLs in a string field using simple string replacement
|
|
135
|
+
*/
|
|
136
|
+
export function rewriteStringUrls(
|
|
137
|
+
value: string,
|
|
138
|
+
exactMap: Record<string, string>,
|
|
139
|
+
baseMap: Map<string, string>,
|
|
140
|
+
): { newValue: string; changed: boolean; urlsRewritten: number } {
|
|
141
|
+
let newValue = value;
|
|
142
|
+
let changed = false;
|
|
143
|
+
let urlsRewritten = 0;
|
|
144
|
+
|
|
145
|
+
// Try exact matches first
|
|
146
|
+
for (const [oldUrl, newUrl] of Object.entries(exactMap)) {
|
|
147
|
+
if (newValue.includes(oldUrl)) {
|
|
148
|
+
newValue = newValue.split(oldUrl).join(newUrl);
|
|
149
|
+
changed = true;
|
|
150
|
+
urlsRewritten++;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// For base URL matching in strings, we need to be more careful
|
|
155
|
+
// Only match if we find a URL that starts with the base
|
|
156
|
+
for (const [baseUrl, newUrl] of baseMap.entries()) {
|
|
157
|
+
// Look for the base URL followed by optional query string or end
|
|
158
|
+
const regex = buildBaseUrlMatchRegex(baseUrl);
|
|
159
|
+
const matches = newValue.match(regex);
|
|
160
|
+
if (matches) {
|
|
161
|
+
for (const match of matches) {
|
|
162
|
+
// Don't replace if we already have an exact match in the map
|
|
163
|
+
if (!exactMap[match]) {
|
|
164
|
+
newValue = newValue.split(match).join(newUrl);
|
|
165
|
+
changed = true;
|
|
166
|
+
urlsRewritten++;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return { newValue, changed, urlsRewritten };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Escape special regex characters in a string
|
|
177
|
+
*/
|
|
178
|
+
function escapeRegExp(string: string): string {
|
|
179
|
+
return string.replace(REGEX_SPECIAL_CHARS, "\\$&");
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function stripWordPressImageSizeSuffix(url: string): string {
|
|
183
|
+
return url.replace(WORDPRESS_IMAGE_SIZE_SUFFIX, "");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function buildBaseUrlMatchRegex(baseUrl: string): RegExp {
|
|
187
|
+
const extensionMatch = BASE_URL_EXTENSION.exec(baseUrl);
|
|
188
|
+
const basePattern = extensionMatch
|
|
189
|
+
? `${escapeRegExp(extensionMatch[1])}(?:-\\d+x\\d+)?${escapeRegExp(extensionMatch[2])}`
|
|
190
|
+
: escapeRegExp(baseUrl);
|
|
191
|
+
|
|
192
|
+
return new RegExp(
|
|
193
|
+
`${basePattern}(\\?[^"'\\s]*)?(?=$|["'\\s<>)\\],;:!?]|\\.(?=$|["'\\s<>)\\]]))`,
|
|
194
|
+
"g",
|
|
195
|
+
);
|
|
196
|
+
}
|
|
@@ -22,9 +22,13 @@ import { normalizeMediaValue } from "#media/normalize.js";
|
|
|
22
22
|
import type { MediaProvider } from "#media/types.js";
|
|
23
23
|
import type { EmDashHandlers } from "#types";
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
import {
|
|
26
|
+
buildBaseUrlMap,
|
|
27
|
+
findMatchingUrl,
|
|
28
|
+
rewritePortableTextUrls,
|
|
29
|
+
rewriteStringUrls,
|
|
30
|
+
} from "./rewrite-url-helpers.js";
|
|
31
|
+
import type { PortableTextBlock } from "./rewrite-url-helpers.js";
|
|
28
32
|
|
|
29
33
|
export interface RewriteUrlsResult {
|
|
30
34
|
/** Total items updated */
|
|
@@ -37,6 +41,8 @@ export interface RewriteUrlsResult {
|
|
|
37
41
|
errors: Array<{ collection: string; id: string; error: string }>;
|
|
38
42
|
}
|
|
39
43
|
|
|
44
|
+
export const prerender = false;
|
|
45
|
+
|
|
40
46
|
export const POST: APIRoute = async ({ request, locals }) => {
|
|
41
47
|
const { emdash, user } = locals;
|
|
42
48
|
|
|
@@ -70,180 +76,6 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
|
|
70
76
|
}
|
|
71
77
|
};
|
|
72
78
|
|
|
73
|
-
/**
|
|
74
|
-
* Strip query parameters from a URL for base matching
|
|
75
|
-
*/
|
|
76
|
-
function getBaseUrl(url: string): string {
|
|
77
|
-
try {
|
|
78
|
-
const parsed = new URL(url);
|
|
79
|
-
return `${parsed.origin}${parsed.pathname}`;
|
|
80
|
-
} catch {
|
|
81
|
-
// If URL parsing fails, try simple string split
|
|
82
|
-
return url.split("?")[0] || url;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Build a map of base URLs to new URLs for flexible matching
|
|
88
|
-
*/
|
|
89
|
-
function buildBaseUrlMap(urlMap: Record<string, string>): Map<string, string> {
|
|
90
|
-
const baseMap = new Map<string, string>();
|
|
91
|
-
for (const [oldUrl, newUrl] of Object.entries(urlMap)) {
|
|
92
|
-
const baseUrl = getBaseUrl(oldUrl);
|
|
93
|
-
baseMap.set(baseUrl, newUrl);
|
|
94
|
-
}
|
|
95
|
-
return baseMap;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Find matching new URL for a given URL, checking both exact and base matches
|
|
100
|
-
*/
|
|
101
|
-
function findMatchingUrl(
|
|
102
|
-
url: string,
|
|
103
|
-
exactMap: Record<string, string>,
|
|
104
|
-
baseMap: Map<string, string>,
|
|
105
|
-
): string | null {
|
|
106
|
-
// Try exact match first
|
|
107
|
-
if (exactMap[url]) {
|
|
108
|
-
return exactMap[url];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Try base URL match (ignoring query params)
|
|
112
|
-
const baseUrl = getBaseUrl(url);
|
|
113
|
-
const baseMatch = baseMap.get(baseUrl);
|
|
114
|
-
if (baseMatch) {
|
|
115
|
-
return baseMatch;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return null;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Portable Text block type (simplified for URL rewriting)
|
|
123
|
-
*/
|
|
124
|
-
interface PortableTextBlock {
|
|
125
|
-
_type: string;
|
|
126
|
-
_key?: string;
|
|
127
|
-
asset?: {
|
|
128
|
-
_type?: string;
|
|
129
|
-
_ref?: string;
|
|
130
|
-
url?: string;
|
|
131
|
-
};
|
|
132
|
-
link?: string;
|
|
133
|
-
// For nested content like galleries
|
|
134
|
-
images?: PortableTextBlock[];
|
|
135
|
-
columns?: Array<{ content?: PortableTextBlock[] }>;
|
|
136
|
-
[key: string]: unknown;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Rewrite URLs in a Portable Text array, returning whether any changes were made
|
|
141
|
-
*/
|
|
142
|
-
function rewritePortableTextUrls(
|
|
143
|
-
blocks: PortableTextBlock[],
|
|
144
|
-
exactMap: Record<string, string>,
|
|
145
|
-
baseMap: Map<string, string>,
|
|
146
|
-
): { changed: boolean; urlsRewritten: number } {
|
|
147
|
-
let changed = false;
|
|
148
|
-
let urlsRewritten = 0;
|
|
149
|
-
|
|
150
|
-
for (const block of blocks) {
|
|
151
|
-
// Handle image blocks
|
|
152
|
-
if (block._type === "image" && block.asset?.url) {
|
|
153
|
-
const newUrl = findMatchingUrl(block.asset.url, exactMap, baseMap);
|
|
154
|
-
if (newUrl) {
|
|
155
|
-
block.asset.url = newUrl;
|
|
156
|
-
block.asset._ref = newUrl; // Also update the reference
|
|
157
|
-
changed = true;
|
|
158
|
-
urlsRewritten++;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Handle image link URLs (for linked images)
|
|
163
|
-
if (block._type === "image" && block.link) {
|
|
164
|
-
const newUrl = findMatchingUrl(block.link, exactMap, baseMap);
|
|
165
|
-
if (newUrl) {
|
|
166
|
-
block.link = newUrl;
|
|
167
|
-
changed = true;
|
|
168
|
-
urlsRewritten++;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Handle gallery blocks with nested images
|
|
173
|
-
if (block._type === "gallery" && Array.isArray(block.images)) {
|
|
174
|
-
const result = rewritePortableTextUrls(block.images, exactMap, baseMap);
|
|
175
|
-
if (result.changed) {
|
|
176
|
-
changed = true;
|
|
177
|
-
urlsRewritten += result.urlsRewritten;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Handle columns blocks with nested content
|
|
182
|
-
if (block._type === "columns" && Array.isArray(block.columns)) {
|
|
183
|
-
for (const column of block.columns) {
|
|
184
|
-
if (Array.isArray(column.content)) {
|
|
185
|
-
const result = rewritePortableTextUrls(column.content, exactMap, baseMap);
|
|
186
|
-
if (result.changed) {
|
|
187
|
-
changed = true;
|
|
188
|
-
urlsRewritten += result.urlsRewritten;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return { changed, urlsRewritten };
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Rewrite URLs in a string field using simple string replacement
|
|
200
|
-
*/
|
|
201
|
-
function rewriteStringUrls(
|
|
202
|
-
value: string,
|
|
203
|
-
exactMap: Record<string, string>,
|
|
204
|
-
baseMap: Map<string, string>,
|
|
205
|
-
): { newValue: string; changed: boolean; urlsRewritten: number } {
|
|
206
|
-
let newValue = value;
|
|
207
|
-
let changed = false;
|
|
208
|
-
let urlsRewritten = 0;
|
|
209
|
-
|
|
210
|
-
// Try exact matches first
|
|
211
|
-
for (const [oldUrl, newUrl] of Object.entries(exactMap)) {
|
|
212
|
-
if (newValue.includes(oldUrl)) {
|
|
213
|
-
newValue = newValue.split(oldUrl).join(newUrl);
|
|
214
|
-
changed = true;
|
|
215
|
-
urlsRewritten++;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// For base URL matching in strings, we need to be more careful
|
|
220
|
-
// Only match if we find a URL that starts with the base
|
|
221
|
-
for (const [baseUrl, newUrl] of baseMap.entries()) {
|
|
222
|
-
// Look for the base URL followed by optional query string or end
|
|
223
|
-
const regex = new RegExp(escapeRegExp(baseUrl) + "(\\?[^\"'\\s]*)?", "g");
|
|
224
|
-
const matches = newValue.match(regex);
|
|
225
|
-
if (matches) {
|
|
226
|
-
for (const match of matches) {
|
|
227
|
-
// Don't replace if we already have an exact match in the map
|
|
228
|
-
if (!exactMap[match]) {
|
|
229
|
-
newValue = newValue.split(match).join(newUrl);
|
|
230
|
-
changed = true;
|
|
231
|
-
urlsRewritten++;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return { newValue, changed, urlsRewritten };
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Escape special regex characters in a string
|
|
242
|
-
*/
|
|
243
|
-
function escapeRegExp(string: string): string {
|
|
244
|
-
return string.replace(REGEX_SPECIAL_CHARS, "\\$&");
|
|
245
|
-
}
|
|
246
|
-
|
|
247
79
|
async function rewriteUrls(
|
|
248
80
|
db: NonNullable<EmDashHandlers["db"]>,
|
|
249
81
|
urlMap: Record<string, string>,
|
|
@@ -36,7 +36,7 @@ export interface WpPluginImportResponse {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export const POST: APIRoute = async ({ request, locals }) => {
|
|
39
|
-
const { emdash,
|
|
39
|
+
const { emdash, user } = locals;
|
|
40
40
|
|
|
41
41
|
const denied = requirePerm(user, "import:execute");
|
|
42
42
|
if (denied) return denied;
|
|
@@ -46,6 +46,8 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
try {
|
|
49
|
+
const emdashManifest = await emdash.getManifest();
|
|
50
|
+
|
|
49
51
|
const body = await parseBody(request, wpPluginExecuteBody);
|
|
50
52
|
if (isParseError(body)) return body;
|
|
51
53
|
|
|
@@ -9,64 +9,81 @@
|
|
|
9
9
|
|
|
10
10
|
import type { APIRoute } from "astro";
|
|
11
11
|
|
|
12
|
+
import { handleError } from "#api/error.js";
|
|
12
13
|
import { getAuthMode } from "#auth/mode.js";
|
|
13
14
|
|
|
14
15
|
import { COMMIT, VERSION } from "../../../version.js";
|
|
15
|
-
import { getStoredConfig } from "../../integration/runtime.js";
|
|
16
16
|
import type { EmDashManifest } from "../../types.js";
|
|
17
17
|
|
|
18
18
|
export const prerender = false;
|
|
19
19
|
|
|
20
20
|
export const GET: APIRoute = async ({ locals }) => {
|
|
21
|
-
const {
|
|
21
|
+
const { emdash } = locals;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
try {
|
|
24
|
+
// Manifest is built fresh from the live database per admin request.
|
|
25
|
+
// `requestCached` inside `getManifest` dedupes if multiple consumers
|
|
26
|
+
// share the request. Wrapped in try/catch so any future DB-touching
|
|
27
|
+
// additions to `getManifest()` (plugin manifest loading, marketplace
|
|
28
|
+
// lookup, etc.) return the standard error envelope rather than an
|
|
29
|
+
// unstructured 500 — matches the pattern used by the WP execute
|
|
30
|
+
// routes.
|
|
31
|
+
const emdashManifest = emdash ? await emdash.getManifest() : null;
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const adminBranding = storedConfig?.admin;
|
|
33
|
+
// Determine auth mode from config
|
|
34
|
+
const authMode = getAuthMode(emdash?.config);
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
SELECT COUNT(*) as cnt FROM allowed_domains WHERE enabled = 1
|
|
38
|
-
`.execute(emdash.db);
|
|
39
|
-
signupEnabled = Number(result.rows[0]?.cnt ?? 0) > 0;
|
|
40
|
-
} catch {
|
|
41
|
-
// Table may not exist yet, that's fine
|
|
42
|
-
}
|
|
43
|
-
}
|
|
36
|
+
// Read admin branding from the per-request config plumbed through middleware
|
|
37
|
+
// (same source admin.astro reads from). Reading from a build-time global
|
|
38
|
+
// here was unreliable -- the virtual config module exports the config but
|
|
39
|
+
// doesn't assign it to globalThis, so getStoredConfig() always returned
|
|
40
|
+
// null and the React SPA never received custom logo/siteName/favicon.
|
|
41
|
+
// See issue #835.
|
|
42
|
+
const adminBranding = emdash?.config?.admin;
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
// Check if self-signup is enabled (any allowed domain with enabled = 1)
|
|
45
|
+
// Only relevant for passkey auth — external auth providers handle their own signup
|
|
46
|
+
let signupEnabled = false;
|
|
47
|
+
if (emdash?.db && authMode.type === "passkey") {
|
|
48
|
+
try {
|
|
49
|
+
const { sql } = await import("kysely");
|
|
50
|
+
const result = await sql<{ cnt: unknown }>`
|
|
51
|
+
SELECT COUNT(*) as cnt FROM allowed_domains WHERE enabled = 1
|
|
52
|
+
`.execute(emdash.db);
|
|
53
|
+
signupEnabled = Number(result.rows[0]?.cnt ?? 0) > 0;
|
|
54
|
+
} catch {
|
|
55
|
+
// Table may not exist yet, that's fine
|
|
51
56
|
}
|
|
52
|
-
|
|
53
|
-
version: VERSION,
|
|
54
|
-
commit: COMMIT,
|
|
55
|
-
hash: "default",
|
|
56
|
-
collections: {},
|
|
57
|
-
plugins: {},
|
|
58
|
-
taxonomies: [],
|
|
59
|
-
authMode: "passkey",
|
|
60
|
-
signupEnabled,
|
|
61
|
-
admin: adminBranding,
|
|
62
|
-
};
|
|
57
|
+
}
|
|
63
58
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
const manifest: EmDashManifest = emdashManifest
|
|
60
|
+
? {
|
|
61
|
+
...emdashManifest,
|
|
62
|
+
authMode: authMode.type === "external" ? authMode.providerType : "passkey",
|
|
63
|
+
signupEnabled,
|
|
64
|
+
admin: adminBranding,
|
|
65
|
+
}
|
|
66
|
+
: {
|
|
67
|
+
version: VERSION,
|
|
68
|
+
commit: COMMIT,
|
|
69
|
+
hash: "default",
|
|
70
|
+
collections: {},
|
|
71
|
+
plugins: {},
|
|
72
|
+
taxonomies: [],
|
|
73
|
+
authMode: "passkey",
|
|
74
|
+
signupEnabled,
|
|
75
|
+
admin: adminBranding,
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return Response.json(
|
|
79
|
+
{ data: manifest },
|
|
80
|
+
{
|
|
81
|
+
headers: {
|
|
82
|
+
"Cache-Control": "private, no-store",
|
|
83
|
+
},
|
|
69
84
|
},
|
|
70
|
-
|
|
71
|
-
)
|
|
85
|
+
);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
return handleError(error, "Failed to build manifest", "MANIFEST_BUILD_ERROR");
|
|
88
|
+
}
|
|
72
89
|
};
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import type { APIRoute } from "astro";
|
|
11
11
|
import { MediaRepository } from "emdash";
|
|
12
12
|
|
|
13
|
-
import { requirePerm } from "#api/authorize.js";
|
|
13
|
+
import { requireOwnerPerm, requirePerm } from "#api/authorize.js";
|
|
14
14
|
import { apiError, apiSuccess, handleError } from "#api/error.js";
|
|
15
15
|
import { isParseError, parseOptionalBody } from "#api/parse.js";
|
|
16
16
|
import { mediaConfirmBody } from "#api/schemas.js";
|
|
@@ -62,6 +62,15 @@ export const POST: APIRoute = async ({ params, request, locals }) => {
|
|
|
62
62
|
return apiError("INVALID_STATE", `Media item is not pending: ${existing.status}`, 400);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
// Only the uploader or a user with media:edit_any can confirm/fail a pending upload
|
|
66
|
+
const ownerDenied = requireOwnerPerm(
|
|
67
|
+
user,
|
|
68
|
+
existing.authorId ?? "",
|
|
69
|
+
"media:edit_own",
|
|
70
|
+
"media:edit_any",
|
|
71
|
+
);
|
|
72
|
+
if (ownerDenied) return ownerDenied;
|
|
73
|
+
|
|
65
74
|
// Optionally verify the file exists in storage
|
|
66
75
|
if (emdash.storage) {
|
|
67
76
|
const exists = await emdash.storage.exists(existing.storageKey);
|
|
@@ -37,9 +37,8 @@ export const GET: APIRoute = async ({ params, request, locals }) => {
|
|
|
37
37
|
|
|
38
38
|
const url = new URL(request.url);
|
|
39
39
|
const cursor = url.searchParams.get("cursor") || undefined;
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
: undefined;
|
|
40
|
+
const rawLimit = url.searchParams.get("limit");
|
|
41
|
+
const limit = rawLimit ? Math.max(1, Math.min(parseInt(rawLimit, 10) || 50, 100)) : undefined;
|
|
43
42
|
const query = url.searchParams.get("query") || undefined;
|
|
44
43
|
const mimeType = url.searchParams.get("mimeType") || undefined;
|
|
45
44
|
|
|
@@ -98,6 +97,16 @@ export const POST: APIRoute = async ({ params, request, locals }) => {
|
|
|
98
97
|
return apiError("NO_FILE", "No file provided", 400);
|
|
99
98
|
}
|
|
100
99
|
|
|
100
|
+
// Basic size validation (default 50MB, configurable via maxUploadSize)
|
|
101
|
+
const maxSize = emdash.config?.maxUploadSize ?? 50 * 1024 * 1024;
|
|
102
|
+
if (file.size > maxSize) {
|
|
103
|
+
return apiError(
|
|
104
|
+
"FILE_TOO_LARGE",
|
|
105
|
+
`File exceeds maximum size of ${Math.round(maxSize / 1024 / 1024)}MB`,
|
|
106
|
+
413,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
101
110
|
const item = await provider.upload({
|
|
102
111
|
file,
|
|
103
112
|
filename: file.name,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Menu items CRUD endpoints
|
|
3
3
|
*
|
|
4
|
-
* POST /_emdash/api/menus/:name/items
|
|
5
|
-
* PUT /_emdash/api/menus/:name/items
|
|
6
|
-
* DELETE /_emdash/api/menus/:name/items
|
|
4
|
+
* POST /_emdash/api/menus/:name/items[?locale=xx]
|
|
5
|
+
* PUT /_emdash/api/menus/:name/items?id=...[&locale=xx]
|
|
6
|
+
* DELETE /_emdash/api/menus/:name/items?id=...[&locale=xx]
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { APIRoute } from "astro";
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
import { isParseError, parseBody, parseQuery } from "#api/parse.js";
|
|
19
19
|
import {
|
|
20
20
|
createMenuItemBody,
|
|
21
|
+
localeFilterQuery,
|
|
21
22
|
menuItemDeleteQuery,
|
|
22
23
|
menuItemUpdateQuery,
|
|
23
24
|
updateMenuItemBody,
|
|
@@ -32,11 +33,14 @@ export const POST: APIRoute = async ({ params, request, locals }) => {
|
|
|
32
33
|
const denied = requirePerm(user, "menus:manage");
|
|
33
34
|
if (denied) return denied;
|
|
34
35
|
|
|
36
|
+
const localeQ = parseQuery(new URL(request.url), localeFilterQuery);
|
|
37
|
+
if (isParseError(localeQ)) return localeQ;
|
|
38
|
+
|
|
35
39
|
try {
|
|
36
40
|
const body = await parseBody(request, createMenuItemBody);
|
|
37
41
|
if (isParseError(body)) return body;
|
|
38
42
|
|
|
39
|
-
const result = await handleMenuItemCreate(emdash.db, name, body);
|
|
43
|
+
const result = await handleMenuItemCreate(emdash.db, name, body, { locale: localeQ.locale });
|
|
40
44
|
return unwrapResult(result, 201);
|
|
41
45
|
} catch (error) {
|
|
42
46
|
return handleError(error, "Failed to create menu item", "MENU_ITEM_CREATE_ERROR");
|
|
@@ -53,13 +57,17 @@ export const PUT: APIRoute = async ({ params, request, locals }) => {
|
|
|
53
57
|
const url = new URL(request.url);
|
|
54
58
|
const query = parseQuery(url, menuItemUpdateQuery);
|
|
55
59
|
if (isParseError(query)) return query;
|
|
60
|
+
const localeQ = parseQuery(url, localeFilterQuery);
|
|
61
|
+
if (isParseError(localeQ)) return localeQ;
|
|
56
62
|
const itemId = query.id;
|
|
57
63
|
|
|
58
64
|
try {
|
|
59
65
|
const body = await parseBody(request, updateMenuItemBody);
|
|
60
66
|
if (isParseError(body)) return body;
|
|
61
67
|
|
|
62
|
-
const result = await handleMenuItemUpdate(emdash.db, name, itemId, body
|
|
68
|
+
const result = await handleMenuItemUpdate(emdash.db, name, itemId, body, {
|
|
69
|
+
locale: localeQ.locale,
|
|
70
|
+
});
|
|
63
71
|
return unwrapResult(result);
|
|
64
72
|
} catch (error) {
|
|
65
73
|
return handleError(error, "Failed to update menu item", "MENU_ITEM_UPDATE_ERROR");
|
|
@@ -76,10 +84,12 @@ export const DELETE: APIRoute = async ({ params, request, locals }) => {
|
|
|
76
84
|
const url = new URL(request.url);
|
|
77
85
|
const query = parseQuery(url, menuItemDeleteQuery);
|
|
78
86
|
if (isParseError(query)) return query;
|
|
87
|
+
const localeQ = parseQuery(url, localeFilterQuery);
|
|
88
|
+
if (isParseError(localeQ)) return localeQ;
|
|
79
89
|
const itemId = query.id;
|
|
80
90
|
|
|
81
91
|
try {
|
|
82
|
-
const result = await handleMenuItemDelete(emdash.db, name, itemId);
|
|
92
|
+
const result = await handleMenuItemDelete(emdash.db, name, itemId, { locale: localeQ.locale });
|
|
83
93
|
return unwrapResult(result);
|
|
84
94
|
} catch (error) {
|
|
85
95
|
return handleError(error, "Failed to delete menu item", "MENU_ITEM_DELETE_ERROR");
|