From d5d49c7a2524a1a3dd6cbe2a62408d48ede3cdea Mon Sep 17 00:00:00 2001 From: Sid Date: Thu, 21 Dec 2023 00:19:57 +0800 Subject: [PATCH] fix: payload __map.json with special character slugs --- packages/karbon/src/runtime/composables/resources.ts | 3 ++- packages/karbon/src/runtime/routes/payload-handler.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/karbon/src/runtime/composables/resources.ts b/packages/karbon/src/runtime/composables/resources.ts index 3bcef5a9..c76b238d 100644 --- a/packages/karbon/src/runtime/composables/resources.ts +++ b/packages/karbon/src/runtime/composables/resources.ts @@ -197,11 +197,12 @@ function getContextFor(type: Resources | string) { } async function convertToId(scope: PayloadScope, resourceID: any): Promise { - const { id, slug, sid } = resourceID + const { id, slug: _slug, sid } = resourceID if (id) { return id } const idComparisonMap = await loadStoripressPayload(scope, '__map', true) + const slug = decodeURIComponent(_slug ?? '') return (slug ? idComparisonMap.slugs[slug] : idComparisonMap.sids[sid]) ?? null } diff --git a/packages/karbon/src/runtime/routes/payload-handler.ts b/packages/karbon/src/runtime/routes/payload-handler.ts index 9e2f1079..892af7e1 100644 --- a/packages/karbon/src/runtime/routes/payload-handler.ts +++ b/packages/karbon/src/runtime/routes/payload-handler.ts @@ -95,7 +95,8 @@ export function definePayloadHandler({ const items = await listAll(true) const initial = { slugs: {}, sids: {} } - return items.reduce((target, { id, slug, sid }) => { + return items.reduce((target, { id, slug: _slug, sid }) => { + const slug = decodeURIComponent(_slug ?? '') slug && Object.assign(target.slugs, { [slug]: id }) sid && Object.assign(target.sids, { [sid]: id }) return target